Presentation is loading. Please wait.

Presentation is loading. Please wait.

Representing Transformations, The TRANSF Package Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday,

Similar presentations


Presentation on theme: "Representing Transformations, The TRANSF Package Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday,"— Presentation transcript:

1 Representing Transformations, The TRANSF Package Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 11, 2004

2 11 Feb 2004CS 481/6812 Review: Stenciling Effects Stenciling means restricting drawing to a region related to some previous drawing. It is much more versatile than it sounds. In OpenGL, we implement stenciling-based effects using the stencil buffer and the stencil test. Last time, we discussed how to use stenciling to do: “Ordinary” Stenciling Restrict drawing to a specified area of the screen. E.g., a window (in any sense of the word). Or restrict a (projection-based) shadow to the object it falls on. The Reverse Painter’s Algorithm Draw front-to-back (somehow … use a BSP tree?). Restrict drawing to pixels whose colors have not been set yet. Capping Hide interiors of closed surfaces that are cut by a clipping plane. Draw a large rectangle in the “capping color”, restricting drawing to pixels whose colors have been set an odd number of times.

3 11 Feb 2004CS 481/6813 Review: Shadow Volumes A final (and much more complex) stenciling-based technique is shadowing via “shadow volumes”. The shadow volume of a polygon is the 3-D region that it hides from the light. For this technique, we assume that the shadow volumes of our polygons do not overlap (although they may touch). Consider the boundaries of shadow volumes. A point is in shadow precisely when we look through an odd number of these boundaries to see it. Assuming the viewer is not in shadow. If the viewer is in shadow, change “odd” to “even”. Zero is even (and not odd)! See shadowvol.cpp for sample code.

4 11 Feb 2004CS 481/6814 Representing Transformations: Rotations: Pro’s & Con’s 44 Matrices Very general. Good for a pipeline! Too general? Tough to retrieve info about “the rotation” when you cannot even be sure it is a rotation. 16 numbers. Angle-Axis Nice way to specify rotations. A bit nasty for computation involving rotations (composition, etc.) Euler Angles (roll, pitch, yaw) Ick! Ick, ick, ick, ick! One & only exception: billboarding (maybe). Quaternions (coming up) Great for computation. Compact. Easy to convert to other forms. Best (IMHO) all-around representation, if you only need to represent rotations.

5 11 Feb 2004CS 481/6815 Representing Transformations: Quaternions [1/2] The quaternions are a generalization of complex numbers. Three square roots of –1: i, j, k. Quaternions are of the form a + bi + cj + dk, for a, b, c, d real numbers. Addition, subtraction are as usual (component-wise). For multiplication: i 2 = j 2 = k 2 = –1. ij = k; jk = i; ki = j. ji = –k; kj = –i; ik = –j. Multiplication is not commutative! But it is associative: (xy)z = x(yz). Use the distributive rule plus the above facts to do multiplication.

6 11 Feb 2004CS 481/6816 Representing Transformations: Quaternions [2/2] We can think of the i, j, k part of a quaternion as a 3-D vector. So a quaternion is a real number plus a vector: a + u. a is the real part. u is the vector part or pure part. Addition: (a + u) + (b + v) = (a + b) + (u + v). Subtraction: (a + u) – (b + v) = (a – b) + (u – v). Multiplication: (a + u)(b + v) = (ab – u·v) + (av + bu + uv).

7 11 Feb 2004CS 481/6817 Representing Transformations: Rotations As Quaternions [1/2] We represent a rotation of an angle α about an axis u (unit vector) as a quaternion as follows:

8 11 Feb 2004CS 481/6818 Representing Transformations: Rotations As Quaternions [2/2] With this representation, composition of rotations is just multiplication. q 1 q 2 is the quaternion representing the rotation of q 2 followed by the rotation of q 1. The conjugate of a quaternion a + u is the quaternion a – u. We denote the conjugate by placing a bar over a letter: To apply the rotation represented by q to the point p (thought of as a vector), we compute the vector part of:

9 11 Feb 2004CS 481/6819 Representing Transformations: General Rigid Transformations A transformation of a rigid 3-D body can be modeled as: A rotation about a line through the origin … Followed by a translation. We can represent the rotation as we have discussed. The translation can be represented as a 3-D vector. The coordinates are those of the point that the transformation takes the origin to. Putting these together, we can represent anything a rigid body can do: Any translation. Any rotation. Corkscrew motions as well. This also gives us a way to represent a “frame of reference” in 3-D space.

10 11 Feb 2004CS 481/68110 The TRANSF Package: Introduction Dr. Hartman and I are writing a C++ transformations package including: Vector algebra. Interpolation. Translations, rotations, and general rigid transformations. The package will be made available to the class and may be used in assignments. We call it “TRANSF” for now. Think of a better name?

11 11 Feb 2004CS 481/68111 The TRANSF Package: Overview [1/2] TRANSF defines 6 classes: vec : 3-D vector Or translation, if you like pos : Position in 3-D space rot : 3-D rotation orient : Orientation in 3-D space transf : 3-D rigid transformation Rotation + translation frameref : A frame of reference in 3-D space Also a low-feature quaternion class called tfquat.

12 11 Feb 2004CS 481/68112 The TRANSF Package: Overview [2/2] The 6 classes can be classified as follows: TRANSF has two source files: vecpos.h Defines and implements classes vec & pos. transf.h Defines and implements classes rot, orient, transf, frameref. Also #include ’s vecpos.h. All classes and global functions are placed in namespace tf. There is also a file tfogl.h. This is an experimental OpenGL interface. So you can do things like glVertex(p); where p is of type tf::pos. This file should be #include ’d after glut.h. RelativeAbsolute vecpos rotorient transfframeref

13 11 Feb 2004CS 481/68113 The TRANSF Package: Sample Code [1/2] #include using namespace tf; vec v1; v1[0] = 1.; v1[1] = 2.; v1[2] = 3.; vec v2(2.,0.,-5.); vec v3 = 3.*v1-2.*v2; vec v4 = cross(v1, v2); double d1 = dot(v1, v2); double d2 = v1.length();

14 11 Feb 2004CS 481/68114 The TRANSF Package: Sample Code [2/2] #include using namespace tf; pos p1; rot r1; rot r2(30., vec(1., 2., 3.)); // Angle-axis. Angle is in degrees. rot r3 = r1.inverse().compose(r2); pos p2 = r3.applyto(p1); rot r4 = rotfromto(p1, p2);


Download ppt "Representing Transformations, The TRANSF Package Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday,"

Similar presentations


Ads by Google