0% found this document useful (0 votes)
17 views3 pages

TP2 Camera ENG

Uploaded by

yehya2792003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

TP2 Camera ENG

Uploaded by

yehya2792003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Machine Translated by Google

Camera placement in OpenGL


This lab aims to understand how to place (and move) the camera in OpenGL. We are going to create a walk
type navigation, that is to say that we will be able to move around the scene like a user who can walk in space.

Reminders
To be able to move the camera and place the point of view anywhere in the scene, we use a kind of virtual
camera with the function call:

gluLookAt(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ)

• eyeX, eyeY and eyeZ define the position of the camera,


• centerX, centerY and centerZ define the position of the point fixed by the camera (the corresponding
point will be in the center of the display window),
• upX, upY and upZ deny the vertical vector.

Placing the camera means moving everyone so that they are centered on the camera and oriented along
the line of sight. This therefore logically influences the GL MODELVIEW matrix and you will
not be surprised that the camera is called just after resetting GL MODELVIEW.
Machine Translated by Google

Examples:
In our initial scene, the cube is placed at (0.,0.,0):
The call to the gluLookAt(0., 0., -10., 0., 0., 0., 0., 1., 0.) function; allows you to see the back of the cube:

Change the vertical (the parameters vertX, vertY and vertZ) and therefore call the function gluLookAt(0.,
0., 0., 0., 0., -5., 1., 1., 0.); allows you to tilt the stage

We will now move the camera using the keyboard arrows.

• Position a Camera in init using the following parameters: eye = {0.,0.,1.,}, aim = {0.,0.,-1.,} and up =
{0.,1., 0.5,0.}. • Add the gluLookAt(...) function
in your code (display). You should know that this function applies to the stack of MODELVIEW matrices
and that you want to position the camera before placing and tracing the different objects in the
scene.

Management of keyboard events:

• Each press of a key causes a movement (in translation or rotation) and the movement is carried out by
calculating the new values of the parameters of the gluLookAt() function. It is therefore no longer
a question of stacking and unstacking OpenGL transformation matrices, but of calculating "by hand" the
new O,X,Y,Z parameters of the camera to move it. For example, for a forward translation, we move the
position O of the camera a certain number of times on the vector Z.

For a rotation, O is fixed, but we will change the orientation of the vectors X,
Y and Z. • Your
gluLookAt(...) is defined as follows:

We are going to create a walk type navigation , that is to say that we will be able to
move around the scene like a user who can walk in space. The following
functionalities will need to be developed:

• move forward/backward: the camera moves forward or backward in its Z


direction, • turn left/right by rotating around the vertical Y axis of the camera, •
orient itself upwards/ bottom by rotation around the horizontal axis X of the camera.
Machine Translated by Google

To do this, we will use the keyboard arrows for forward/backward and left/right, as well as the h and b keys
for up/down.

Go forward go backward

Start by moving the camera forward/backward. Please note, the movement is made in the direction of the
camera's Z vector.

Rotate left/right, Rotate up/down


Now let's look at the rotations:
• The rotation around the Y axis will be carried out using the following method:
1. Move the target point (which is always O + Z ) in the direction of the vector

2. Calculate the new unit vector Z corresponding to the new position of the point
targeted and finally calculate the new vector
3. Calculate the new vector X.

On the same principle, perform the up/down rotation

You might also like