This post is also available in: Italian
const float pi = 3.14159265f; // but an infinity of digits in reality
Cosinus & Sinus
(From http://commons.wikimedia.org/wiki/User:Geek3 , under GNU Free Documentation License )
t is an angle in radians.
0 radians = 0 degrees
180 degrees = Pi radians
360 degrees ( full circle ) = 2*Pi radians
90 degrees = Pi/2 radians
ALWAYS know in which coordinates your vector is. See section 3 for details.
A 3D vector is (x,y,z), but a homogeneous 3D vector is (x,y,z,w).
- w=0 : it’s a direction
- w=1 : it’s a position
- else : it may still be correct, but you’d better know what you’re doing.
You can only multiply a 4×4 matrix with a homogeneous vector.
Just like cartesian distance : sqrt( x² + y² + z² ). w doesn’t count.
The X is the notation for the cross product. length( a x b ) == length(a) * length(b) * sin(θ), so you may want to normalize() the result.
A.B = length(A)*cos(Theta) , but most likely computed as A.x*B.x +A.y*B.y +A.z*B.z
Addition and substraction
res.x = A.x + B.x res.y = A.y + B.y ...
res.x = A.x * B.x res.y = A.y * B.y ...
Divide the vector by its length :
normalizedVector = vec * ( 1.0f / vec.length() )
example for a translation matrix :
… but in your shaders, you can also represent your vectors in tangent space. And in image-space when you do post-effects.