Original Post
Hi I am trying to write a method that will put an object into the correct octree node. I am stuck with a nasty if statement and I cant think any further on how to insert it more effectively. This is the structure of one of my node: I am doing a test on the objects AABB to see which side of the XYZ planes the object will be on or wether it will straddle a plane, in that case I will insert it into the current node. I just think that this test there is to many steps, I will be left with a result such as left, top, back, or right, bottom, front but then I will need to figure out which node that corresponds to, which I could do, but thats an additional check to what I have already. Any advice on how I could achieve this in a more efficient manner? I am probably going about this the wrong way!
// .--------------.
// 8 --->/ / /|<--- 5
// /--------------/ |
// / / /| |
// .--------------. | |
// | | | |/|
// 7 --->| 4 | 1 | / |<--- 6
// | | |/|6|
// |-------|------| | .
// | | | |/
// | 3 | 2 | /
// | | |/
// .--------------.
This is my unfinished method where Center is the center point of the current node.
public void InsertObject(Renderable obj)
{
bool straddle = false;
if (obj.BoundingBox.Max.X < Center.X)
{
// left of x plane
}
else if (obj.BoundingBox.Min.X > Center.X)
{
// right of x plane
}
else
{
straddle = true;
}
if (obj.BoundingBox.Max.Y < Center.Y)
{
// bottom of y plane
}
else if (obj.BoundingBox.Min.Y > Center.Y)
{
// top of y plane
}
else
{
straddle = true;
}
if (obj.BoundingBox.Max.Z < Center.Z)
{
// back of z plane
}
else if (obj.BoundingBox.Min.Z > Center.Z)
{
// front of z plane
}
else
{
straddle = true;
}
}