#3: Hierarchical Transforms. Geometric CalculationsOutline for Today:Object and World CoordinatesObject CoordinatesWorld CoordinatesPlacing object in the worldPlacing object coordinates in the worldRelative TransformationsSample SceneSchematic Diagram (Top View)Top view with CoordinatesSlide 12Current coordinate systemDrawing with a CTMUsing a CTMTop view, just framesTable1 and Book1Draw Table1 and Book1Simplify the idiomDraw Table1 and Book, reduxTable2 and KeyboardDraw Table2 and KeyboardWhat about drawing entire scene?Keep a Stack for the CTMDraw whole scene, hierarchicallyHierachical grouping within a modelAccess something in the middle?CTM and matrix stack in OpenGLThinking top-down vs bottom-upAnother example:Slide 31Example: Normal of a TriangleSlide 33Example: Alignment to TargetSlide 35Example: Distance to PlaneSlide 37Example: Area of a TriangleSlide 39Scaling and volumeVolume Preserving ScaleTransforming normalsSlide 43Shear TransformationsNext class#3: Hierarchical Transforms. Geometric CalculationsCSE167: Computer GraphicsInstructor: Ronen BarzelUCSD, Winter 20062Outline for Today:Hierarchical TransformsGeometric Calculations3Object and World CoordinatesIn project1, constructed matrix to transform points of cubeCube defined using (-1,1,1), …Transformed each point to final positionQuickTime™ and aTIFF (LZW) decompressorare needed to see this picture.4Object CoordinatesEach object is defined using some convenient coordinatesOften “Axis-aligned”. (when there are natural axes for the object)Origin of coordinates is often in the middle of the objectOrigin of coordinates is often at the “base” or corner of the objectE.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 modelNotice: build, manipulate object in object coordinatesDon’t know (or care) where the object will end up in the scene.Also calledObject spaceLocal coordinates5World CoordinatesThe common coordinate system for the sceneAlso 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 lotAside: Screen CoordinatesX 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 Coordinates6Placing object in the worldBundle together a single composite transform.Known as:Model MatrixModel TransformWorld MatrixWorld TransformModel-to-World TransformLocal-to-World MatrixIn OpenGL: included in MODELVIEW matrix (composed model & view matrix)Transforms each point7QuickTime™ and aTIFF (LZW) decompressorare needed to see this picture.Placing object coordinates in the worldPlace the coordinate frame for the object in the worldDon’t know or care about the shape of the objectWorld matrix columns = object’s frame in world coordinates8Relative TransformationsUntil now, used a separate world matrix to place each object into the world separately.But usually, objects are organized or grouped together in some wayFor example…A bunch of moons and planets orbiting around in a solar systemSeveral objects sitting on a tray that is being carried aroundA hotel with 1000 rooms, each room containing a bed, chairs, table, etc.A robot with torso and jointed arms & legsPlacement of objects is described more easily relative to each other rather than always in world space9Sample Scene10Schematic Diagram (Top View)QuickTime™ and aTIFF (LZW) decompressorare needed to see this picture.11Top view with CoordinatesQuickTime™ and aTIFF (LZW) decompressorare needed to see this picture.12Relative TransformationsPut the objects on the tablesEach table has a simple coordinate systemE.g. Book1 at (3.75,1,0) on Table1’s topE.g. Keyboard at (3,.5,0) on Table2’s topDon’t care where the tables are in order to do this partPut the tables in the roomBooks etc. should end up in the right placeHow do we do this…?13Current coordinate systemIn our code, we maintain a “current coordinate system”Everything we draw will be in those coordinatesI.e. we keep a variable with a matrix known as the “current transformation matrix” (CTM)Everything we draw we will transform using that matrixTransforms from current coordinates to world coordinates14Drawing with a CTMOld 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 CTMdrawCube() {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); . . .}15Using a CTMAs we go through the program, we incrementally update the CTMStart with the current coordinates=world coordinatesCTM = IBefore we draw an object, we update the CTMfrom the current location to the object’s locationWe 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.16Top view, just framesQuickTime™ and aTIFF (LZW) decompressorare needed to see this picture.17Table1 and Book1QuickTime™ and aTIFF (LZW) decompressorare needed to see this picture.18Draw Table1 and Book1 // Start in World coords, on floor of roomCTM = Matrix::IDENTITY;// Move to Table1 position, draw tableCTM = CTM*Matrix.MakeTranslate(2,8,0);drawTable();// Move up to tabletop heightCTM = 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();19Simplify the idiomRoutines 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 }20Draw Table1 and Book, redux // Start in
View Full Document