16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function Calls or Protocol Data
26/5/ :47 UML Modeling in Three Dimensions Two Approaches 0 Constructive Solid Geometry (CSG) -Primitives are a small set of volumetric objects such as cube, pyramid, sphere, etc. -Objects built from normalized set operations on these objects 0 Boundary (surface) representation -Objects are described by their surfaces and can be thought of as being hollow -Surfaces composed (approximated) by simple, convex, planar polygons -Objects can be specified through a set of vertices in three dimensions =Implies underlying coordinate system =Duality: Object Object representation
36/5/ :47 UML Representation of a Cube Surface Representation Data Structure X 0, Y 0, Z 0 X 1, Y 1, Z 1 X 2, Y 2, Z 2 X 3, Y 3, Z 3 X 4, Y 4, Z 4 X 5, Y 5, Z 5 X 6, Y 6, Z 6 X 7, Y 7, Z A B C D E F FACES VERTEX LISTS VERTICES Object: set of points Representation: data structure
46/5/ :47 UML Inward and Outward Pointing Faces: Right Hand Rule Outside
56/5/ :47 UML Transformations 0 Maps an object into another object -In general, a transformation maps every point on an object to another point in the underlying coordinate space. 0 Why do we want/need transformations? -Change size, location, orientation of objects without changing underlying model (or primitive drawing commands) -Animation -Instancing Object New Object Representation New Representation Transformation Operation
66/5/ :47 UML P1’P1’ P2’P2’ What Do We Require of Transforms? Line Preserving P1P1 P2P2 Line Not Preserved
76/5/ :47 UML Abstract Data Types: Affine Space Scalar -Magnitude (e.g. real numbers) Vector u, v, w, x -Direction -Magnitude -No Position Point P, Q, R, X -Position -No Direction -No Magnitude
86/5/ :47 UML Defined Operations: Scalars Addition: -Additive identity: zero Additive inverse: - -Subtraction defined in terms of additive inverse Multiplication: -Multiplicative identity: 1 Multiplicative inverse: 1/ -Division defined in terms of multiplicative inverse
96/5/ :47 UML Defined Operations: Vectors Addition u v u + v | u | = Magnitude (produces scalar) Dot Product u v u v = | u | | v | cos (produces scalar) Cross Product u v Produces vector w orthogonal to u and v. w = u x v | w | = | u | | v | sin
106/5/ :47 UML Defined Operations: Scalars and Vectors Multiplication of vector by scalar: Produces vector u v = u | u | = | u |
116/5/ :47 UML Defined Operations: Points and Vectors Affine Addition: Point + Vector = Point P Q v Q = P + v Related to point subtraction.
126/5/ :47 UML Defined Operations: Points Subtraction (Addition of points has no meaning.) P R u = P - R Produces vector
136/5/ :47 UML Lines in Affine Space P Q v Q = P + v R R = P + v R’ Line segment from P to Q defined when: 0 1
146/5/ :47 UML Planes in Affine Space Planes are defined uniquely by three points: P, Q, R P Q R u v T( ) S( ) S( ) = P + v T( ) = P + u W( ) = S + (T - S) = P + v + u - v) W ( ) = P + 1 - v + u W = P + v + u W( ) u = Q - P v = R - P
156/5/ :47 UML Representations of Points and Vectors Coordinate system: z y x v P (x, y, z) where:
166/5/ :47 UML Homogeneous Coordinates Frame is specified by: Homogeneous coordinate representation: Frame where are linearly independent basis vectors and P 0 arbitrary point
176/5/ :47 UML Representation of Vectors In Homogeneous Coordinates
186/5/ :47 UML Affine Addition In Homogeneous Coordinate Representation Point Scalar times vector
196/5/ :47 UML Transform as a Change of Frame y x y x (2, 3) Want to translate by: x = 2 y=4 (2, 3) in x’y’ (4,7) in x y y’ x’ 1. Transform frame 2. Find representation in original frame x = 2 y=4
206/5/ :47 UML Transform as a Change of Frame Representation: Frame:
216/5/ :47 UML Transformation Matrix Original Frame:Transformed Frame: Express elements of transformed frame in original frame: where:
226/5/ :47 UML Transformation of Representation is representation in transformed frame is representation in original frame where is of the form:
236/5/ :47 UML Affine Transformations T(point) -> point T(vector) -> vector
246/5/ :47 UML P1’P1’ P2’P2’ What Do We Require of Transforms? Line Preserving P1P1 P2P2 Line Not Preserved
256/5/ :47 UML Affine Transformation: Line Preservation Matrix multiplication is linear. Therefore: p p+vp+v v T(p) T(p)+ T(v) T(v) Meets our requirements!
266/5/ :47 UML Translation Translate the new frame: Assumptions:
276/5/ :47 UML Scaling Scale the new frame:
286/5/ :47 UML Rotation Rotation around the z axis:
296/5/ :47 UML Rotation About x and y axes Similar derivations give:
306/5/ :47 UML Concatenation of Transformations Apply T 1, Then apply T 2 :
316/5/ :47 UML OpenGL Matrix Operations glLoadIdentity(); Loads an identity matrix onto the top of the current stack glLoadMatrixf(pointer_to_matrix); Loads arbitrary matrix onto top of the current stack glMultMatrixf(pointer_to_matrix); Postmultiplies current matrix by arbitrary matrix Matricies are one-dimensional arrays of type GLfloat in column major order.
326/5/ :47 UML Predefined Postmultiplier Operators in OpenGL glTranslatef(dx, dy, dz); Multiplies current matrix with translation matrix. dx, dy, and dz are translations along x,y, and z axes. glRotatef(angle, x, y, z); Multiplies current matrix with rotation about the line from the origin through the point (x, y, z) by angle. Right hand rule applies. Angle in degrees. glScalef(sx, sy, sz); Multiplies current matrix with scaling matrix. sx, sy, sz are the scale factors along the x, y, and z axes.
336/5/ :47 UML Transformation Matrices in OpenGL Stack Current Stack CurrentLoad Matrix Vertices 3D Model Vertices 3D 2D ModelviewProjection Matrix Mode