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:
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
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.