Jump to content
  • Advertisement
Sign in to follow this  

help needed with octree implementation

This topic is 3906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, one method I just though of is as follows..please critique find the AABB for the object i.e. minB and maxB vectors. Then determine the length(max.x-min.x), breadth(max.y - min.y) and height ( max.z - min.z). After this, L = length/2, B = breadth/2, H = height/2 Then, since we know values of all the 8 corners, use these to find the corners for each of the cells.. For eg at corner (xmin, ymin, zmin) - (xmin , ymin, zmin) (xmin + L, ymin, zmin) (xmin + L, ymin + B, zmin) (xmin + L, ymin, zmin) Then for the four corners above, simply add height to zmin in each of the above. It is easy to determine the minB and maxB vectors through this with simple comparisons. This gives one cell. Similarly traverse to 7 other corners and determine 7 cells. To determine which triangles are inside a particular cell use simple test like min.x > = vertex.x < = max.x min.y > = vertex.y < = max.y min. z > = vertex.z <= max.z i = 0...3 For triangles which are coplanar with splitting plane, their id's will be automatically repeated in other cell and the ones that are spanning across the plane must also be dealt with in the same way. Make the routine a recursive one ... octree(BBox, length, width, height, number_of_triangles_in_list, tri *list) { if(length && width && heigth <= some tolerance value || number_of_triangles_in_list <= some tolerance value) Make the 8 children of the box as NULL return; ........ ........ octree(BBox, length/2, width/2, height/2, number_of_triangles_in_list, list); } For traversal, start with the root node and check which of the 8 cells the ray is hitting. Find that cell and further traverse until you reach a leaf node for which children are all NULL.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!