Original Post
🔒 Locked
OpenGL camera
Advertisement
How can I create an opengl camera?
Hi there,
nice name for asking that question :3
In general a camera is realized over a view-matrix.
This is a 4x4-matrix, which moves and rotates your scene against the camera.
So if your virtual camera rotates right, the view-matrix needs to rotate the vertices of your scene to the left.
If your virtual camera moves forward, the view-matrix needs to move the vertices of your scene backwards.
I would highly recommend to read about the basics of 3D-maths and computer-graphics matrices.
Have a look at the red book's chapter about viewing.
If you're using the deprecated fixed-function-pipeline (glBegin(), glVertex(), ... instead of shaders) you can change the view-matrix with the glTranslate- and glRotate-functions. Those functions change the matrix like you would expect it from a camera.
// Choose the Model-View-Matrix
glMatrixMode(GL_MODELVIEW);
// Rotate the camera 90 degrees around it's x-axis
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
// Move the camera-position along it's new x-axis (after rotation)
glTranslatef(10.0f, 0.0f, 0.0f);
If you want to use shader, you need an extern matrix-class or a 16-float array representing that matrix, which you then load onto the gpu-memory.
[quote name='openglpro' timestamp='1323561214' post='4892665']
How can I create an opengl camera?
Hi there,
nice name for asking that question :3
In general a camera is realized over a view-matrix.
This is a 4x4-matrix, which moves and rotates your scene against the camera.
So if your virtual camera rotates right, the view-matrix needs to rotate the vertices of your scene to the left.
If your virtual camera moves forward, the view-matrix needs to move the vertices of your scene backwards.
I would highly recommend to read about the basics of 3D-maths and computer-graphics matrices.
Have a look at the red book's chapter about viewing.
If you're using the deprecated fixed-function-pipeline (glBegin(), glVertex(), ... instead of shaders) you can change the view-matrix with the glTranslate- and glRotate-functions. Those functions change the matrix like you would expect it from a camera.
// Choose the Model-View-Matrix
glMatrixMode(GL_MODELVIEW);
// Rotate the camera 90 degrees around it's x-axis
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
// Move the camera-position along it's new x-axis (after rotation)
glTranslatef(10.0f, 0.0f, 0.0f);
If you want to use shader, you need an extern matrix-class or a 16-float array representing that matrix, which you then load onto the gpu-memory.
[/quote]
If he is using old OpenGL he could far more easily use gluLookAt. (Which makes implementing a camera trivial)
http://www.dei.isep....uLookAt.3G.html has a description of how the function works aswell if you wish to replicate it using a modern OpenGL version.
[quote name='Fnord42' timestamp='1323564855' post='4892677']
[quote name='openglpro' timestamp='1323561214' post='4892665']
How can I create an opengl camera?
Hi there,
nice name for asking that question :3
In general a camera is realized over a view-matrix.
This is a 4x4-matrix, which moves and rotates your scene against the camera.
So if your virtual camera rotates right, the view-matrix needs to rotate the vertices of your scene to the left.
If your virtual camera moves forward, the view-matrix needs to move the vertices of your scene backwards.
I would highly recommend to read about the basics of 3D-maths and computer-graphics matrices.
Have a look at the red book's chapter about viewing.
If you're using the deprecated fixed-function-pipeline (glBegin(), glVertex(), ... instead of shaders) you can change the view-matrix with the glTranslate- and glRotate-functions. Those functions change the matrix like you would expect it from a camera.
// Choose the Model-View-Matrix
glMatrixMode(GL_MODELVIEW);
// Rotate the camera 90 degrees around it's x-axis
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
// Move the camera-position along it's new x-axis (after rotation)
glTranslatef(10.0f, 0.0f, 0.0f);
If you want to use shader, you need an extern matrix-class or a 16-float array representing that matrix, which you then load onto the gpu-memory.
[/quote]
If he is using old OpenGL he could far more easily use gluLookAt. (Which makes implementing a camera trivial)
http://www.dei.isep....uLookAt.3G.html has a description of how the function works aswell if you wish to replicate it using a modern OpenGL version.
[/quote]
Nice addition, completely forgot to mention gluLookAt.
But it doesn't always make camera-implementation more trivial.
If he goes for first-person mouse-look for example, it would be easier to just add the the difference of the mouseposition to the rotation around the y-axis.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement