IMGD - The Game Development Process: 3D Modeling and Transformations b Robert W. Lindeman (gogo@wpi.edu Kent Quirk (kent_quirk@cognito.com (with lots of input from Mark Clapool! Overview of 3D Modeling Modeling Create 3D model of scene/objects Coordinate sstems (left hand, right hand Basic shapes (cone, clinder, etc. Transformations/Matrices Lighting/Materials Snthetic camera basics View volume Projection Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 2
Coordinate Sstems Right-handed and left-handed coordinate sstems Make an "L" with inde finger and thumb No real "standard," but... Converting from one to the other is a simple transformation +Y +X +Y +Z +X +Z Right-Handed Coordinate Sstem Left-Handed Coordinate Sstem Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 3 Right-Handed Coordinates To determine positive rotations Make a fist with our right hand, and stick thumb up in the air (CCW +Y +Z +X Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 4 2
Hierarchical Transformations Graphical scenes have object dependencies Man small objects Attributes (position, orientation, etc. depend on each other hammer A Robot Hammer! lower arm base Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 5 Hierarchical Transformations (cont. Object dependenc description using tree structure Base Lower arm Upper arm Hammer Root node Leaf node Object position and orientation can be affected b its parent, grand-parent, grand-grand-parent, nodes Hierarchical representation is known as Scene Graph Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 6 3
Transformations Two was to specif transformations. Absolute transformation: each part of the object is transformed independentl relative to the origin Translate the base b (5,, ; Translate the lower arm b (5, 2, ; Translate the upper arm b (5, 4, ; Translate the hammer head b (5, 4, 4 Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 7 Relative Transformations A better (and easier wa. Relative transformation: Specif the transformation for each object relative to its parent Step : Translate the base (and its descendants b (5,, ; Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 8 4
Relative Transformations (cont. Step 2: Rotate the lower arm and (its descendants relative to the bases local ais b -9 degrees Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 9 Relative Transformations Using a Scene Graph Base Translate (5,, Lower arm Rotate (-9 about its local Upper arm Hammer Appl all the wa down Appl all the wa down Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 5
Introduction to Transformations A transformation changes an objects Sie (scaling Position (translation Orientation (rotation We will introduce first in 2D or (,, build intuition Later, talk about 3D and 4D? Transform object b appling sequence of matri multiplications to object vertices Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science Wh Matrices? All transformations can be performed using matri/vector multiplication Allows pre-multiplication of all matrices Note: point (, needs to be represented as (,,, also called homogeneous coordinates Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 2 6
Point Representation We use a column matri (2 matri to represent a 2D point General form of transformation of a point (, to (, can be written as: a + b + c d + e + f or a b c d e f * Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 3 Translation To reposition a point along a straight line Given point (, and translation distance (t, t The new point: (, (, + t + t (, or P P + T where P P t T t Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 4 7
8 Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 5 33 2D Translation Matri t t + use 3 vector t t * Note: it becomes a matri-vector multiplication + t + t Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 6 Translation of Objects How to translate an object with multiple vertices? Translate individual vertices
9 Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 7 2D Scaling Scale: Alter object sie b scaling factor (s, s. i.e., * S * S (, (2,2 S 2, S 2 (2,2 (4,4 S S Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 8 33 2D Scaling Matri S S S S * S * S
2D Rotation Default rotation center is origin (, > : Rotate counter clockwise < : Rotate clockwise Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 9 2D Rotation (cont. (, -> Rotate about the origin b (, (, r (, How to compute (,? r* r*sin( r* + r*sin( + Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 2
Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 2 2D Rotation (cont. Using trig. identities (, (, r sin( sin( + Matri form? sin( sin( sin sin cos cos + sin cos cos sin sin( + + Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 22 33 2D Rotation Matri (, (, r sin( sin( sin( sin(
2D Rotation How to rotate an object with multiple vertices? Rotate individual Vertices Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 23 Arbitrar Rotation Center To rotate about arbitrar point P (P, P b : Translate object b T(-P, -P so that P coincides with origin Rotate the object b R( Translate object back: T(P, P In matri form T(P,P R( T(-P,-P * P P sin( P sin( Similar for arbitrar scaling anchor P P Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 24 2
Composing Transformations Composing transformations Appling several transforms in succession to form one overall transformation Eample M X M2 X M3 X P where M, M2, M3 are transform matrices applied to P Be careful with the order! For eample Translate b (5,, then rotate 6 degrees is NOT same as Rotate b 6 degrees, then translate b (5, Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 25 3D Transformations Affine transformations Mappings of points to new points that retain certain relationships Lines remain lines Several transformations can be combined into a single matri Two was to think about transformations Object transformations All points of an object are transformed Coordinate transformations The coordinate sstem is transformed, and models remain defined relative to this Lindeman & Quirk (& Clapool - WPI Dept. of Computer Science 26 3