On Jul 5, 10:55=A0pm, ampheta...@[EMAIL PROTECTED]
wrote:
> Greetings! I recently started learning OpenGL and I have run into
> quite a problem. I really have no idea how to implement a simple
> camera using OpenGL's transformation functions. What particularly
> bothers me is the order in which transformations must be applied.
>
> Suppose the camera is located at (x, y, z) and its rotation is -45
> degrees (from the default orientation, that is, looking towards (0, 0,
> -1)).
>
> If I translate first, by calling glTranslate(-x, -y, -z), the rotation
> will have that point as its origin. I don't need that.
>
> If I rotate first, I will have to somehow calculate the translation
> vector (because forward, for example, won't be (0, 0, -1) anymore).
>
To go forwards you have to do the new translation before the
previous rotation/translation, ie. your transform is now:
T * R * T
Then if you want to go forwards again it becomes:
T * T * R * T
Obviously you can't keep this up forever. What you can
do is store the "R * T" part using glGetMatrix(), put it
back again the next time around with glLoadMatrix(),
then compute "T * R * T".
Now you store that matrix for the next time around and
compute "T * T * R * T" using it. etc.
After a while the floating point rounding errors will catch up
with you so you need to fix them. Each row of the upper 3x3
part of a transformation matrix is a unit vector which is the
vector product* of the other two rows. This means it's quite
easy to recompute the true value of each row. Recompute
the rows every now and again and you'll be ok.
[*] Or "cross product" in vulgar parlance.
--
<\___/>
/ O O \
\_____/ FTB. Remove my socks for email address.


|