Presentation is loading. Please wait.

Presentation is loading. Please wait.

And an introduction to matrices COORDINATE SYSTEMS JEFF CHASTINE 1.

Similar presentations


Presentation on theme: "And an introduction to matrices COORDINATE SYSTEMS JEFF CHASTINE 1."— Presentation transcript:

1 and an introduction to matrices COORDINATE SYSTEMS JEFF CHASTINE 1

2 THE LOCAL COORDINATE SYSTEM JEFF CHASTINE 2 Sometimes called “Object Space” It’s the coordinate system the model was made in

3 THE LOCAL COORDINATE SYSTEM JEFF CHASTINE 3 Sometimes called “Object Space” It’s the coordinate system the model was made in (0, 0, 0)

4 THE WORLD SPACE JEFF CHASTINE 4 The coordinate system of the virtual environment (619, 10, 628)

5 JEFF CHASTINE 5 (619, 10, 628)

6 QUESTION JEFF CHASTINE 6 How did get the monster positioned correctly in the world? Let’s come back to that…

7 CAMERA SPACE JEFF CHASTINE 7 It’s all relative to the camera…

8 CAMERA SPACE JEFF CHASTINE 8 It’s all relative to the camera… and the camera never moves! (0, 0, -10)

9 THE BIG PICTURE JEFF CHASTINE 9 How to we get from space to space? ? ?

10 THE BIG PICTURE JEFF CHASTINE 10 How to we get from space to space? For every model Have a (M)odel matrix! Transforms from object to world space M ?

11 THE BIG PICTURE JEFF CHASTINE 11 How to we get from space to space? To put in camera space Have a (V)iew matrix Usually need only one of these M V

12 THE BIG PICTURE JEFF CHASTINE 12 How to we get from space to space? The ModelView matrix Sometimes these are combined into one matrix Usually keep them separate for convenience M V MV

13 MATRIX - WHAT? JEFF CHASTINE 13 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

14 BACK TO THE BIG PICTURE JEFF CHASTINE 14 If you multiply a matrix by a matrix, you get a matrix! How might we make the model matrix? M

15 BACK TO THE BIG PICTURE JEFF CHASTINE 15 If you multiply a matrix by a matrix, you get a matrix! How might we make the model matrix? M Translation matrix T Rotation matrix R 1 Rotation matrix R 2 Scale matrix S

16 BACK TO THE BIG PICTURE JEFF CHASTINE 16 If you multiply a matrix by a matrix, you get a matrix! How might we make the model matrix? M Translation matrix T Rotation matrix R 1 Rotation matrix R 2 Scale matrix S T * R 1 * R 2 * S = M

17 MATRIX ORDER JEFF CHASTINE 17 Multiply left to right Results are drastically different (an angry vertex)

18 MATRIX ORDER JEFF CHASTINE 18 Multiply left to right Results are drastically different Order of operations Rotate 45°

19 MATRIX ORDER JEFF CHASTINE 19 Multiply left to right Results are drastically different Order of operations Rotate 45° Translate 10 units

20 MATRIX ORDER JEFF CHASTINE 20 Multiply left to right Results are drastically different Order of operations Rotate 45° Translate 10 units before after

21 MATRIX ORDER JEFF CHASTINE 21 Multiply left to right Results are drastically different Order of operations

22 MATRIX ORDER JEFF CHASTINE 22 Multiply left to right Results are drastically different Order of operations Translate 10 units

23 MATRIX ORDER JEFF CHASTINE 23 Multiply left to right Results are drastically different Order of operations Translate 10 units Rotate 45°

24 MATRIX ORDER JEFF CHASTINE 24 Multiply left to right Results are drastically different Order of operations Translate 10 units Rotate 45° before after

25 BACK TO THE BIG PICTURE JEFF CHASTINE 25 If you multiply a matrix by a matrix, you get a matrix! How might we make the model matrix? M Translation matrix T Rotation matrix R 1 Rotation matrix R 2 Scale matrix S T * R 1 * R 2 * S = M Backwards

26 BACK TO THE BIG PICTURE JEFF CHASTINE 26 If you multiply a matrix by a matrix, you get a matrix! How might we make the model matrix? M Translation matrix T Rotation matrix R 1 Rotation matrix R 2 Scale matrix S S * R 1 * R 2 * T = M

27 THE (P)ROJECTION MATRIX JEFF CHASTINE 27 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)

28 ORTHOGRAPHIC VS. PERSPECTIVE JEFF CHASTINE 28

29 AN OLD VERTEX SHADER JEFF CHASTINE 29 in vec4 vPosition;// The vertex in NDC void main () { gl_Position = vPosition; } Originally we passed using NDCs (-1 to +1)

30 A BETTER VERTEX SHADER JEFF CHASTINE 30 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; } Original (local) positionNew position in NDC

31 SMILE – IT’S THE END! JEFF CHASTINE 31

32 HOW ABOUT MORE THAN ONE OBJECT? Hierarchical Transformations Composing transformations Coordinate systems/frames

33 33 COMPOSING TRANSFORMATIONS: ROTATION ABOUT A FIXED POINT 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?

34 ROTATE AROUND A FIXED POINT T -1

35 ROTATE AROUND A FIXED POINT R Ө

36 Ө

37 ROTATE AROUND A FIXED POINT T Ө

38 38 OPENGL/GLM EXAMPLE 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 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);...

39 TRANSFORMATION HIERARCHIES For example, a robot arm

40 Transformation Hierarchies Let’s examine:

41 Transformation Hierarchies What is a better way?

42 Transformation Hierarchies What is a better way?

43 Transformation Hierarchies We can have transformations be in relation to each other How do we do this in openGL and glm? World Coordinates Upper Arm Coordinates Lower Arm Coordinates Hand Coordinates Transformation: Upper Arm -> World Transformation: Lower -> Upper Transformation: Hand-> Lower

44 Transformation Hierarchies Activity: how you would have an object B orbiting object A, and object A is constantly translating. World Coordinates Upper Arm Coordinates Lower Arm Coordinates Hand Coordinates Transformation: Upper Arm -> World Transformation: Lower -> Upper Transformation: Hand-> Lower


Download ppt "And an introduction to matrices COORDINATE SYSTEMS JEFF CHASTINE 1."

Similar presentations


Ads by Google