1 / 40

3-D Transformations

3-D Transformations. Kurt Akeley CS248 Lecture 8 18 October 2007 http://graphics.stanford.edu/courses/cs248-07/. Overview. Tuesday 2-D transformation Composition of 2-D transformations Line equations, 2-D normals, and inverses Today Apply 2-D concepts to 3-D

lou
Download Presentation

3-D Transformations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Overview Tuesday • 2-D transformation • Composition of 2-D transformations • Line equations, 2-D normals, and inverses Today • Apply 2-D concepts to 3-D • Look at OpenGL in some detail

  3. Homogeneous 3-D coordinates

  4. Specify rotation, scale, and shear Specify translation (Almost) always have these values Homogeneous 3-D transformation

  5. Homogeneous translation and scale Translation: Scaling (about the origin):

  6. Homogeneous rotation (about a coordinate axis) y x z Right-hand rule for rotations by positive θ

  7. Homogeneous rotation (ccw about axis a)

  8. Composition of transformations

  9. The plane equation

  10. Transforming the plane equation Plane equations are transformed by the inverse of the matrix used to transform vertexes

  11. The normal to the plane n

  12. Derivation

  13. Transformation of normals (correct) Convert to plane equation, transform, and convert back:

  14. Transformation of normals (approximation)

  15. Elemental inverse transforms are simple

  16. Transformation in OpenGL

  17. The vertex pipeline Application struct { float x,y,z,w;float nx,ny,nz; float r,g,b,a;} vertex; Vertex assembly Vertex operations Primitive assembly Primitive operations Rasterization Fragment operations Framebuffer Display

  18. Conceptual coordinate systems no vo Object coordinates Transform vo by MTransform no by M-1 Model transformation World coordinates(lighting calculations) nw vw Transform vw by V Vertex operations View transformation ve Eye coordinates Transform ve by P Projection transformation vc Clip coordinates

  19. 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 MMVP matrix Advantages: • Efficient implementation (less arithmetic) • Simplified semantics Costs: • Must transform lights to object coordinates • And how would the light positions be defined? • Incorrect answers …

  20. Rigid-body transformations Change orientation and position, but not shape Preserve geometric lengths and (relative) angles Rigid-body transformations are: • Translation and Rotation • 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 • All columns are orthogonal and unit-length, and • All rows are orthogonal and unit-length

  21. Non-rigid transformations warp normals

  22. Conceptual coordinate systems no vo Object coordinates Transform vo by MTransform no by M-1 Model transformation(non-rigid) World coordinates(lighting calculations) nw vw Transform vw by V View transformation(rigid) Vertex operations ve Eye coordinates Transform ve by P Projection transformation(non-rigid) vc Clip coordinates

  23. Collapsed coordinate systems (obvious) no vo Object coordinates Transform vo by MTransform no by M-1 Model transformation(non-rigid) World coordinates(lighting calculations) nw vw Vertex operations View and projection transformation(non-rigid) Transform vw by MVE vc Clip coordinates

  24. OpenGL coordinate systems (actual) no vo Object coordinates “Model-view” transformation(non-rigid) Transform vo by MTransform no by M-1 Eye coordinates(lighting calculations) ne ve Vertex operations Transform ve by P Projection transformation(non-rigid) vc Clip coordinates

  25. Why compute lighting in eye coordinates? Simplicity • Eliminates the need to explicitly specify viewer location Efficiency • In eye coordinates • View location is (0 0 0) • View direction is (0 0 -1) • These zeros and ones lead to efficient lighting calculations • 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 • There is little penalty for doing so: • Diffuse, ambient, and emission lighting work well • But specular lighting, which depends on viewer location, doesn’t • In X-Window terminology: “Mechanism, not policy” • Write your own vertex “shader” • OpenGL 2.0 allows you to redefine everything I’ll describe today

  26. OpenGL matrix commands no vo Object coordinates glMatrixMode(GL_MODELVIEW); “Model-view” transformation(non-rigid) Transform vo by MTransform no by M-1 Eye coordinates(lighting calculations) ne ve glMatrixMode(GL_PROJECTION); Transform ve by P Projection transformation(non-rigid) vc Clip coordinates

  27. OpenGL matrix assignment commands glLoadIdentity(); Remember to do this! glLoadMatrixf(float m[16]); glLoadMatrixd(double m[16]); glLoadTransposeMatrixf(float m[16]); glLoadTransposeMatrixd(double m[16]);

  28. OpenGL matrix composition commands glMultMatrixf(float m[16]); glMultMatrixd(double m[16]); glMultTransposeMatrixf(float m[16]); glMultTransposeMatrixd(double m[16]);

  29. 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. Why post-multiplication ? glTranslated(px, py, pz); glRotated(θ, a); glTranslated(-px, -py, -pz); DrawObject();

  31. Duality Transform the coordinate system Transform the object glMultMatrixf(mat1); glMultMatrixf(mat2); glMultMatrixf(mat3); DrawObject();

  32. Rotation about a specified point Transform the coordinate system Transform the object glTranslated(2, 3, 0); glRotated(45, 0, 0, 1); glTranslated(-2, -3, 0); DrawObject();

  33. Transform the object Transformations are applied opposite the specified order Each transformation operates in the fixed coordinate system (2.5 3.5 0)

  34. 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. 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. 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(); glPopMatrix(); glPopMatrix(); glPopMatrix();

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

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

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

  40. End

More Related