Jump to content

Computer Graphics: Difference between revisions

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=p-f</math> with up vector <math>u</math> and right vector <math>r</math>,
Given a camera at position <math>\mathbf p</math> looking at target <math>\mathbf t</math> and up vector <math>\mathbf u</math>.<br>
this matrix is written as:
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