5,321
edits
Line 11: | Line 11: | ||
[https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/lookat-function Lookat function]<br> | [https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/lookat-function Lookat function]<br> | ||
The view matrix is a 4x4 matrix which encodes the position and rotation of the camera.<br> | The view matrix is a 4x4 matrix which encodes the position and rotation of the camera.<br> | ||
Given a camera at position <math>p</math> looking at target <math>t | Given a camera at position <math>\mathbf p</math> looking at target <math>\mathbf t</math> and up vector <math>\mathbf u</math>.<br> | ||
We can calculate the forward vector (from target to position) as <math>\mathbf{f}=\mathbf{p} - \mathbf{t}</math>.<br> | |||
We can calculate the right vector as <math>\mathbf u \times \mathbf f</math>.<br> | |||
Then the view matrix is written as: | |||
<pre> | <pre> | ||
r_x r_y r_z 0 | r_x r_y r_z 0 |