PDA

View Full Version : Making a camera or viewpoint?



Siwko
05-03-2001, 09:33 AM
Well, it's once again time for the "I'm too stupid (or lazy) to figure this out myself" zone.

Basically, I'm wondering how to create a "camera" system in 3D (not really just OpenGL, but in general). What I'm looking for is a way to structure and control the movement of an object, which for all intents can be considered a "camera".

I currently have a little structure which is capable of storing the location and orientation of the "camera", but it's actually controlling it that is the problem. From it's initial resting point, sure, I can translate it cumulatively in any direction. But the problem is that these coordinates are in raw world coordinates. Now say I want to always move "forward", but rather than +ZAxis of the world, I want to move forward alone the local ZAxis of the camera? How do I go about doing this? How do I accumulate and store this into the camera object?

Do we all understand what I'm asking? Basically, I want to replicate the first-person "camera" and control of something like Quake 3 or CS (or whatever).

Hit me. http://www.opengl.org/discussion_boards/ubb/smile.gif

Siwko

zen
05-03-2001, 05:50 PM
This is how it goes(I think):
A 'camera' is just anothr coordinate system(cs) like the world cooridnate system.In order to go from world to camera cs you first translate to your camera's position and then rotate by the camera's rotation matrix.You want to be able to translate/move the camera along the cameras axes so you want to convert camera coords to world coords.Assuming that you have or can find your cameras rotation matrix it's simple:just multiply the translation vector(e.g. (0,0,5) if you wanna move 5 units ahead) by the inverse of the camera's roation matrix.Note that since it's a rotation matrix it's inverse and transpose are the same so use the transpose.Hope that helps.

Siwko
05-04-2001, 07:13 AM
Okay... so, assume I have the following:




class Camera
{
float xPos;
float yPos;
float zPos;
Quaternion orientation;
...
Rotate(float a, float x, float y, float z);
Move(float x, float y, float z);
}


First I would "orient" the camera with "Rotate". Next I would "Move" the camera by the desired amount using the matrix that Rotate provides. Then finally, store the transformed position in x, y and z?

Is that right?

Siwko

zen
05-04-2001, 10:09 AM
Right,only the operations are actually taking place in the reverse order.Have a look at the 3rd chapter of the red book for more on that.So to convert camera to worlds coordinates extarct a roation matrix out of the orientation quaternion,cal. its transpose and multiply the world translation values (as a (x,y,z) vector) by it.

SlyFox
05-05-2001, 12:14 AM
This is very similiar to a question I recently posed, is there some example source or documentation on this sort of thing you could point us at?

zen
05-05-2001, 03:54 AM
There are a couple camera tutorials on-line but I didn't find them to be of very much help.You can give'em a rty though.You should be able to find them quite easily.