Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class 12 Complex object with moving parts

Similar presentations


Presentation on theme: "Class 12 Complex object with moving parts"— Presentation transcript:

1 Class 12 Complex object with moving parts
Viewing Transformations: glLookAt Selection and Picking Intro to lighting (Chapter 11)

2 Assembling a Clown Head Run clown3.cpp
head radius 2 ear radius 0.5 Hat: height 4 radius 2 Brim: inner radius 0.2 outer radius 2.2 ear to head 0 - 2 Hat sits 2 units from center of head Tilted 30o from vertical

3 clown3.cpp figure out placement of ears
// Transformations of the left ear. glTranslatef(sin((PI/180.0)*angle), 0.0, 0.0); glTranslatef(3.5, 0.0, 0.0); // Transformations of the right ear. glTranslatef(-sin((PI/180.0)*angle), 0.0, 0.0); glTranslatef(-3.5, 0.0, 0.0);

4 clown3.cpp: spring to left ear
// Transformations of the spring to the left ear. glTranslatef(-2.0, 0.0, 0.0); glScalef(-1 - sin( (PI/180.0) * angle ), 1.0, 1.0); // Spring to left ear. glColor3f(0.0, 1.0, 0.0); glBegin(GL_LINE_STRIP); for(t = 0.0; t <= 1.0; t += 0.05) glVertex3f(t, 0.25 * cos(10.0 * PI * t), 0.25 * sin(10.0 * PI * t)); glEnd();

5 clown3.cpp Study the code. Notice the order of transformations
Notice the use of glPushMatrix() and glPopMatrix(). Observe how the animation is done.

6 floweringPlant.cpp run uses depth testing
uses 3 sequential display list: stem segment, sepal, petal

7 Viewing Transformation
gluLookAt( eyex, eyey,eyez, centerx, centery,centerz, upx, upy, upz ) eye is where the camera should be center is where it should be aimed up determines how we hold the camera

8 gluLookAt( eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz )
Line of Sight ( los) goes through eye and center. Vertex of pyramid that gives frustum is at eye. Near and Far measured from there. Line Of Sight runs through center of frustum "True up" is component of up perpendicular to los.

9 gluLookAt(0.0, 0.0, 0.0, 2.0, 0.0, 5.0, , 1.0, 0.0 ); 2 1 -4 -3 -2 -1 1 2 3 4 -1 -2 -3

10 gluLookAt(0.0, 0.0, 0.0, 2.0, 0.0, 5.0, , 0.0, 0.0 ); 2 1 -4 -3 -2 -1 1 2 3 4 -1 -2 -3

11 gluLookAt(2.0, 1.0, 0.0, 2.0, 0.0, 5.0, , 1.0, 0.0 ); 2 1 -4 -3 -2 -1 1 2 3 4 -1 -2 -3

12 gluLookAt( ); 2 1 -4 -3 -2 -1 1 2 3 4 -1 -2 -3

13 boxWithLookAt.cpp Run. Just like box, but with gluLookAt instead of glTranslate.

14 clown3.cpp Run. Modify to use gluLookAt instead of glTranslate.
Look from front of sphere, just touching. What do you see?

15 clown3.cpp Run. Modify to use gluLookAt instead of glTranslate.
Look from front of sphere, just touching. What do you see? Have to adjust glFrustum!

16 clown3.cpp Run. Modify to use glLookAt instead of glTranslate.
Look down from well above hat. What do you want "up" to be?

17 gluLookAt( eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz )
Apply to the MODELVIEW matrix, not the PROJECTION matrix Code: Load the MODELVIEW matrix Set matrix to the identiry Place your cameral Build your world using reasonable world coordinates

18 gluLookAt(eyex, eyey, eyez, centerx, centery, centerz,upx, upy, upz)
move the camera to (eyex, eyey, eyez) rotate till it is facing the center rotate about the line of sight till up is in the right direction. Is equivalent to moving the surrounding world: glRotate(B,0,0,1); glRotate(A, wx, wy, wz); glTranslate(-eyex, -eyey, -eyez);

19 gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
is equivalent to reverse of: Translate camera from eye to origin rotate the camera about the x-axis, till the line of sight lies on the x-z plane rotate the camera about the y-axis, (staying in the x-z plane) till the line of sight is pointing in the -z direction. rotate the camera about the line of sight ( = z-axis) till the top is pointing in the +y direction.

20 The 3 angles from the 3 "rotates" are the Euler angles.

21 simple shadow run ballAndTorusShadowed.cpp
in drawFlyingBallAndTorus see if(shadow) code. in drawScene see 2 calls to drawFlyingBallAndTorus "Light" is at infinity, directly overhead.

22 Picking and Selection Run BallAndTorusPicking.cpp to understand the problem. How computer knows which shape or color to use for drawing. How can the computer "know" which shape belongs to a pixel to modify?

23 glRenderMode(GL_SELECT)
Selection Tell computer you will be selecting glRenderMode(GL_SELECT) Specify a (new, small) viewing volume selection volume Redraw the scene, invisibly, recoding which items hit the viewing volume hit list

24 when hit records are written
A hit record is written into the hit buffer when both a name stack manipulation or a glRenderMode() command is encountered a hit has occured - a primitive has been drawn that intersects the selection volume

25 what hit records contain
the number of names in the name stack at the time of writing the record the min z-value‡ of primitives that hit selection volume since last hit record was written the max z-value‡ of primitives that hit selection volume since last hit record was written the sequence of names in the name stack at time of writing, bottom one first, may be none.

26 How to PICK the right selection volume?

27 gluPickMatrix(pickX, pickY, width, height, viewport[4])
glLoadIdentity(); gluPickMatrix(pickX, pickY,width,height, viewport[4]); glFrustrum(); or gluPerspective; or glOrtho; (same as resize function, or what the program is using.)

28 gluPickMatrix(pickX, pickY, width, height, viewport[4])
pickX and pickY are in gl screen coords. front face of selection volume is centered at (pickX, pickY) with given width and height. In pixels. viewport array supplies current viewport boundaries. Can use glGetIntegerv(GL_VIEWPORT,viewport)

29 min and max values ‡ min and max are "normalized" by dividing by depth of selection volume, so value is in range [0,1]. Then multiplied by and stored as an unsigned int.

30 ballAndTorusPicking.cpp void drawBallAndTorus(void)
void drawScene(void) // The mouse callback routine. void pickFunction(int button, int state, int x, int y) void findClosestHit(int hits, unsigned int buffer[]) void animate(int value)

31 ballAndTorusPicking Make these changes for better model
In function drawBallAndTorus remove glutSwapBuffers(); In function drawScene add glutSwapBuffers();

32 collision detection Run spaceTravel.cpp
Go through code - non-collision parts Notice class, constructors Notice viewports. Notice display list. Notice rand. In setup I added srand(time(0)); Need to include ctime I also changed FILL_PROBABILITY

33 geometry of the spacecraft
radius 5 height 10 red center to edge of circle =sqrt(50) = 7.072

34 geometry of collisions
Got to Here!!!!!!!!

35 collision detection spaceTravel.cpp
static int isCollision = 0; // Is there collision between the spacecraft and an asteroid? functions: int checkSpheresIntersection(...) int asteroidCraftCollision(...) see specialKeyInput function

36 Articulated Figure On your own, run animateMan.cpp.
Do the experiments in the book. Come back with questions.

37 Phong's Lighting Model Ambient light - even light all around. Direction of light and viewer don't matter. Diffuse - fine scale graininess of surface. Direction of light source matters, direction of viewer doesn't matter. Specular - shininess of surface. Direction of light source and viewer both matter.

38 Run sphereInBox1.cpp Observe box and ball materials and lighting.
Look at code later.

39 Lots of thing to specify for each light and material of objects
Ambient R, G, B Diffuse R, G, B Specular R, G, B For material, also emissive - looks like light coming from object. Specular also has a shininess component.

40 Normals To get proper reflection, we need to know "surface direction".

41 BoxAndSquaresPickingAndViews.cpp Cookie cutter approach – take advantage of it!


Download ppt "Class 12 Complex object with moving parts"

Similar presentations


Ads by Google