CoordinateSystems.pptx

advertisement
COORDINATE SYSTEMS
and an introduction to matrices
JEFF CHASTINE
1
THE LOCAL COORDINATE SYSTEM
•
Sometimes called “Object Space”
•
It’s the coordinate system the model was made in
JEFF CHASTINE
2
THE LOCAL COORDINATE SYSTEM
•
Sometimes called “Object Space”
•
It’s the coordinate system the model was made in
(0, 0, 0)
JEFF CHASTINE
3
THE WORLD SPACE
•
The coordinate system of the virtual environment
(619, 10, 628)
JEFF CHASTINE
4
(619, 10, 628)
JEFF CHASTINE
5
QUESTION
• How did get the monster positioned correctly in the
world?
• Let’s come back to that…
JEFF CHASTINE
6
CAMERA SPACE
•
It’s all relative to the camera…
JEFF CHASTINE
7
CAMERA SPACE
•
It’s all relative to the camera… and the camera never moves!
(0, 0, -10)
JEFF CHASTINE
8
THE BIG PICTURE
•
How to we get from space to space?
?
JEFF CHASTINE
?
9
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
?
10
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
M
JEFF CHASTINE
V
11
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
12
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
JEFF CHASTINE
1.0
0.0
0.0
0.0
0.0
1.0
0.0
0.0
0.0
0.0
1.0
0.0
0.0
0.0
0.0
1.0
The Identity Matrix
13
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
14
BACK TO THE BIG PICTURE
•
If you multiply a matrix by a matrix, you get a matrix!
•
How might we make the model matrix?
Translation matrix T
Rotation matrix R1
Rotation matrix R2
Scale matrix S
M
JEFF CHASTINE
15
BACK TO THE BIG PICTURE
•
If you multiply a matrix by a matrix, you get a matrix!
•
How might we make the model matrix?
Translation matrix T
Rotation matrix R1
Rotation matrix R2
Scale matrix S
M
T * R1 * R2 * S = M
JEFF CHASTINE
16
MATRIX ORDER
•
Multiply left to right
•
Results are drastically different
(an angry vertex)
JEFF CHASTINE
17
MATRIX ORDER
•
Multiply left to right
•
Results are drastically different
•
Order of operations
• Rotate 45°
JEFF CHASTINE
18
MATRIX ORDER
•
Multiply left to right
•
Results are drastically different
•
Order of operations
• Rotate 45°
• Translate 10 units
JEFF CHASTINE
19
MATRIX ORDER
•
Multiply left to right
•
Results are drastically different
•
Order of operations
• Rotate 45°
• Translate 10 units
before
JEFF CHASTINE
after
20
MATRIX ORDER
•
Multiply left to right
•
Results are drastically different
•
Order of operations
JEFF CHASTINE
21
MATRIX ORDER
•
Multiply left to right
•
Results are drastically different
•
Order of operations
• Translate 10 units
JEFF CHASTINE
22
MATRIX ORDER
•
Multiply left to right
•
Results are drastically different
•
Order of operations
• Translate 10 units
• Rotate 45°
JEFF CHASTINE
23
MATRIX ORDER
•
Multiply left to right
•
Results are drastically different
•
Order of operations
after
• Translate 10 units
• Rotate 45°
before
JEFF CHASTINE
24
BACK TO THE BIG PICTURE
•
If you multiply a matrix by a matrix, you get a matrix!
•
How might we make the model matrix?
Translation matrix T
Rotation matrix R1
Rotation matrix R2
Scale matrix S
M
T * R1 * R2 * S = M
JEFF CHASTINE
Backwards
25
BACK TO THE BIG PICTURE
•
If you multiply a matrix by a matrix, you get a matrix!
•
How might we make the model matrix?
Translation matrix T
Rotation matrix R1
Rotation matrix R2
Scale matrix S
M
S * R1 * R2 * T = M
JEFF CHASTINE
26
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
27
ORTHOGRAPHIC VS. PERSPECTIVE
JEFF CHASTINE
28
AN OLD VERTEX SHADER
in vec4 vPosition;
// The vertex in NDC
Originally we passed using NDCs (-1 to +1)
void main () {
gl_Position = vPosition;
}
JEFF CHASTINE
29
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
JEFF CHASTINE
Original (local) position
30
SMILE – IT’S THE END!
JEFF CHASTINE
31
Download