1 / 58

Class 12

Class 12. idle function timers Iron Maiden example Double Buffering BallAndTorus throwBall – incorporating physics Complex object with moving parts Viewing Transformations: glLookAt Cummulative Rotation Orientation and Euler Angles selection. rotatingHelix1.cpp. press space

bennerm
Download Presentation

Class 12

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class 12 idle function timers Iron Maiden example Double Buffering BallAndTorus throwBall – incorporating physics Complex object with moving parts Viewing Transformations: glLookAt Cummulative Rotation Orientation and Euler Angles selection

  2. rotatingHelix1.cpp • press space • increase angle • redraw (once) with the updated angle

  3. rotatingHelix2.cpp • press space • glutIdleFunc(increaseAngle); or glutIdleFunc(NULL); • registered Idle function: Keep doing that function as long as nothing else is happening. • increaseAngle() says add to the angle and redraw (once).

  4. glutIdleFunc(f); • registers the function to use while idle. • NULL for don't do anything. • void f(void); • Note functions can be "registered" outside of main, and the registered functions can change.

  5. rotatingHelix3.cpp • draw picture once • get on line in the event queue for another turn to • add to angle • draw picture once • get on line in the event queue ...

  6. glutTimerFunc(period,timerFunction, value) • put the timerFunction on the event queue period milliseconds from now. • void timerFunction(int value); • value, an input value that will be passed to the timerFunction • value is often not needed so is set to anything.

  7. using a timer • Main starts the timer function glutTimerFunc(5, animate, 1); run the function animate in 5 millisecs. • Have timer function call itself, ie, get in queue again. At the end of animate have the call glutTimerFunc(animationPeriod, animate, 1);

  8. Go through all of rotatingHelix3.cpp to see how whole process works.

  9. Double Buffering • front buffer = viewable buffer • back buffer = drawable buffer • Two ring circus: • spotlight on one ring : viewable • in the dark, set up the next act in other ring : drawable

  10. Double Buffering - how to • In main, glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); instead of GLUT_SINGLE Can have one window double buffered and the other single. • at end of display function use glutSwapBuffers(); instead of glFlush();

  11. Iron maiden example • maiden project • Nate Robbins gets credit. (Check out, but don't copy, his tutorials.)

  12. ballAndTorus.cpp • run it.

  13. the Torus • glutWireTorus(2.0, 12.0, 20, 20); • center is the origin.

  14. the Sphere • glutWireSphere(2.0, 10, 10); radius 2 center at the origin

  15. ballAndTorus.cpp

  16. move the sphere to the right, outside the torus glTranslatef(20.0, 0.0, 0.0); glutWireSphere(2.0, 10, 10);

  17. rotate sphere about one spot on the torus(revolve about the torus) • "latitudinal rotation" • about the line through (12,0,0), parallel to the y axis • in a circle of radius 8. • on the xz plane. • The TRICK glTranslatef(12.0, 0.0, 0.0); glRotatef(latAngle, 0.0, 1.0, 0.0); glTranslatef(-12.0, 0.0, 0.0);

  18. move the sphere in big circle about the torus • "longitudinal rotation" • about the line through (0,0,1), parallel to the z axis • in a circle of radius 20. • on the xy plane. • glRotatef(longAngle, 0.0, 0.0, 1.0);

  19. spiral motion about the torus • combine the two motions.

  20. throwBall.cpp • run it. • incorporate physics • x(t)=h*t • y(t)=v*t - g/2 * t*t // Apply equations of motion to transform sphere. glTranslatef(h*t, v*t - (g/2.0)*t*t, 0.0);

  21. Using a for loop for circle or time (or even color!) • On the white board • 10 points on a circle • 10 seconds of a flying ball • 50 shades of grey

  22. throwBall.cpp • note routine to print float to string • also note special key functions • Try out ballAndTorusWithFriction.cpp - more physics

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

  24. 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);

  25. 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();

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

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

  28. 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

  29. 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.

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

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

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

  33. gluLookAt( ); 2 1 -4 -3 -2 -1 1 2 3 4 -1 -2 -3

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

  35. boxWithLookAt.cpp • What do we see if our eye is in the middle of the right face of the box, looking to the center of the box? (And what should the gluLookAt be?) • What do we see if our eye is at a corner of the box, looking to the center? (And what should the gluLookAt be?) • What do we see if our eye is at the center of the box, looking forward, in the positive z direction?

  36. clown3.cpp • Run. Modify to use gluLookAt instead of glTranslate. • Get depth buffer working. • Look from front of sphere, just touching. • What do you see?

  37. 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!

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

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

  40. 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. gluLookAt(eyex, eyey, eyez, centerx, centery, centerz,upx, upy, upz) Is equivalent to moving the surrounding world: glRotate(B,0,0,1); glRotate(A, wx, wy, wz); glTranslate(-eyex, -eyey, -eyez);

  41. 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.

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

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

  44. 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?

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

  46. 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

  47. 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.

  48. 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 232-1 and stored as an unsigned int.

  49. How to PICK the right selection volume?

  50. gluPickMatrix(pickX, pickY, width, height, viewport[4]) glLoadIdentity(); gluPickMatrix(pickX, pickY,width,height, viewport[4]); glFrustrum(); or gluPerspective; or glOrtho; (same as resize function)

More Related