Presentation is loading. Please wait.

Presentation is loading. Please wait.

3-D Transformations Kurt Akeley CS248 Lecture 8 18 October 2007

Similar presentations


Presentation on theme: "3-D Transformations Kurt Akeley CS248 Lecture 8 18 October 2007"— Presentation transcript:

1 3-D Transformations Kurt Akeley CS248 Lecture 8 18 October 2007 http://graphics.stanford.edu/courses/cs248-07/

2 CS248 Lecture 8Kurt Akeley, Fall 2007 Overview Tuesday n 2-D transformation n Composition of 2-D transformations n Line equations, 2-D normals, and inverses Today n Apply 2-D concepts to 3-D n Look at OpenGL in some detail

3 CS248 Lecture 8Kurt Akeley, Fall 2007 Homogeneous 3-D coordinates

4 CS248 Lecture 8Kurt Akeley, Fall 2007 Homogeneous 3-D transformation Specify translation Specify rotation, scale, and shear (Almost) always have these values

5 CS248 Lecture 8Kurt Akeley, Fall 2007 Homogeneous translation and scale Translation: Scaling (about the origin):

6 CS248 Lecture 8Kurt Akeley, Fall 2007 Homogeneous rotation (about a coordinate axis) x y z Right-hand rule for rotations by positive θ

7 CS248 Lecture 8Kurt Akeley, Fall 2007 Homogeneous rotation (ccw about axis a )

8 CS248 Lecture 8Kurt Akeley, Fall 2007 Composition of transformations

9 CS248 Lecture 8Kurt Akeley, Fall 2007 The plane equation

10 CS248 Lecture 8Kurt Akeley, Fall 2007 Transforming the plane equation Plane equations are transformed by the inverse of the matrix used to transform vertexes

11 CS248 Lecture 8Kurt Akeley, Fall 2007 The normal to the plane n

12 CS248 Lecture 8Kurt Akeley, Fall 2007 Derivation

13 CS248 Lecture 8Kurt Akeley, Fall 2007 Transformation of normals (correct) Convert to plane equation, transform, and convert back:

14 CS248 Lecture 8Kurt Akeley, Fall 2007 Transformation of normals (approximation)

15 CS248 Lecture 8Kurt Akeley, Fall 2007 Elemental inverse transforms are simple

16 CS248 Lecture 8Kurt Akeley, Fall 2007 Transformation in OpenGL

17 CS248 Lecture 8Kurt Akeley, Fall 2007 The vertex pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a; } vertex; Framebuffer

18 CS248 Lecture 8Kurt Akeley, Fall 2007 Conceptual coordinate systems Vertex operations Transform v o by M Transform n o by M -1 Transform v w by V Transform v e by P Object coordinates World coordinates (lighting calculations) Eye coordinates Clip coordinates vovo vwvw veve vcvc nono nwnw Model transformation View transformation Projection transformation

19 CS248 Lecture 8Kurt Akeley, Fall 2007 Why not collapse to a single transformation? Move world-coordinate and eye-coordinate operations (e.g., vertex lighting) to object coordinates Collapse the M, V, and P matrixes to a single M MVP matrix Advantages: n Efficient implementation (less arithmetic) n Simplified semantics Costs: n Must transform lights to object coordinates n And how would the light positions be defined? n Incorrect answers …

20 CS248 Lecture 8Kurt Akeley, Fall 2007 Rigid-body transformations Change orientation and position, but not shape Preserve geometric lengths and (relative) angles Rigid-body transformations are: n Translation and Rotation n Not Scale and Shear (with occasional exceptions) A homogeneous matrix is a rigid-body matrix if its upper-left 3x3 matrix is orthogonal A matrix is orthogonal if and only if n All columns are orthogonal and unit-length, and n All rows are orthogonal and unit-length

21 CS248 Lecture 8Kurt Akeley, Fall 2007 Non-rigid transformations warp normals

22 CS248 Lecture 8Kurt Akeley, Fall 2007 Conceptual coordinate systems Vertex operations Transform v o by M Transform n o by M -1 Transform v w by V Transform v e by P Object coordinates World coordinates (lighting calculations) Eye coordinates Clip coordinates vovo vwvw veve vcvc nono nwnw Model transformation (non-rigid) View transformation (rigid) Projection transformation (non-rigid)

23 CS248 Lecture 8Kurt Akeley, Fall 2007 Collapsed coordinate systems (obvious) Vertex operations Transform v o by M Transform n o by M -1 Transform v w by M VE Object coordinates World coordinates (lighting calculations) Clip coordinates vovo vwvw vcvc nono nwnw Model transformation (non-rigid) View and projection transformation (non-rigid)

24 CS248 Lecture 8Kurt Akeley, Fall 2007 OpenGL coordinate systems (actual) Vertex operations Transform v o by M Transform n o by M -1 Transform v e by P Object coordinates Eye coordinates (lighting calculations) Clip coordinates vovo veve vcvc nono nene “Model-view” transformation (non-rigid) Projection transformation (non-rigid)

25 CS248 Lecture 8Kurt Akeley, Fall 2007 Why compute lighting in eye coordinates? Simplicity n Eliminates the need to explicitly specify viewer location Efficiency n In eye coordinates n View location is (0 0 0) n View direction is (0 0 -1) n These zeros and ones lead to efficient lighting calculations n But the optimizations are no longer important  You are free to treat the intermediate coordinates as world coordinates: Compose view transform V into P rather than M n There is little penalty for doing so: –Diffuse, ambient, and emission lighting work well –But specular lighting, which depends on viewer location, doesn’t n In X-Window terminology: “Mechanism, not policy” n Write your own vertex “shader” n OpenGL 2.0 allows you to redefine everything I’ll describe today

26 CS248 Lecture 8Kurt Akeley, Fall 2007 OpenGL matrix commands Transform v o by M Transform n o by M -1 Transform v e by P Object coordinates Eye coordinates (lighting calculations) Clip coordinates vovo veve vcvc nono nene “Model-view” transformation (non-rigid) Projection transformation (non-rigid) glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_PROJECTION);

27 CS248 Lecture 8Kurt Akeley, Fall 2007 OpenGL matrix assignment commands glLoadIdentity(); glLoadMatrixf(float m[16]); glLoadMatrixd(double m[16]); glLoadTransposeMatrixf(float m[16]); glLoadTransposeMatrixd(double m[16]); Remember to do this!

28 CS248 Lecture 8Kurt Akeley, Fall 2007 OpenGL matrix composition commands glMultMatrixf(float m[16]); glMultMatrixd(double m[16]); glMultTransposeMatrixf(float m[16]); glMultTransposeMatrixd(double m[16]);

29 CS248 Lecture 8Kurt Akeley, Fall 2007 OpenGL transformation commands glRotatef(float θ, float x, float y, float z); glRotated(double θ, double x, double y, double z); glTranslatef(float x, float y, float z); glTranslated(double x, double y, double z); glScalef(float x, float y, float z); glScaled(double x, double y, double z);

30 CS248 Lecture 8Kurt Akeley, Fall 2007 Why post-multiplication ? glTranslated(px, py, pz); glRotated(θ, a); glTranslated(-px, -py, -pz); DrawObject();

31 CS248 Lecture 8Kurt Akeley, Fall 2007 Duality glMultMatrixf(mat1); glMultMatrixf(mat2); glMultMatrixf(mat3); DrawObject(); Transform the coordinate system Transform the object

32 CS248 Lecture 8Kurt Akeley, Fall 2007 Rotation about a specified point glTranslated(2, 3, 0); glRotated(45, 0, 0, 1); glTranslated(-2, -3, 0); DrawObject(); Transform the coordinate system Transform the object

33 CS248 Lecture 8Kurt Akeley, Fall 2007 Transform the object Transformations are applied opposite the specified order Each transformation operates in the fixed coordinate system (2.5 3.5 0)

34 CS248 Lecture 8Kurt Akeley, Fall 2007 Transform the coordinate system Transformations are applied in the order specified Each transformation operates relative to the current coordinate system (2.5 3.5 0)

35 CS248 Lecture 8Kurt Akeley, Fall 2007 OpenGL matrix stack Separate stacks are maintained for M and P Minimum (queryable) depths are 32 for M and 2 for P glPushMatrix(); // pushes C onto the appropriate stack // leaves C unchanged glPopMatrix(); // restores C from top of stack and pops

36 CS248 Lecture 8Kurt Akeley, Fall 2007 Transforming the coordinate system glPushMatrix(); glRotatef(shoulder, 1, 0, 0); SolidBox(1.5*unit, 1.5*unit, 5*unit, RED); glTranslatef(0, 0, 5*unit); glPushMatrix(); glRotatef(elbow, 1, 0, 0); SolidBox(1.25*unit, 1.25*unit, 4*unit, WHITE); glTranslatef(0, 0, 4*unit); glPushMatrix(); glRotatef(wrist, 1, 0, 0); SolidBox(unit, unit, 1.5*unit, GREEN); glTranslatef(0, 0, 1.5*unit); glPushMatrix(); glTranslatef(0, 0.25*unit, 0); glRotatef(finger, 1, 0, 0); SolidBox(0.75*unit, 0.5*unit, 1.5*unit, YELLOW); glPopMatrix(); glPushMatrix(); glTranslatef(0, -0.25*unit, 0); glRotatef(thumb, 1, 0, 0); SolidBox(0.75*unit, 0.5*unit, 1.5*unit, YELLOW); glPopMatrix();

37 CS248 Lecture 8Kurt Akeley, Fall 2007 Details (x y z 0) specifies a 3-D direction n Division by zero pushes the point to infinity n Normals are a special kind of direction n Transformed by the inverse of the vertex matrix n Other directions are correctly transformed by the vertex matrix itself n E.g., surface tangents OpenGL provides no mechanism to pre-multiply C n Why?

38 CS248 Lecture 8Kurt Akeley, Fall 2007 Summary Our 2-D understanding translated easily to 3-D n Lines  planes n Rotation becomes more involved Normals are transformed by the upper-left 3x3 of M There is a duality to transformation n Transform the coordinate system n Transformations are applied in the specified order n Each transformation is relative to the current coordinate system n Transform the object n Transformations are applied opposite the specified order n Each transformation operates in the fixed coordinate system OpenGL matrixes are post-multiplied n Matches vertex semantics (interesting) n Enables hierarchical modeling (important)

39 CS248 Lecture 8Kurt Akeley, Fall 2007 Assignments Reading assignment for Thursday’s class n FvD chapter 6 n OpenGL chapter 3 Project 2: n Assigned this past Tuesday n Due next Tuesday, 23 October (midnight, almost Wednesday) n Help session this Friday from 4:15 to 5 pm, Gates B03

40 CS248 Lecture 8Kurt Akeley, Fall 2007 End


Download ppt "3-D Transformations Kurt Akeley CS248 Lecture 8 18 October 2007"

Similar presentations


Ads by Google