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 )
( Modified from http://en.wikipedia.org/wiki/User:Gustavb under Crative Commons 3.0 )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 4x4 matrix with a homogeneous vector.
Just like cartesian distance : sqrt( x² + y² + z² ). w doesn’t count.
( Modified from http://en.wikipedia.org/wiki/User:Acdx , former image under Creative Commons 3.0 )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.
( from http://en.wikipedia.org/wiki/File:Dot_Product.svg )A.B = length(A)cos(Theta) , but most likely computed as A.xB.x +A.yB.y +A.zB.z
Addition and substraction
1 res.x = A.x + B.x 2 res.y = A.y + B.y 3 ...
1 res.x = A.x * B.x 2 res.y = A.y * B.y 3 ...
Divide the vector by its length :
1 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.
res.x = A.x + B.x