|
Post by vorpal on Dec 25, 2018 16:07:13 GMT
I'm trying to figure out the bounds (for the bounding box) for a cone.
Is it something along the lines of:
minx = minz = -max(abs(miny), abs(maxy)) maxx = maxz = max(abs(miny), abs(maxy))
And then of course the Y values are the ones specified in the cone?
|
|
|
Post by Jamis on Dec 25, 2018 19:21:35 GMT
Yup, that's right!
|
|
|
Post by vorpal on Dec 25, 2018 19:35:35 GMT
Great! Thanks! Now to see if I can get the rest of this bounding box algorithm done! (And Merry Christmas / whatever holiday if any that you celebrate!)
|
|
|
Post by vorpal on Dec 25, 2018 20:42:19 GMT
Hi Jamis,
I'm a little bit confused about the bounding box still.
For part (2), in bounds(shape), do I just always return the bounding box for the shape, never taking the parent into effect?
For part (3), making the bounds(group) method, I'm very uncertain as to what to do. Do we convert all the bounds for every shape s in the group to group space by multiplying by the transformation in the group? How does parent space fit in here compared to part (2)?
Do I apply the group transformation to each shape and then find the minx, miny, minz, maxx, maxy, maxz, across all shapes, and then apply a transformation (which?) to the vertices (minx, miny, minz), (minx, miny, maxz), (minx, maxy, minz), ... (maxx, maxy, maxz)? And from there find a bounding box that accommodates all of these points?
I guess I'm really very confused about part (3). Sorry to bother you, but any clarity you could provide would be great. If someone else has implemented this, it might be useful to see their code to figure out what they're doing.
|
|
|
Post by Jamis on Dec 25, 2018 21:58:40 GMT
vorpal, Great questions. Let me see if I can help clarify. For (2), yes, bounds(shape) should return the bounds in the object's own space. So a sphere, for instance, would have min=(-1,-1,-1) max=(1,1,1), even if it has been transformed. For (3), I think you've got it, but let me recommend introducing a new function, bounds_in_parent_space(shape), which multiplies the shape's bounding box (per the bounds(shape) function) by the shape's transformation matrix. Doing so converts the bounding box from object space, to parent (or, for top-level objects, world) space. Then, when finding the bounds of a group, you call bounds_in_parent_space(shape) on each of the group's children, and find the bounding box that contains them all. Be careful not to apply the group's transformation to the children, though. A shape's transformation matrix converts a point in the shape's own "local" space, to the space of the shape's parent (or the world). I hope that makes sense; I struggle to know how best to explain it. If you want to convert a point (or vector, or an entire bounding box) from local object space to parent space, you multiple it by the transformation matrix of the shape it belongs to. Take a point in object space, say (0, 1, 0), where the shape has a transformation matrix of translation(0, 5, 0). Multiplying the point by the transformation matrix gives you the point (0, 6, 0), which would be in the coordinate system of the object's parent (or the world, if the shape has no parent). Lastly, when transforming a bounding box, you need to (1) find all eight points that define the box's corners, (2) transform them all by the shape's transformation matrix, and (3) find the bounding box that fits all eight of those transformed points. It's not sufficient to just transform the box's min and max points -- to see why, imagine rotating the box by 45 degrees (any axis), and consider how you'd find the axis-aligned bounding box of the resulting non-axis-aligned box. It's honestly no bother at all! I'm happy to help. I'm currently working on the next bonus chapter, which covers this very topic, but it might be a couple of weeks until it's ready. It covers not only bounding boxes, but also subdividing the children of a group into subgroups, so that models with large triangle counts can be rendered more efficiently.
|
|