440 likes | 462 Views
Dive into coordinate systems and matrices introduction by Jeff Chastine. Learn about the local coordinate system, world space, camera space, and matrix operations in graphics. Explore the concepts of translation, rotation, scaling, and projection matrices.
E N D
Coordinate Systems and an introduction to matrices Jeff Chastine
The Local Coordinate System • Sometimes called “Object Space” • It’s the coordinate system the model was made in Jeff Chastine
The Local Coordinate System • Sometimes called “Object Space” • It’s the coordinate system the model was made in (0, 0, 0) Jeff Chastine
The World SPACE • The coordinate system of the virtual environment (619, 10, 628) Jeff Chastine
(619, 10, 628) Jeff Chastine
Question • How did get the monster positioned correctly in the world? • Let’s come back to that… Jeff Chastine
Camera Space • It’s all relative to the camera… Jeff Chastine
Camera Space • It’s all relative to the camera… and the camera never moves! (0, 0, -10) Jeff Chastine
The Big Picture • How to we get from space to space? ? ? Jeff Chastine
The Big Picture • How to we get from space to space? • For every model • Have a (M)odel matrix! • Transforms from object to world space ? M Jeff Chastine
The Big Picture • How to we get from space to space? • To put in camera space • Have a (V)iew matrix • Usually need only one of these V M Jeff Chastine
The Big Picture • How to we get from space to space? • The ModelView matrix • Sometimes these are combined into one matrix • Usually keep them separate for convenience V M MV Jeff Chastine
Matrix - What? • A mathematical structure that can: • Translate (a.k.a. move) • Rotate • Scale • Usually a 4x4 array of values • Idea: multiply each point by a matrix to get the new point • Your graphics card eats matrices for breakfast The Identity Matrix Jeff Chastine
Back to The Big Picture • If you multiply a matrix by a matrix, you get a matrix! • How might we make the model matrix? M Jeff Chastine
Back to The Big Picture Translation matrix T Rotation matrix R1 Rotation matrix R2 Scale matrix S • If you multiply a matrix by a matrix, you get a matrix! • How might we make the model matrix? M Jeff Chastine
Back to The Big Picture Translation matrix T Rotation matrix R1 Rotation matrix R2 Scale matrix S • If you multiply a matrix by a matrix, you get a matrix! • How might we make the model matrix? M T * R1 * R2 * S = M Jeff Chastine
Matrix Order • Multiply left to right • Results are drastically different (an angry vertex) Jeff Chastine
Matrix Order • Multiply left to right • Results are drastically different • Order of operations • Rotate 45° Jeff Chastine
Matrix Order • Multiply left to right • Results are drastically different • Order of operations • Rotate 45° • Translate 10 units Jeff Chastine
Matrix Order • Multiply left to right • Results are drastically different • Order of operations • Rotate 45° • Translate 10 units before after Jeff Chastine
Matrix Order • Multiply left to right • Results are drastically different • Order of operations Jeff Chastine
Matrix Order • Multiply left to right • Results are drastically different • Order of operations • Translate 10 units Jeff Chastine
Matrix Order • Multiply left to right • Results are drastically different • Order of operations • Translate 10 units • Rotate 45° Jeff Chastine
Matrix Order • Multiply left to right • Results are drastically different • Order of operations • Translate 10 units • Rotate 45° after before Jeff Chastine
Back to The Big Picture Translation matrix T Rotation matrix R1 Rotation matrix R2 Scale matrix S • If you multiply a matrix by a matrix, you get a matrix! • How might we make the model matrix? M T * R1 * R2 * S = M Backwards Jeff Chastine
Back to The Big Picture Translation matrix T Rotation matrix R1 Rotation matrix R2 Scale matrix S • If you multiply a matrix by a matrix, you get a matrix! • How might we make the model matrix? M S * R1 * R2 * T = M Jeff Chastine
The (P)rojection Matrix • Projects from 3D into 2D • Two kinds: • Orthographic: depth doesn’t matter, parallel remains parallel • Perspective: Used to give depth to the scene (a vanishing point) • End result: Normalized Device Coordinates (NDCs between -1.0 and +1.0) Jeff Chastine
Orthographic vs. Perspective Jeff Chastine
An Old Vertex Shader in vec4 vPosition; // The vertex in NDC void main () { gl_Position = vPosition; } Originally we passed using NDCs (-1 to +1) Jeff Chastine
A Better Vertex Shader in vec4 vPosition; // The vertex in the local coordinate system uniform mat4 mM; // The matrix for the pose of the model uniform mat4 mV; // The matrix for the pose of the camera uniform mat4 mP; // The projection matrix (perspective) void main () { gl_Position = mP*mV*mM*vPosition; } New position in NDC Original (local) position Jeff Chastine
SMILE – It’s the END! Jeff Chastine
How about more than one object? • Hierarchical Transformations • Composing transformations • Coordinate systems/frames
Basic idea: 1) Move fixed point to origin 2) Rotate 3) Move the fixed point back Remember, postmultiplication applies transforms in reverse Result: M = T RT –1 What does this look like graphically? Composing Transformations: Rotation about a Fixed Point
Rotation about z axis by 30 degrees with a fixed point of (1.0, 2.0, 3.0) Remember that last transform specified in the program is the first applied OpenGL/glm Example model *= glm::translate(1.0, 2.0, 3.0)* glm::rotate(30.0, 0.0, 0.0, 1.0)* glm::translate(-1.0, -2.0, -3.0); cube.render(view*model, &shader); ...
For example, a robot arm Transformation Hierarchies
Transformation Hierarchies • Let’s examine:
Transformation Hierarchies • What is a better way?
Transformation Hierarchies • What is a better way?
World Coordinates Transformation Hierarchies Transformation: Upper Arm -> World • We can have transformations be in relation to each other • How do we do this in openGL and glm? Upper Arm Coordinates Transformation: Lower -> Upper Lower Arm Coordinates Transformation: Hand-> Lower Hand Coordinates
World Coordinates Transformation Hierarchies Transformation: Upper Arm -> World • Activity: how you would have an object B orbiting object A, and object A is constantly translating. Upper Arm Coordinates Transformation: Lower -> Upper Lower Arm Coordinates Transformation: Hand-> Lower Hand Coordinates