Opengl Camera
Hi i want to find a way to make a camera in Opengl. I have used some things but none is working. Also i ve seen how some people use gluLookAt. But i dont know exactly how to make an opengl camera for a 3d engine. Can anyone send some help or hints?Thanx
Talos
A common way of implementing a camera is this:
struct Camera
{
float Position[3];
float Yaw;
float Pitch;
float Roll;
};
To use this way you have to initialize the MODELVIEW matrix like so:
glTranslate3f(-Position[0], -Position[1], -Position[2]);
glRotatef(-Roll, 0, 0, 1);
glRotatef(-Pitch, 1, 0, 0);
glRotatef(-Yaw, 0, 1, 0);
Another way, which is more suitable for use with gluLookAt:
struct Camera2
{
float Position[3];
float LookAt[3]; // The coordinate that the camera is focusing on
float CameraUp[3]; // The direction of the camera''s upvector in world coordinates
};
With this structure it is, as I mentioned easier to use gluLookAt:
gluLookAt(Position[0],Position[1],Position[2],
LookAt[0],LookAt[1],LookAt[2],
CameraUp[0],CameraUp[1],CameraUp[2]);
(I''m too lazy to write correct C code here, but you get the idea.)
struct Camera
{
float Position[3];
float Yaw;
float Pitch;
float Roll;
};
To use this way you have to initialize the MODELVIEW matrix like so:
glTranslate3f(-Position[0], -Position[1], -Position[2]);
glRotatef(-Roll, 0, 0, 1);
glRotatef(-Pitch, 1, 0, 0);
glRotatef(-Yaw, 0, 1, 0);
Another way, which is more suitable for use with gluLookAt:
struct Camera2
{
float Position[3];
float LookAt[3]; // The coordinate that the camera is focusing on
float CameraUp[3]; // The direction of the camera''s upvector in world coordinates
};
With this structure it is, as I mentioned easier to use gluLookAt:
gluLookAt(Position[0],Position[1],Position[2],
LookAt[0],LookAt[1],LookAt[2],
CameraUp[0],CameraUp[1],CameraUp[2]);
(I''m too lazy to write correct C code here, but you get the idea.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement