CS 445/645 Fall 2001 Splines Last Class • Hermite and Bézier Splines – Understand how these curves are defined • The G matrix – Understand how.
Download ReportTranscript CS 445/645 Fall 2001 Splines Last Class • Hermite and Bézier Splines – Understand how these curves are defined • The G matrix – Understand how.
CS 445/645 Fall 2001 Splines Last Class • Hermite and Bézier Splines – Understand how these curves are defined • The G matrix – Understand how the curve definitions lead to the coefficient matrices • The M matrix – Blending functions – Convex Hulls Assignment 4, part 2 • One-week extension… – Program due December 5th at midnight • Quaternions not required – Will be extra credit • Reason for extension – We think you can have more fun with this assignment if you play with a couple new ideas Quaternions • Remember why we don’t like Euler angles – Gimbal lock – Arbitrary multiplication order – Interpolation Gimbal Lock • Occurs when two axes are aligned • Second and third rotations have effect of transforming earlier rotations – ex: Rot x, Rot y, Rot z • If Rot y = 90 degrees, Rot z == -Rot x Multiplication Order • (qx, qy, qz) = RzRyRx – Rotate qx degrees about x-axis – Rotate qy degrees about y-axis – Rotate qz degrees about z-axis • Axis order is not defined – (y, z, x), (x, z, y), (z, y, x)… are all legal – Pick one Interpolation Local Rotations • Multiple applications of small Euler angles cause numerical errors and drift – Consider 720 rotations about y of 1 degree cos(1) 0 sin(1) 0 0 1 0 0 0 cos(1) 0 0 0 1 0 sin(1) 720 .9999817 0 .017452374 0 0 .017452374 0 1 0 0 0 .9999817 0 0 0 1 720 – Should end up back where you started .9999817 0 .017452374 0 0 .017452374 0 1 0 0 0 .9999817 0 0 0 1 720 1 1 0 ? 0 0 0 0 0 Local Rotations • Not only is the Euler computation expensive • But it won’t provide the correct result • Matrices may not be orthonormal Quaternion • • • • Doesn’t suffer from Gimbal Lock Multiplication order is clear Interpolation is sensible Compositions are cheap Implementing Quaternions • • • • Instead of storing xrot and yrot Store quaternion Initially quaternion is set to (0, 0, 0, 1) If user moves mouse, multiply initial quaternion by a second quaternion corresponding to the rotation the user caused • When drawing scene convert current quaternion to rotation matrix and multiply on stack User Interaction • In handleMouseMovement() – You can keep track of the change in x and y between when the user clicked the mouse and released – Imagine the user had a sticky finger and touched the surface of a sphere encircling your model and then spun the sphere with their finger – How would the sphere have rotated? User Interaction • Compute points of surface of sphere where user first clicked and released • Use these points to compute • Amount of rotation (in degrees) • Cross product of vectors between sphere center and these two points • These will be your quaternion parameters User Interaction • Compute amount of rotation (cos (theta / 2) is scalar of quaternion) • Multiply rotation by scalar so rotations match mouse translation • Axis of rotation (use cross product) • Zero-out the z-component of axis • Normalize axis of rotation • Multiply axis of rotation by sin (theta/2) • You might have to normalize again • Multiply previous quaternion by this new quaternion to compose rotations Cube Mapping • Consider projection of triangle onto 2 faces of cube Other things • glTexSubImage2D • glUnproject • glDepthFunc (GL_LEQUAL) Making Movies • Next Class