dilevin / computer-graphics-bounding-volume-hierarchy

Computer Graphics Assignment about Bounding Volume Hierarchies
6 stars 7 forks source link

When do I set Descendant? #100

Open grandrx10 opened 1 month ago

grandrx10 commented 1 month ago

Within AABBTree_ray_intersection, I recursively set descendant but I never implement a base case for it. I'm wondering where I can actually implement this base case, or if I even need to (does an object have a base implemented descendant return?)

The reason why I am asking about this is because when running the code, I encountered a seg fault (see below) which I traced to a function that uses the descendant return.

image image

Can I get some clarification on how the descendant is supposed to be used? (I have read the other post about descendant, and I am still unclear on how to do so.)

Zhecheng-Wang commented 1 month ago

The base case would be if the ray has intersected with a box. Then it checks if there is left descendant, it checks if the ray intersects with left descendant (tree). The same goes for right tree. So, if the left descendent is a leaf, then the descendant should be set to the leaf object pointer. Otherwise the descendant is just the left tree pointer. The same goes for right tree.

grandrx10 commented 1 month ago

Can I assume that leaf objects will automatically return themselves as a descendant when I call ray intersect on them?

Zhecheng-Wang commented 1 month ago

Yes I believe so. The ray_intersect should be overloaded when called on a leaf object. So the tricky part is how do you know if the returned descendant object is a leaf or not.