Skip to main content
gamedev.net
🔒 Locked

camera look at

Started by gowron67 May 3, 2003 at 11:43 AM 2 replies 550+ views
Original Post
gowron67
gowron67
I''ve got a basic camera class up and running where it uses a quaternion to store it''s orientation, a 4x4 matrix is then created from this quaternion and passed to OpenGL. My question is I want to be able to give my camera class a point to look at, similar to the way gluLookAt works, but I can''t figure out what to do to the camera''s orientation quaternion to make the camera look at the specified point. Can anyone help please ?
JuNC
JuNC
If you really must store the orientation as a quaternion, then just construct the rotation matrix for the lookat, then convert that back to your quaternion. (the rotation matrix is simple to construct:


z_axis = normalize( -(focus - eye) );

x_axis = normalize( cross(up,z_axis) );

y_axis = cross(z_axis,x_axis);

matrix4X4(x_axis.x,x_axis.y,x_axis.z,0,
y_axis.x,y_axis.y,y_axis.z,0,
z_axis.x,z_axis.y,z_axis.z,0,
0.0,0.0,0.0,1.0);


You''ll need to fiddle it a bit depending on your matrix system, this one here adheres to the OpenGL conventions).
gowron67
gowron67
thanks..but what does focus refer to here ??
grhodes_at_work
grhodes_at_work
focus is the point being looked-at. eye is the camera location.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.