View Full Version : need some help with simple transformation

hello everyone

ok, so say i have my camera at 2,3,5 and its looking at a point at 3,3,5. my up vector is 0,1,0...now i want to rotate my camera an arbitrary amount (say 5 degrees clockwise) in the x-z plane. how would i calculate the new point to where the camera is pointing? do i have to use trigonometry? or is there a matrix i should build, then send to glMultMatrixf()?

thank you

LoCo3D

07-30-2001, 02:13 PM

I'd build a matrix because it's much easier and you should be using one anyway. http://www.opengl.org/discussion_boards/ubb/wink.gif

yeah, ok, so exactly what matrix would i build? (what values would i put in it?) and how would i use it?

Aster

07-31-2001, 03:41 PM

The issue that causes many misunderstandings with OpenGL is that the coordinates you specify in glRotate and glTransate calls are relative to the viewpoint, which is always located at the origin (0, 0, 0). The same thing happens with gluLookAt: after you position your world, the coordinates specified in the parameter list are relative to the viewpoint before the viewing transformation. So, to rotate your camera, let's say, by 5 degrees counterclockwise in the xz plane, just rotate your world by -5 degrees - a single call to glRotate would do the trick. But remember the order of transformations:

gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0); /* positions camera at the origin looking down -z axis (actually redundant call - defailt position) */

glRotatef(-5, 0, 1, 0); /* rotates camera by 5 degrees, or the world by -5 degrees) */

/* draw your world */

I hope this helps. Good luck.

OK rotY is from 0 ... 360 this is the XZ plane depending on which angle the cam is looking use the following

angle in radians

dirX = sin( rotY * DEG2RAD )

dirZ = cos( rotY * DEG2RAD )

gluLookAt( 2,3,5, 2+dirX,3+dirY,5+dirZ, 0,1,0 )

Aster

08-01-2001, 12:34 PM

Hey lee!

Sorry, I missed the whole point of your question the last time. You actually want to find the point where the camera is pointing. If your camera position is (x0, y0, z0) = (2, 3, 5) and it's pointing at (x1, y1, z1), then your camera's direction vector is (x1 - x0, y1 - y0, z1 - z0) = (dirx, diry, dirz). Rotate it in the xz plane by using the following calculation

[cos a 0 sin a] [dirx] [newx]

[ 0 1 0 ] x [diry] = [newy]

[-sin a 0 cos a] [dirz] [newz]

where a is the angle of rotation. Then, to find the new point where the camera is pointing, just add the result to your camera's position vector:

[x0] [newx]

[y0] + [newy]

[z0] [newz]

The result is the point you are looking for.

Cheers.

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.