#3: Hierarchical Transforms. Geometric Calculations CSE167: Computer Graphics Instructor: Ronen Barzel UCSD, Winter 2006.

Slides:



Advertisements
Similar presentations
Homogeneous Transformations CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.
Advertisements

This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
Computer Graphics Lecture 4 Geometry & Transformations.
Translation and Rotation in 2D and 3D David Meredith Aalborg University.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
CMPE 466 COMPUTER GRAPHICS
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections I.
Transformations II Week 2, Wed Jan 17
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Transformations II Week.
2D Geometric Transformations
Transformations IV Week 3, Wed Jan 23
#4: OpenGL Implementation & Project 2 CSE167: Computer Graphics TAs: Alex Kozlowski & Cameron Chrisman UCSD, Winter 2006.
Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs.
Outline for Today More math… Finish linear algebra: Matrix composition
3-D Geometry.
Now Playing: Gong Sigur Rós From Takk... Released September 13, 2005.
Computer Graphics (Fall 2008) COMS 4160, Lecture 3: Transformations 1
OpenGL (II). How to Draw a 3-D object on Screen?
Computer Graphics (Fall 2004) COMS 4160, Lecture 3: Transformations 1
Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
2IV60 Computer Graphics 2D transformations
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
CS 450: Computer Graphics 2D TRANSFORMATIONS
Hierarchical Transformations Hierarchical Models Scene Graphs
CS 450: COMPUTER GRAPHICS 3D TRANSFORMATIONS SPRING 2015 DR. MICHAEL J. REALE.
Mathematical Fundamentals
COMP 175: Computer Graphics March 10, 2015
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.
COMP 175: Computer Graphics March 24, 2015
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformations Dr. Amy Zhang.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Geometric Transformations Jehee Lee Seoul National University.
Lecture 3 Transformations.
Geometric transformations The Pipeline
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Geometric Transformations
Geometric Camera Models
10/3/02 (c) 2002 University of Wisconsin, CS 559 Last Time 2D Coordinate systems and transformations.
Transformations Tutorial
1/50 CS148: Introduction to Computer Graphics and Imaging Transforms CS148: Introduction to Computer Graphics and Imaging Transforms.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
Lecture 3 Transformations. 2D Object Transformations The functions used for modifying the size, location, and orientation of objects or of the camera.
12/24/2015 A.Aruna/Assistant professor/IT/SNSCE 1.
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Hierarchical Modeling.
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 3: Transformations 1
Computer Graphics Matrices
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
1 Geometric Transformations Modelling Transforms By Dr.Ureerat Suksawatchon.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
OpenGL LAB III.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections I.
The Modelview Stack Lecture 9 Wed, Sep 12, The Modelview Stack OpenGL maintains a stack of matrices. The matrix on top of the stack is the current.
Transformations V, Viewing I Week 3, Fri Jan 22
A circular dial with the digits 0 through 9 evenly spaced around its edge can be rotated clockwise 36°. How many times would you have to perform this.
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Geometric Objects and Transformations (II)
Viewing/Projections I Week 3, Fri Jan 25
Transformations IV Week 3, Wed Jan 23
Hierarchical Modeling
Presentation transcript:

#3: Hierarchical Transforms. Geometric Calculations CSE167: Computer Graphics Instructor: Ronen Barzel UCSD, Winter 2006

1 Outline for Today: Hierarchical Transforms Geometric Calculations

2 Object and World Coordinates In project1, constructed matrix to transform points of cube Cube defined using (-1,1,1), … Transformed each point to final position

3 Object Coordinates Each object is defined using some convenient coordinates Often “Axis-aligned”. (when there are natural axes for the object) Origin of coordinates is often in the middle of the object Origin of coordinates is often at the “base” or corner of the object E.g. cube in project1 was -1,-1,1… could also use just 0,1 Axes could be lined up any way. Model of a book: put the Z axis along the spine? Front-to-back? No “right” answer. Just what’s most convenient for whomever builds model Notice: build, manipulate object in object coordinates Don’t know (or care) where the object will end up in the scene. Also called Object space Local coordinates

4 World Coordinates The common coordinate system for the scene Also called World Space Also chosen for convenience, no “right” answer. Typically if there’s a ground plane, it’s XY horizontal and Z up That’s most common for people thinking of models I tend to use it a lot Aside: Screen Coordinates X to the right, Y up, Z towards you That’s the convention when considering the screen (rendering) Handy when drawing on the blackboard, slides In project1, World Coordinates == Screen Coordinates

5 Placing object in the world Bundle together a single composite transform. Known as: Model Matrix Model Transform World Matrix World Transform Model-to-World Transform Local-to-World Matrix In OpenGL: included in MODELVIEW matrix (composed model & view matrix) Transforms each point

6 Placing object coordinates in the world Place the coordinate frame for the object in the world Don’t know or care about the shape of the object World matrix columns = object’s frame in world coordinates

7 Relative Transformations Until now, used a separate world matrix to place each object into the world separately. But usually, objects are organized or grouped together in some way For example… A bunch of moons and planets orbiting around in a solar system Several objects sitting on a tray that is being carried around A hotel with 1000 rooms, each room containing a bed, chairs, table, etc. A robot with torso and jointed arms & legs Placement of objects is described more easily relative to each other rather than always in world space

8 Sample Scene

9 Schematic Diagram (Top View)

10 Top view with Coordinates

11 Relative Transformations Put the objects on the tables Each table has a simple coordinate system E.g. Book1 at (3.75,1,0) on Table1’s top E.g. Keyboard at (3,.5,0) on Table2’s top Don’t care where the tables are in order to do this part Put the tables in the room Books etc. should end up in the right place How do we do this…?

12 Current coordinate system In our code, we maintain a “current coordinate system” Everything we draw will be in those coordinates I.e. we keep a variable with a matrix known as the “current transformation matrix” (CTM) Everything we draw we will transform using that matrix Transforms from current coordinates to world coordinates

13 Drawing with a CTM Old drawCube: drawCube(Matrix M) { p1 = M*Point3( 1,-1, 1); p2 = M*Point3( 1,-1,-1); p3 = M*Point3( 1, 1,-1); p4 = M*Point3( 1, 1, 1); p5 = M*Point3(-1,-1, 1); p6 = M*Point3(-1,-1,-1); p7 = M*Point3(-1, 1,-1); p8 = M*Point3(-1, 1, 1);... } New drawCube: // global CTM drawCube() { p1 = CTM*Point3( 1,-1, 1); p2 = CTM*Point3( 1,-1,-1); p3 = CTM*Point3( 1, 1,-1); p4 = CTM*Point3( 1, 1, 1); p5 = CTM*Point3(-1,-1, 1); p6 = CTM*Point3(-1,-1,-1); p7 = CTM*Point3(-1, 1,-1); p8 = CTM*Point3(-1, 1, 1);... }

14 Using a CTM As we go through the program, we incrementally update the CTM Start with the current coordinates=world coordinates CTM = I Before we draw an object, we update the CTM from the current location to the object’s location We perform a relative transformation. The CTM accumulates the full current-to-world transformation. Draw from the outside in. Draw containers before the things they contain.

15 Top view, just frames

16 Table1 and Book1

17 Draw Table1 and Book1 // Start in World coords, on floor of room CTM = Matrix::IDENTITY; // Move to Table1 position, draw table CTM = CTM*Matrix.MakeTranslate(2,8,0); drawTable(); // Move up to tabletop height CTM = CTM*Matrix.MakeTranslate(0,0,3); // Move to Book1 position & orientation, draw CTM = CTM*Matrix.MakeTranslate(3.75,1,0); CTM = CTM*Matrix.MakeRotateZ(90); drawBook();

18 Simplify the idiom Routines that affect the CTM: LoadIdentity () { CTM = Matrix::IDENTITY } Translate(V) { CTM = CTM*Matrix::MakeTranslate(V) } RotateZ(angle) { CTM = CTM*Matrix::MakeRotateZ(angle) } Etc… Transform(M) { CTM = CTM*M }

19 Draw Table1 and Book, redux // Start in World coords, on floor of room LoadIdentity(); // Move to Table1 position, draw table Translate(2,8,0); drawTable(); // Move up to tabletop height Translate(0,0,3); // Move to Book1 position & orientation, draw Translate(3.75,1,0); RotateZ(90); drawBook();

20 Table2 and Keyboard

21 Draw Table2 and Keyboard // Start in World coords, on floor of room LoadIdentity(); // Move to Table2 position & orientation, draw Translate(2,8,0); RotateZ(-81); drawTable(); // Move up to tabletop height Translate(0,0,3); // Move to Keyboard position, draw Translate(3,0.5,0); drawKeyboard();

22 What about drawing entire scene? After we drew Book1 or Keyboard, our coordinate system had moved deep into the world somewhere. How do we get back…? To the tabletop coordinates so we can place another book? To the room coordinates so we can place another table? Don’t want to start over at the beginning for each object. At each stage, need to remember where we are so we can get back there

23 Keep a Stack for the CTM Add two more routines: PushCTM() -- saves a copy of the CTM on the stack PopCTM() -- restores the CTM from the stack

24 Draw whole scene, hierarchically PushCTM(); Translate(2,8,0); drawTable() Translate(0,0,3); PushCTM(); Translate(3.75,1,0); RotateZ(90); drawBook() PopCTM(); PushCTM(); Translate(…); Rotate(…); drawBook(); PopCTM(); …etc… PopCTM() …etc…

25 Hierachical grouping within a model Model can be composed of parts Draw parts using Push & Pop CTM drawTable(){ PushCTM() // save PushCTM() // draw leg1 Translate(…); drawLeg(); PopCTM(); PushCTM() // draw leg2 Translate(…); drawLeg(); PopCTM(); …etc leg3 & leg4… PushCTM(); // draw top Translate(…); drawTableTop(); PopCTM(); PopCTM() // restore } Has no effect outside this routine.

26 Access something in the middle? CTM always contains the complete Local-to-world transform for what we’re currently drawing. Sometimes need to hold on to copy of CTM in the middle pushCTM(); …stuff… pushCTM(); …transform… Book1Matrix = CTM; drawBook(); popCTM(); …stuff… popCTM(); Later in code, mosquito lands on Book1 pushCTM(); LoadMatrix(Book1Matrix); Translate(…); drawMosquito(); popCTM();

27 CTM and matrix stack in OpenGL OpenGL provides glTranslatef(…) glRotatef(…) glPushMatrix() glPopMatrix() (But don’t use them for proj2--need to know how to do it yourself) Actually, other properties, such as color, are also part of “current state” and can be pushed and popped.

28 Thinking top-down vs bottom-up Transforms for World-to-Keyboard (ignoring pushes, pops, etc.): 1. Translate(2,8,0) 2. RotateZ(-81) 3. Translate(0,0,3) 4. Translate(3,0.5,0) 5. drawKeyboard() Top-down: transform the coordinate frame: Translate the frame, then rotate it, then translate twice more, then draw the object Bottom-up: transform the object: Create a keyboard, translate it in X&Y, then in Z, then rotate about the origin, then translate again Both ways give same result Both ways useful for thinking about it.

29 Another example: Sample sequence: 1. RotateZ(45) 2. Translate(0,5,0) 3. Scale(2,1,1) 4. drawCube() Top-down: transform a coordinate frame: rotate it 45 degrees about its origin, then translate it along its Y, then stretch it in X, then draw the primitive. Bottom-up: transform the object create a square, then scale it in X then translate it along the Y axis, then rotate 45 degrees about the origin. Both ways useful

30 Outline for Today: Hierarchical Transforms Geometric Calculations

31 a b c Example: Normal of a Triangle The concept of a “normal” will be essential to lighting Find the unit length normal of the triangle defined by 3D points a,b,c

32 a b c Example: Normal of a Triangle Find the unit length normal of the triangle defined by 3D points a, b, and c

33 p t Example: Alignment to Target An object is at position p with a unit length heading of. We want to rotate it so that the heading is facing some target at position t. Find a unit axis a and an angle θ to rotate around.

34 p t θ Example: Alignment to Target

35 p x Example: Distance to Plane A plane is described by a point p on the plane and a unit normal. Find the (perpendicular) distance from point x to the plane

36 p x Example: Distance to Plane The distance is the length of the projection of onto :

37 a b c Example: Area of a Triangle Find the area of the triangle defined by 3D points a, b, and c

38 a b c Example: Area of a Triangle

39 Scaling and volume Scale Matrix: Scaling an object changes its volume by s x *s y *s z A uniform scale s changes volume by s 3 E.g. scaling uniformly by 2 increases volume by 8 A non-uniform scale with 0 (projection into a plane) flattens object New volume is 0

40 Volume Preserving Scale Stretch one axis while squashing the other two E.g., a volume preserving scale along the x-axis by a factor of s x would scale the y and z axes by 1/sqrt(s x ) This way, the total volume change is

41 Transforming normals A “normal vector” perpendicular to object Not really a vector (a “co-vector”/linear functional/covariant tensor) Represents relationship to other vectors After a transform M, want it to still be normal. No problem if transform is rigid, or has uniform scale But if M has non-uniform scale, angle won’t stay right:

42 Transforming normals Answer: transform using inverse of transpose of M For rotations, inverse=transpose, so inverse of transpose is inverse of inverse, I.e. M unchanged. Only makes a difference if M has non-uniform scale (or shear)

43 A shear transformation matrix looks something like this: With pure shears, only one of the constants is non-zero A shear is equivalent to a non-uniform scale along a rotated set of axes Shears are sometimes used in computer graphics for simple deformations or cartoon-like effects Shear Transformations

44 Next class I’ll be away Class will be held by TA’s will go over project code, OpenGL, review transforms, etc… Discussion… bring your questions! Next Tuesday: Models Hierarchical Modeling / Scene Graphs