Hello everyone,
I've searched the forum for any topic with information about bounding boxes, but didn't find what I was looking for.
My question: is it possible to get a bounding box of a 3d object within a 2d plane? Perhaps this is a bit unclear, so I made the following picture:
As you can see, the 3d objects are within 2d bounding boxes. I have no idea how to calculate the dimensions of such a box. Could someone point me in the right direction?
Thanks in advance.
- Dave.
2D bounding box
Is it not enough to get the ordinary 3d bounding box and call get2DCoordinate with the points in the box? Not just min and max, but all positions, sortof.
pseudocode:
OrigBox=Node->getBoundingBox()
VectorList L
OrigBox.getEdges(L)
aabbox NewBox(vector3df(0,0,0))
for each L
Position2d Pos
NewBox.addInternalPoint(Pos.X, Pos.Y, 0)
end for each
end code
With that i think the new bbox should hold the box coords in a 2d plane, since z is ignored. I think this might be ok.
pseudocode:
OrigBox=Node->getBoundingBox()
VectorList L
OrigBox.getEdges(L)
aabbox NewBox(vector3df(0,0,0))
for each L
Position2d Pos
NewBox.addInternalPoint(Pos.X, Pos.Y, 0)
end for each
end code
With that i think the new bbox should hold the box coords in a 2d plane, since z is ignored. I think this might be ok.
If you don't have anything nice to say, don't say anything at all.
I thought of that too, but when viewing from other angles, the bounding box will often be much larger than the model itself, especially if it's small compared to its bounding box (for instance a long thin diagonal object). If you want to have it snug fit around the model (as shown in the image), you'll need get2DCoordinates().
Hello again.
I thought it would be nice to post the solution here, so other people can use it too. Note that it doesn't yet work up to 100%, but the results are quite okay
I used the bounding box for my calculations, since this isn't as CPU-intensive as using all the vertices of a model.
1) Calculate the 3D coordinates of all 8 points in the bounding box.
2) Convert those points to 2D screen coordinates (getScreenCoordinatesFrom3DPosition).
3) Calculate the length of the 4 diagonals in the bounding box using the 2D screen coordinates:
4) Get the X- and Y-coordinate from the largest diagonal and save them as the size of the box.
5) Get the smallest X- and Y-coordinate from the diagonals and save it as the starting point.
6) Draw a cube with the saved starting point and size.
I thought it would be nice to post the solution here, so other people can use it too. Note that it doesn't yet work up to 100%, but the results are quite okay
I used the bounding box for my calculations, since this isn't as CPU-intensive as using all the vertices of a model.
1) Calculate the 3D coordinates of all 8 points in the bounding box.
2) Convert those points to 2D screen coordinates (getScreenCoordinatesFrom3DPosition).
3) Calculate the length of the 4 diagonals in the bounding box using the 2D screen coordinates:
Code: Select all
/4--------/0
/ | / |
/ | / |
6---------2 |
| 5- - -| -1
| / | /
|/ | /
7---------3/
Diagonal 1: from 0 to 7
Diagonal 2: from 1 to 6
Diagonal 3: from 2 to 5
Diagonal 4: from 3 to 4
5) Get the smallest X- and Y-coordinate from the diagonals and save it as the starting point.
6) Draw a cube with the saved starting point and size.
Sorry for the bump, but it seems that my code didn't work when rotating objects. Vitek just posted a very nice solution right over here: http://irrlicht.sourceforge.net/phpBB2/ ... 361#123361.