1. ## OpenGL Object Rotation

If I understand correctly
Code:
`glRotatef(anglef, xamountf, yamountf, zamountf);`
Applys a matrix multiplication based on the objects current position, and renders the object in a different position than its "actual" position. I'm starting to work with some higher poly count objects and in doing such I came to a conclusion of making one BaseTri Class that can have a local rotation and a global rotation (based on a given pivot point of the object).

When both rotations are applied to the object it can be given a semi-complex position that is not acurate to its "actual" position. When it comes to detecting collisions I have done such based on the objects actual position, so inevitably this is going to create an inaccuracy. If the object was small and only allowed to rotate its BaseTriangles around its center point, and the object that was colliding was moving fast the inaccuracy wouldn't be percievable. But what if I have a object that is based off one main object and a few orbiting objects (say swords swirling around a mage) If i wanted to detect a collision with a sword I don't understand how I would detect a collision with this object since the rotate function is only creating the illusion of motion and in actuality the swords would be standing still. I have two possible solutions both of which seem to be very comsuming for coding, and a desperate hope.

1). Detect Collisions based off a forumla that analyzes an objects x, y, and z angles around its Pivot Point, and size, and shape. (considering the 3 rotation values can have an incredibly large number of possibilities of position if all rotations are enabled, this is daunting)

2). Don't use glRotatef and write formulas for manually rotating the actual positions of each vertex of each BaseTriangle. (once again working with 3 possible angles with range 0- 359.9, becomes a little daunting)

I wasn't sure which would be more "functional" as I don't see any pitfall of either solution(other than the time taken to manually produce and validate the formulas), and I was curious if there was already some "accepted" standard for this type of problem.

Desperate hope: (which would seem the easiest) is there a way to store the finished product of a rotation multiplication back into the vertice points of the triangles?

2. Don't use Euler angles for orientation. You can use axis-angle or Quaternion representations.
Collision detection is done through AABB's, OOBB's and finally ray triangle intersections. Whether you do these in world or local space is totally up to you.

The order of transforms is:

W = I S R O T
where O is T(center) * R(orbit)
I is identity or can be the parent's world matrix.

3. Thanks for the response bubba. I was using AABB then when I got into rotations I realized they wouldn't be accurate so I figured out how to do Point to Triangles which has been my current method(though the abrreviates you gave me show I've been overcomplicating it). I never heard of OOBB before, but I just read up on it sounds pretty simple.

Quaternions on the other hand not sinking in so well. Just bought a calculus book though (never took the class in high school), so hopefully a few days should shed some light on it. What I found kind of strange though.

Quaternions don't suffer from gimbal lock, unlike Euler angles.
then
You have to convert them to get a human-readable representation (Euler angles) or something OpenGL can understand (Matrix).
How is this logic not circular? Having to convert back to Euler in order to use them in OpenGL doesn't still give you the possibility of suffering from gimbal lock?

4. On further review of my calculus book and Wiki it appears a Quaternion is a set of 4 numbers (much like a triple or cartesian coordinates) that has another scaler (real number) added to it. or
Code:
`Quaternion = W + Xi + Yj + Zk; (don't understand why wiki said that)`
Seems by discription this is an ordered quad and not a formula to derive one number. (correct me if I'm wrong)
It would make more sense to me as.
Code:
`Quaternion = {w, xi, yj, zk};`
W being the 4th point in space. I, J, and K were throwing me off I couldn't find anything about it. Then chapter 11 (Vectors, Points, and Planes) got into a section on Unit Vectors.
Unit Vector - A vector whose length is equal to 1.
Code:
`Length = sqrt((x*x) + (y*y) + (z*z))`
It defined i, j, and k in the book as defualt unit vectors i.e. vectors that equal 1 in length on their respective plane.
Code:
```X unit vector    i = (1, 0, 0)
Y unit vector    j = (0, 1, 0)
Z unit vector   k = (0, 0, 1)```
Am I correct in assuming that these are refering to the same thing? Then my guess would be that i, j, and k are unit vectors drawn to represent the angle of rotation of an object, but I don't get how to find 180 degrees of rotation on any given axis with i, j, and k, since they are represented as a length of 1 and therefore can only be denoted.
i || -i ,
j || -j,
k || -k

Web links I've used thus far.
OpenGL:Tutorials:Using Quaternions to represent rotation - GPWiki
Quaternion - Wikipedia, the free encyclopedia

I know the first one has the functions drawn explicitly, but I don't understand the basic math so I'm not going to copy and paste it.

5. Just take for granted that quaternions work. I cannot explain the math of why or how they work but I know they do. Also when working with quaternions all you need to know is the various operations that can be performed on them such as normalization, cross product, dot product, etc.

The reason you convert to a quaternion is b/c you can then linearily interpolate between two orientations. You must then take the result or the interpolated quaternion and convert back to a matrix b/c the hardware needs matrices. All the quaternion is allowing you to do is smoothly interpolate between two orientations without running into gimbal lock.

Seems by discription this is an ordered quad and not a formula to derive one number. (correct me if I'm wrong)
What 'one number' are you referring to? Quaternions and vectors both are 4 numbers. They both use x,y,z and w.

6. What 'one number' are you referring to?
If you notice my first quote from wiki used operators in between w, xi, yj, and zk implying that they should be added.
Quaternions and vectors both are 4 numbers. They both use x,y,z and w.
I've never read a math book anywhere that defined a vector in 4 points. (if you could point to a reference of that I'd appreciate it) I guess it has to be done in openGL to simplify Sums between Vectors and Quaternions since you can't add a matrix of 1x3 to a matrix of 1x4. I have read of vectors being defined in two variables U and V, being direction and magnitude. Which are still just results of its Cartesian Coordinates. The vectors I've used thus far are all 3 point vectors/vertices (since they can be defined the same), and I've been writing a calculus header as I learned laws of vectors that uses the struct vector I defined in the calculus header.

Code:
`Just take for granted that quaternions work.`
That takes half the fun out of it. I am doing this to learn about game programming and the math behind it. I couldn't imagine I could ever be a innovator if I didn't understand how the previous methods were laid before me. Might take me a few more days, but hopefully the reward will be worth it.

Once again thanks Bubba your posts always manage to drop one HUGE word that I find myself chasing down a rabbit hole of knowledge for days.