I've got a box drawn in WorldWind using OpenGL/JOGL. This box is a bounding box for a 3D Object. All of this code is based on code found in this forum here. My code is adapted from that and is working the way I want it. I can put a model and its box on the WorldWInd canvas and retrieve the position and altitude of the origin point when the model is picked. My adaptation puts the origin at what would be the 'bottom' face of the box and in the center of that face like so:
What I need to know is what is the highest altitude of the of the bounding box? The models and associated boxes can be rotated on any of the three axes using the glRotate call; they can also be scaled. All of these values are arbitrarily chosen by the user of my application but are visible to me in the program. So while I cannot plan for them ahead of time, I can still use the values. The position and altitude associated with the model inside the box do not change during rotation/scaling, the model + box are rotated at draw. This example rotates it on one axis:
Without the possibility for rotating, I can add the scaled height of the box (the Y height) to the origin position's altitude to get the altitude at the top. With rotating, it is more difficult. If rotation was only possible on one axis, the answer would be derived from math found in questions like these:
which easily explain how to do what I want in 2D. In 3D, the math gets more complicated.
- How do I get the height of the box after glRotate is called on all 3 axes? Preferably in meters or in a format that can be easily converted to meters. Because what I really need is the altitude at the highest point of the box.
- Is there a gl call to get the height or would this be pure math? If gl call, what is it please? If math, can someone explain the formula? I've tried the math but I keep getting negative numbers, which is wrong.
What I'm doing so far:
theta1 = rotation on Y axis, theta2 = rotation on X axis, theta3 = rotation on Z axis
XY = (originalYHeight)*cos(theta1) + (originalXWidth)*sin(theta1)
XZ = (originalXWidth)*cos(theta2) + (originalZDepth)*sin(theta2)
YZ = (originalZDepth)*cos(theta3) + (originalYHeight)*sin(theta3)
This messes up if the angles of rotation are negative/between 90deg and 270deg. Even if it does get me the correct side lengths, it will not have which of these sides points 'up'.
The way your doing the linear transformations is very unnatural and also not very efficient.
You should have a Rotations-Translation Matrix and solely work with vertices of the box. Also create a point on the bottom of the box that you want to book-keep.
Now it is ridiculously easy to know where the ground of the bottom is:
Note that every vertices that rotates and/or translates has to undergo this Matrix-Vector Multiplication.
This is the way to go. Do not use angles, cosines, sines and other inconvenient stuff. It is actually quite simple once you figured out how that works.