User Tutorials - Pitch Roll and turn angles
Tutorial 4
This tutorial is based on the work done in previous tutorials 1, 2 and 3.
You may have noticed the PitchAngle, RollAngle and TurnAngle properties on GLLines1.
and wondered why there are not used instead of the rather confusing Direction and Up vectors. Some rather complex 3D math comes into play here but I’ll attempt to explain when you should and when you should not use these properties.
First thing to note is the fact that any of the three angles (Pitch, roll and turn) are defined relative to the objects own coordinate system and not against the coordinate system of the parent like is the case with the Position, direction and Up vector.
This is a confusing situation because if you change the PitchAngle from 0 to 30 degrees then the object will pitch 30 degrees from it’s current pitch angle. The objects coordinate system, direction vector and Up vector are all updated. Let’s try it.
- Select GLLines1 in the scene editor and press F10 to bring up the object inspector
- Set the PitchAngle to 30
pic
The result is that the GLLines1 object pitches 30 degrees like so:
pic
Did you notice in the above object inspector how the Direction Vector has changed? So if the Pitch is relative to the objects coordinate system. How come that the pitch still shows 30 while the GLLines1 object has a pitch of 0 relative to it’s own coordinate system.
Indeed, confusing. The way GLScene implements these angles is that behind the scenes the library is simply instruction to pitch the coordinate system around the X axis by the change of the PitchAngle. In our example the old PitchAngle was 0, the new one was 30 therefore the pitch change was 30.
So if you now enter PitchAngle = 20 you will find that the delta pitch is -10 and the coordinate system will come back in pitch by 10 degrees.
- Set GLLines1.PitchAngle to 20
Now, let’s take control of this object and align the Direction vector back with the Y axis as it was before.
- Set GLLines1.direction.Y to 1 and GLLines1.Direction.Z to 0
Have a good look at the Form and object inspector. The direction vector corresponds with what you see on the form but the PitchAngle still shows 20!
pic
Yeah, have a coffee at this point and a little cry. It just isn’t fair. What is happening is that within the objects coordinate system the object was told to pitch 20 degrees. After that we re-aligned the coordinate system with the Y axis and thus the GLLines1 object points up again. Guess what happens if you set PitchAngle to 0? Right.
Conclusion: Using Pitch, Roll or turn is useful as long as you don’t mix it’s use with the Direction and Up vector. Another important limitation is that you should not manipulate the object around more than one axis.
Let’s prove this with another example.
- Set GLLines1.PitchAngle to 0
- Set GLLines1.TurnAngle to 0
- Set GLLines1.RollAngle to 0
- Set GLLines1.Direction.X = 0, GLLines1.Direction.Y to 0 and GLLines1.Direction.Z to 1
- Set GLLines1.Up.X = 0, GLLines1.Up.Y to 1 and GLLines1.Up.Z to 0
You should see this again:
pic
Now let’s pitch this object up by a 60 degrees, around by 135 degrees and back down to a pitch of 0. You would expect this right?
pic
But that is NOT what you are going to see. Try it now and observe the form after each step.
- Set GLLines1.PitchAngle = 60
- Set GLLines1.TurnAngle = 135
- Set GLLines1.PitchAngle = 0
pic
As you could see. After each step the objects coordinate system changes and therefore subsequent steps are performed in a different coordinate system that has a different orientation. A good way to overcome the complex gimbal error issues is by using TDummyCube objects to construct a logical pivot system. This
Tip describes how to build a tripod for your
TGLCamera.
The best thing to do is go back and re-read the topic about vectors if not fully understood. Or refrain from manipulating more than one angle on an object.