Sorry for the super delayed response guys, I wasn‘t notified about your replies for some reason :(.
For the sake of completion. I found the answer on the Real-Time Collision Detection book and basically it says what @aressera said “2. Transform the AABB from local to world space…”. The book comes with an algorithm for updating a box when a rotation is involved (scaling and translation are not a real issue) at the cost of not having a tight box anymore.
@gnollrunner @aresera About your comments on whether or not the octree is a good idea actually make sense. First, I forgot to mention that I’m making a Real-Time 3D Renderer (my bad there). Second, my scene is not that large for the moment, so maybe a brute-force approach might be enough right now. Third, I would like to make a DS that can support Frustum Culling and physics on the future.
@aressera about BVH… I was looking at them actually but I decided to go with Octrees because:
- For dynamic scenes the insertion method is basically the only option for BVH.
- On BVH if the object moves we will have to move the hierarchy too (seems odd to do a bunch of updates and based on preliminary research that seems expensive)
- Octrees are locked to the “world“ (might need a refit if and object is outside of the volume but we can always limit the movement space to the root node limits)
- Technically, Loose Octrees could have O(1) insertion and deletion, thus making them a better fit for dynamic scenes.
- Found more information about octrees for dynamic scenes compared to BVH.
I would like to make disclaimer about Octrees tho as I’m getting stuck on that O(1) insertion.
Loose Octrees claim to have O(1) insertion but the algorithm seems to be forgotten XD. I found the specific algorithm on Thatcher Ulrich (Game Programming Gems 1, 2000, p. 444-452). The algorithm goes as follows:
// W is the worlds length, it is expected that the Octree is a cube.
// R is the radius of the bounding volume.
// k = 2 - i.e. loosenesses factor.
S(depth) => W / 2 ^ depth
// Depth is the depth at which the object can be inserted. It is guaranteed
// that the node doesn’t have a variation + 1 child node, this is, a tightest
// node is either at that depth or one more.
depth = floor(log2(W/R))
// Expects the root Node octree to be centered on the origin (0,0,0)
index = floor((object.center + (W/2))/S(depth))
Now, there seems to be to be a caveat on this algorithm:
If you precompute your octree and you stop at an upper level than the one specified on the depth (i.e. MAXLEVEL < depth) then you seem to loose the advantage of the Loose Octree. In that case either you insert it on the MAX_LEVEL and on the node that’s closets to your object or you do a normal descent-insertion i.e. partition your node, go down to the child that’s closes to your object until you reach the desired Depth, insert. Thus making it a log/O(1) insertion when the depth is not created.