Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class 10 Part 1 What values to use for Frustum The Trick

Similar presentations


Presentation on theme: "Class 10 Part 1 What values to use for Frustum The Trick"— Presentation transcript:

1 Class 10 Part 1 What values to use for Frustum The Trick
Relative vs Absolute Placement glPushMatrix glPopMatrix Animation glutIdleFunc(increaseAngle) glutTimerFunc Double Buffering Iron Maiden example BallAndTorus

2 What values to use for glFrustum?
Uses glFrustum(-5.0,5.0,-5.0,5.0,5.0,100.) Picture translated to z=-25

3 -far ?? ? z right -near

4 -far ?? far = ?? near right far * right= ?? near ? z |z| * right= ? near right -near

5 -far ?? 25 * 5 = 25 5 ? z |z| * right= ? near right -near

6 The Trick - rotating about a general line
MJBrotateOffCenter.cpp glRect(x1,y1,x2,y2) draws a rectangle, not at the origin. What if we want to rotate it about its center? The TRICK: move to the origin, rotate, move back.

7 Relative vs Absolute Placement
Case 1: put cube 5 to the right, put sphere 10 above it.(relative) Case 2: put cube 5 to the right, put sphere 10 above the origin. (absolute) MJBrelativeVSabsolute.cpp

8 Relative: Prop 4.1 "If object 1 precedes object 2 in the code, the location of object 2 in the local coordinate system of object 1 is determined by the transformation statements between the two and nothing else." See relative code

9 glPushMatrix(), glPopMatrix
glLoadIdentity(); glTranslatef(0.0, 0.0, -15.0); glPushMatrix(); glTranslatef(15.0,0.0,0.0); glutWireCube(5.0); glPopMatrix(); glTranslatef(0.0,10.0,0.0); glutWireSphere(4.0,10,10); I*M1=M1 M1 M1*M2=N2 M1 M1 M1*M3=N3

10 Animation The WRONG way: In the display function:
for (a lot times) redraw the picture with a minor change Doesn't allow for interaction. May not even be redrawn

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

12 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).

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

14 rotatingHelix3.cpp draw picture once
get on line in the event queue for another turn to add to angle get on line in the event queue ... got to here

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

16 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);

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

18 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

19 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();

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

21 ballAndTorus.cpp run it.

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

23 the Sphere glutWireSphere(2.0, 10, 10); radius 2 center at the origin

24 ballAndTorus.cpp

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

26 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);

27 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);

28 spiral motion about the torus
combine the two motions.


Download ppt "Class 10 Part 1 What values to use for Frustum The Trick"

Similar presentations


Ads by Google