Matrix 4x4 Translation of a vector
Submitted by markos on Sat, 01/03/2008 - 20:56
(Please see Matrix 4x4 addition/subtraction (floats) for the typedefs and definitions used.)
Getting the translation matrix of a vector is essential to do movements of a vector in 3D space.
For the theory behind translation matrices please see URL below.
We follow a similar method as in the Identity matrix:
void Mat44Identity(Mat44 m, Vec4f pVec) { vector float v0 = vec_ctf(vec_splat_u32(0), 0); LOAD_VECTOR(vvec, pVec); CLEAR_VECTOR(&m[0]); CLEAR_VECTOR(&m[4]); CLEAR_VECTOR(&m[8]); STORE_VECTOR(vvec, &m[12]); m[15] = 1.0f; }
where we defined CLEAR_VECTOR as the macro:
#define CLEAR_VECTOR(vs) \ { \ vec_st(vec_splat_s8(0), 0, (float *)vs); \ }
Relevant URLs: