5,337
edits
Line 1: | Line 1: | ||
Basics of Computer Graphics | Basics of Computer Graphics | ||
==Homogeneous Coordinates== | |||
[http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/ http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/] | |||
Points and vectors are represented using homogeneous coordinates in computer graphics.<br> | |||
Points are <math>(x,y,z,1)</math> and vectors are <math>(x,y,z,0)</math>.<br> | |||
The last coordinate in points allow for translations to be represented as matrix multiplications.<br> | |||
Transformations consists of translations, rotations, and scaling | |||
===Translation Matrix=== | |||
<math> | |||
\begin{bmatrix} | |||
1 & 0 & 0 & X\\ | |||
0 & 1 & 0 & Y\\ | |||
0 & 0 & 1 & Z\\ | |||
0 & 0 & 0 & 1 | |||
\end{bmatrix} | |||
</math> | |||
===Rotation Matrix=== | |||
Rotations can be about the X, Y, and Z axis.<br> | |||
Below is a rotation about the Z axis by angle <math>\theta</math>.<br> | |||
<math> | |||
\begin{bmatrix} | |||
\cos(\theta) & -\sin(\theta) & 0 & 0\\ | |||
\sin(\theta) & \cos(\theta) & 0 & 0\\ | |||
0 & 0 & 1 & 0\\ | |||
0 & 0 & 0 & 1 | |||
\end{bmatrix} | |||
</math> | |||
===Scaling Matrix=== | |||
<math> | |||
\begin{bmatrix} | |||
X & 0 & 0 & 0\\ | |||
0 & Y & 0 & 0\\ | |||
0 & 0 & Z & 0\\ | |||
0 & 0 & 0 & 1 | |||
\end{bmatrix} | |||
</math> | |||
==MVP Matrices== | ==MVP Matrices== | ||
To convert from model coordinates <math>v</math> to screen coordinates <math>w</math>, you do multiply by the MVP matrices <math>w=P*V*M*v</math> | To convert from model coordinates <math>v</math> to screen coordinates <math>w</math>, you do multiply by the MVP matrices <math>w=P*V*M*v</math> | ||
* The model matrix <math>M</math> applies the transform of your object. This includes the position and rotation. <math>M*v</math> is in world coordinates. | * The model matrix <math>M</math> applies the transform of your object. This includes the position and rotation. <math>M*v</math> is in world coordinates. | ||
* The view matrix <math>V</math> applies the transform of your camera. | * The view matrix <math>V</math> applies the transform of your camera. | ||
* The projection matrix <math>P</math> applies the projection of your camera, typically an orthographic or a perspective camera. The perspective camera shrinks objects in the distance. | * The projection matrix <math>P</math> applies the projection of your camera, typically an orthographic or a perspective camera. The perspective camera shrinks objects in the distance. | ||
===View Matrix=== | ===View Matrix=== |