64
Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition Chapter 4

Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

  • Upload
    ezra

  • View
    35

  • Download
    0

Embed Size (px)

DESCRIPTION

Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition. Chapter 4. Figure 4.1: Screenshot of box.cpp. Figure 4.2: Translation: glTranslatef(p, q, r). Figure 4.3: Translating into the viewing frustum. Figure 4.4: Screenshot of Experiment 4.3. Figure 4.5: Scaling: - PowerPoint PPT Presentation

Citation preview

Page 1: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Computer Graphics Through OpenGL: From Theory to

Experiments, Second Edition

Chapter 4

Page 2: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.1: Screenshot ofbox.cpp.

Page 3: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.2: Translation: glTranslatef(p, q, r).

Page 4: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.3: Translating into the viewing frustum.

Page 5: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.4: Screenshot ofExperiment 4.3.

Page 6: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.5: Scaling:glScalef(u, v, w).

Page 7: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.6: Screenshot ofinitial configuration ofExperiment 4.4.

Page 8: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.7: Reflection inthe yz-plane.

Page 9: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.8: Screenshots of Experiment 4.5: (a) before scaling (b) after.

Page 10: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.9: Screenshotfor Experiment 4.6.

Page 11: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.10: Turningalong a cylinder.

Page 12: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.11: Rotation: glRotatef(A, p, q, r). The point P is rotated according tothe 4-step process in the text. The rotation of a box is also shown.

Page 13: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.12: glRotatef(A, 0.0, 0.0, 1.0).

Page 14: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.13: Screenshots from Experiment 4.9.

Page 15: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.14: Rotating a square about its own center.

Page 16: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.15: Screenshots: (a) Experiments 4.10 and (b) 4.11.

Page 17: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.16: Local system (bold) coincides with the global initially. The global systemis fixed.

Page 18: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.17: Transitions of the box, the box's local coordinates system (bold) and thesphere. The world coordinate system, which never changes, coincides with the box'sinitial local.

Page 19: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.18: Screenshotof relativePlacement.cppafter all transformationsfrom the scaling down havebeen executed.

Page 20: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.19: Planning a head on a torso: (a) The plan (b) Drawn without isolating thescaling (c) After isolating the scaling.

Page 21: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.20: Transitions of the modelview matrix stack.

Page 22: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.21: Screenshotof rotatingHelix1.cpp.

Page 23: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.22: Animationcontrol inrotatingHelix3.cpp.

Page 24: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.23: Successivecycles in double buffering.

Page 25: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.24: Screenshotof ballAndTorus.cpp.

Page 26: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.25: The ball's axis of latitudinal rotation from its start position is L.

Page 27: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.26: Screenshotfrom Experiment 4.21.

Page 28: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.27: Screenshotof throwBall.cpp.

Page 29: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.28: Ballbouncing off wall.

Page 30: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.29: Screenshot of (a) clown1.cpp (b) clown2.cpp (c) clown3.cpp.

Page 31: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.30: (a) Cone drawn by glutWireCone(base, height, slices, stacks) (b)Torus drawn by glutWireTorus(inRadius, outRadius, sides, rings). Note that the axesare depicted differently in each diagram.

Page 32: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.31: Screenshotof floweringPlant.cpp inmid-bloom.

Page 33: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.32: (a) Ball rolling down one plane (b) Ball rolling down two planes (c) Ballbouncing on a box (d) Ball traveling along a helix (e) Four segments opening from asquare into a straight line (f) Solar system with a sun, one planet and two moons (g)Pool table with one ball.

Page 34: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.33: (a) The (conceptual) OpenGL camera's default pose (b) A (conceptual)point camera at the origin with film on the viewing plane of the frustum.

Page 35: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.34: Camera pose determined by gluLookAt(eyex, eyey, eyez, centerx,centery, centerz, upx, upy, upz).

Page 36: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.35: (a) gluLookAt(): the broken frustum is the original viewing frustum, theunbroken one is where it's translated by the gluLookAt() call, the box doesn't move. (b)glTranslatef(): the viewing frustum doesn't move, rather the box is translated by theglTranslatef() call.

Page 37: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.36: Sectional diagrams of the (simulated) conguration of the eye and frustumfor various gluLookAt() calls in boxWithLookAt.cpp.

Page 38: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.37: Screenshots from Experiment 4.28.

Page 39: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.38: Taking thedot product:u·v = |u||v|cos θ .

Page 40: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.39: (a)Splitting v intocomponents v1 and v2,parallel and perpendicularto u, respectively (b) v2 asthe “shadow” of v on aplane p perpendicular to u.

Page 41: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.40: The camera is seen face-forward so that its back-plane p lies on the page.The line of sight los comes perpendicularly up from the page toward the reader. Thecomponents of the vector up, parallel and perpendicular to los, respectively, are up1 andup2 (the latter lying on the page).

Page 42: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.41: Solution to Exercise 4.44(a).

Page 43: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.42: Checkingthe solution toExercise 4.44(a).

Page 44: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.43: Camera flying over balls.

Page 45: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.44: Camerarotated on an imaginarysphere enclosing a teapot.

Page 46: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.45: Relative movement of the camera and scene.

Page 47: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.46: Restoring the camera to its default pose: broken arrows indicatemovements which applied take the camera to the next conguration in the sequence(a)-(d).

Page 48: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.47: Screenshotfrom Experiment 4.30.

Page 49: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.48: Viewing transformation equivalent to a sequence of modelingtransformations.

Page 50: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.49: Applying a translation (1) and rotations (2)-(4) about the threecoordinate axes to bring the camera back to its default pose. The original line of sight isbold. The up direction is shown only at the end.

Page 51: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.50: Solution to Example 4.6: the configuration of the camera given bygluLookAt(0.0, 0.0, 0.0, 1.0, 1.0, 0.0, -1.0, 1.0, 0.0) is at left; the line ofsight and up vectors are indicated by blue arrows; rotations are both annotated at thetop and indicated in the figures themselves by broken arrows, the result of each rotationbeing the next configuration.

Page 52: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.51: Screenshot of spaceTravel.cpp.

Page 53: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.52: Spacecraft diagrams.

Page 54: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.53: Ball rollingtoward a box.

Page 55: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.54: Screenshotof animateMan1.cpp.

Page 56: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.55: Screenshotof animateMan1.cpp indevelop mode.

Page 57: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.56: Screenshotof animateMan2.cpp.

Page 58: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.57: Screenshotof ballAndTorus-Shadowed.cpp.

Page 59: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.58: OpenGL's synthetic-camera pipeline (highly simplified!).

Page 60: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.59: Screenshotfrom selection.cpp.

Page 61: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.60: Name stack configurations: (a) Initial (b) When the red rectangle isdrawn (c) When the green rectangle is drawn.

Page 62: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.61: Clicking P “hits” the aircraft because the latter intersects V’.

Page 63: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.62: Screenshotof ballAndTorus-Picking.cpp momentsafter the ball has beenclicked.

Page 64: Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition

Figure 4.63: Color coding.