0% found this document useful (0 votes)
52 views14 pages

CG Lab - Lect 5-Exercise

This document outlines exercises for a computer graphics lab involving 3D modeling and projections. It discusses: 1. Using keyboard events to interactively control camera position and projection variables. 2. Implementing perspective projection and changing the camera position using variables for near, far, and camera translation values. 3. Demonstrating the differences between perspective projection and orthographic projection while interactively controlling the camera position. 4. Rendering basic 3D shapes like cubes, teapots, spheres, and platonic solids using OpenGL functions and controlling their display.

Uploaded by

Hazim
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)
52 views14 pages

CG Lab - Lect 5-Exercise

This document outlines exercises for a computer graphics lab involving 3D modeling and projections. It discusses: 1. Using keyboard events to interactively control camera position and projection variables. 2. Implementing perspective projection and changing the camera position using variables for near, far, and camera translation values. 3. Demonstrating the differences between perspective projection and orthographic projection while interactively controlling the camera position. 4. Rendering basic 3D shapes like cubes, teapots, spheres, and platonic solids using OpenGL functions and controlling their display.

Uploaded by

Hazim
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/ 14

+

Computer Graphics Lab


14012501-3
Lecture 5
+
Outline

n Keyboard Events => glutSpecialFunc

n Projection

n View function => camera

n 3D objects
+
Your program initially have this
output

Void init()
{
glMatrixMode(GL_PROJECTION);
gluPerspective( 65, (win_width/win_hight), 0.01, 50 )
glMatrixMode(GL_MODELVIEW);
gluLookAt(5, 5, 5, 0, 0, 0, 0, 1, 0);
}
+
Exercise 1: keyboard special keys

In your code you have 5 declared variables:


n float transValueX; // translate the camera x position
n float transValueY; // translate the camera y position
n float transValueZ; // translate the camera z position
n float near;
n float far;

n All these variables are already initialized in the init function

n Use the glutSpecialFunc function to interact with the variables


transValueY & transValueX (to the camera position)
1. Use the GLUT_KEY_UP to increase the value of transValueY by 0.1 &
2. The GLUT_KEY_DOWN to decrement the value of transValueY by 0.1
3. The GLUT_KEY_RIGHT to increase the value of transValueX by 0.1 &
4. The GLUT_KEY_LEFT to decrement the value of transValueX by 0.1
+
Exercise 1: keyboard function

n For the other variables:


n float transValueZ; // translate the camera z position
n float near;
n float far;

n Use the glutKeyboardFunc function to interact with the variables


transValueZ, far & near
1. Use the letter ‘Z’ to increase the value of transValueZ by 0.1 &
2. Use the letter ‘z’ to decrement the value of transValueZ by 0.1
3. Use the letter ‘N’ to increase the value of near by 0.1 &
4. Use the letter ‘n’ to decrement the value of near by 0.1
5. Use the letter ‘F’ to increase the value of far by 0.1 &
6. Use the letter ‘f’ to decrement the value of far by 0.1

n You can use some C++ print statement to show the change in the
transValueX values. Example:
n cout<<“The translate X: ”<<transValueX<<endl;
+
Exercise 2: Perspective Projection
& camera
n In your display function, use the functions:
gluPerspective & gluLookAt => don’t forget using the appropriate
matrix for each!!!

n Use all the previous variables and interactively change their values
using the keyboard events.

n Use transValueX, transValueY, transValueZ to change the camera


position using the gluLookAt function.

n Use near, far to change the perspective projection near & far values.

n Test case1: interactively change the near value to 3.41

n Test case2: Now try in anther example to interactively change the far
value to 4

n Do you Understand the differences?!


+
Exercise 2: Output

gluPerspective( 65, (win_width/win_hight), near, far); gluPerspective( 65, (win_width/win_hight), near, far);
With far value = 4 With near value = 3.41
+
Exercise 3: Camera

n Test case3: gluPerspective & gluLookAt interactively


change only the transValueZ of camera position to 0.1

n Test case4: glOrtho & gluLookAt interactively change only


the transValueZ of camera position to 0.1

n Can you see the differences?!


+
Exercise 3: Output

gluPerspective( 65, (win_width/win_hight), near, far); glOrtho(-6, 6,-6, 6,near, far);


gluLookAt(transValueX, transValueY, transValueZ, 0, gluLookAt(transValueX, transValueY, transValueZ, 0,
0, 0, 0, 1, 0); 0, 0, 0, 1, 0);
With transValueZ value = 0.1 With transValueZ value = 0.1
+
Exercise 4: Some Stander shapes

n Rather than using the drawCube function provided in the


code use one of these functions:
n glutWireTeapot(size);
n glutSolidTeapot(size);
n glutWireTetrahedron();
n glutSolidTetrahedron();
n glutWireCube(edge length);
n glutSolidCube(edge length);
n glutWireOctahedron();
n glutSolidOctahedron();
n glutWireDodecahedron();
n glutSolidDodecahedron();
n glutWireIcosahedron();
n glutSolidIcosahedron();
n glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
n glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
+
Exercise 4: Output

glutWireCube(1); glutWireTeapot(1); glutSolidSphere(1.0, 20, 20);


glutSolidCube(1); glutSolidTeapot(1); glutWireSphere(1.0, 20, 20);
+
Exercise 4: Output

glutWireDodecahedron(); glutWireOctahedron() glutWireIcosahedron()


glutSolidDodecahedron glutSolidOctahedron() glutSolidIcosahedron()
+
You can search for more like
+
You can search for more like

You might also like