This topic is now archived and is closed to further replies.


Camera Rotation Whitout Matrix

Recommended Posts

uncutno    146
Ok, here is my problem! Ive got a ViweDirection Vector! Ive got a UpDirection Vector, Ive even got a RightDirection Vector! These three makes a perfect matrix for rotation! My question is, how do i make OpenGL use these vectors, so that the "camera" points that way? I found a hard way, with filling up a float m[15], and then use something like glMultMatrix(m), but there must be a easy way? -Anders-Oredsson-Norway-

Share this post

Link to post
Share on other sites
mittens    1323
I would *STRONGLY* recommend that you don''t use your own matrices for rotations and such (even the Red Book says its not recommended). The gl commands for translation/rotation/scaling/etc are *FAR* faster than yours can ever be (unless of course you figure out a way to do in hardware). And if you want to look at a specific point, use gluLookAt(...).

Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials

Share this post

Link to post
Share on other sites
SirKnight    316
Well if you have a geforce 3 then its easy to do it in hardware. Just use vertex programs.

But yes, since you have those three vectors, gluLookAt is just what you need. That function wants those exact vectors you already have!


Share this post

Link to post
Share on other sites
Obelix    122
use gluLookAt. From the MSDN documentation:

The gluLookAt function defines a viewing transformation.

void gluLookAt(
GLdouble eyex,
GLdouble eyey,
GLdouble eyez,
GLdouble centerx,
GLdouble centery,
GLdouble centerz,
GLdouble upx,
GLdouble upy,
GLdouble upz
eyex, eyey, eyez
The position of the eye point.
centerx, centery, centerz
The position of the reference point.
upx, upy, upz
The direction of the up vector.
The gluLookAt function creates a viewing matrix derived from an eye point, a reference point indicating the center of the scene, and an up vector. The matrix maps the reference point to the negative z-axis and the eye point to the origin, so that when you use a typical projection matrix, the center of the scene maps to the center of the viewport. Similarly, the direction described by the up vector projected onto the viewing plane is mapped to the positive y-axis so that it points upward in the viewport. The up vector must not be parallel to the line of sight from the eye to the reference point.

The matrix generated by gluLookAt postmultiplies the current matrix.

Share this post

Link to post
Share on other sites