Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale

Similar presentations


Presentation on theme: "Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale"— Presentation transcript:

1 Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
reflection glRotate composing transformations placing multiple objects

2 MJBBasicTransformations.cpp rotation scaling translation

3 Multiple rotation experiment
work in pairs: Both, place book face up so you can read it. Person 1, rotate 90 degrees around z-axis, then rotate 180 degrees around y axis. Person 2, rotate 180 degrees around y axis, then rotate 90 degrees around z-axis. Compare.

4 Multiple rotation experiment
Conclutions: Order Matters!

5 PROJECTION and MODELVIEW Matrices
GL_MODELVIEW is for organizing the pieces of the picture - building the model. GL_PROJECTION is for setting viewing box and type of projection for viewing.

6 PROJECTION and MODELVIEW Matrices
Both matrices are alway active and being used. We can only change or set one at a time. To modify one we have to put it in the "matrix modifying machine", eg glMatrixMode(GL_PROJECTION); glMatrixMode(GL_MODELVIEW);

7 PROJECTION and MODELVIEW Matrices
To make sure we start with a clean slate: glLoadIdentity(); Any new changes are made to the matrix that is currently "in Mode". The current state of both is used for whatever is being drawn.

8 PROJECTION Matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho... or glFrustum... This is usually in resize routine, but it can be modified in display routine. Remember to then return to the MODELVIEW matrix, glMatrixMode(GL_MODELVIEW);

9 Modeling Transformations
Run box.cpp In resize: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 100.0); glMatrixMode(GL_MODELVIEW);

10 box.cpp in drawScene glLoadIdentity(); // Modeling transformations. glTranslatef(0.0, 0.0, -15.0); glutWireCube(5.0); // Box. //A 5x5 cube, centered at the origin

11 Moving the box into view

12 glTranslatef( p, q, r) translate (x,y,z) to (x+p,y+q,z+r);
Reminder - away from your eye is NEGATIVE z direction.

13 boxV2.cpp //Modeling Transformations glTranslatef(0.0, 0.0, -15.0);
... glScalef(.7,2.0,3.0); Run boxV2.cpp

14 boxV2.cpp Black box is First scaled (while at the origin)
Then translated.

15 glScalef(u,v,w); maps (x, y, z) of an object to (u*x, v*y, w*z)

16 Reflection glScale(1.0, -1.0, 1.0); Run boxV3.cpp.
press m to see before and after reflection. Notice toggle.

17 boxV4.cpp //Modeling Transformations glTranslatef(0.0, 0.0, -15.0);
... glRotatef(60.0, 0.0,0.0,1.0); glutWireTeapot(3.0); Run and look at boxV4.cpp

18 boxV4.cpp glRotatef(60.0, 0.0,0.0,1.0); Counterclockwise rotation looking from origin to (0,0,1) or (0,0,1) to origin?

19 boxV4.cpp glRotatef(60.0, 0.0,0.0,1.0); Counterclockwise rotation looking from origin to (0,0,1) or (0,0,1) to origin?

20 glRotatef(A, p, q, r) rotate around the vector (p, q, r)
A is the angle in degrees, counterclockwise looking from the point (p, q, r) toward the origin

21 Transformations Run the experiments in the book. Think through the answer before you run it.

22 Composing Transformations
run boxV5.cpp, draw on board Key input t: glTranslatef(10.0,0.0,0.0); glRotatef(45.0, 0.0,0.0,1.0); glutWireCube(5.0); Key input r:

23 Placing multiple objects
Do experiment with Powerpoint:

24 Trotate.cpp //Modeling Transformations glTranslatef(0.0, 0.0, -15.0);
... glRotatef(60.0, 0.0,0.0,1.0); glBegin(GL_LINES); glVertex3f(0, 0, 0); glVertex3f(3, 0, 0); glVertex3f(3, -1, 0); glVertex3f(3, 1, 0); glEnd(); Run and look at Trotate.cpp

25 boxV6.cpp original - a box and a sphere draw on board
m: translate together o: say translate then rotate, but really rotate then translate Check out the code! try ortho and frustrum

26 pushPopDemo.cpp Any transformations (rotate,translate, scale) put inside a glPushMatrix() and a glPopMatrix() pair are ignored outside that pair. Other statements (color, draw something,...) are NOT ignored

27 pushPopDemo.cpp Any transformations (rotate,translate, scale) put inside a glPushMatrix() and a glPopMatrix() pair are ignored outside that pair. Other statements (color, draw something,...) are NOT ignored


Download ppt "Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale"

Similar presentations


Ads by Google