[Bf-python] matrix multiplication problem
models at paposo.com
models at paposo.com
Tue Nov 25 04:08:22 CET 2003
void Mat4MulVec4fl( float mat[][4], float *vec)
{
float x,y,z;
x=vec[0];
y=vec[1];
z= vec[2];
vec[0]=x*mat[0][0] + y*mat[1][0] + z*mat[2][0] + mat[3][0]*vec[3];
vec[1]=x*mat[0][1] + y*mat[1][1] + z*mat[2][1] + mat[3][1]*vec[3];
vec[2]=x*mat[0][2] + y*mat[1][2] + z*mat[2][2] + mat[3][2]*vec[3];
vec[3]=x*mat[0][3] + y*mat[1][3] + z*mat[2][3] + mat[3][3]*vec[3];
}
This is the typical way blender uses matrix muliplication. However, correct
me if Im wrong but i think this is not correct.
if you have a 3D vector and a 4x4 matrix:
[v0] [m0,0][m0,1][m0,2][m0,3]
[v1] [m1,0][m1,1][m1,2][m1,3]
[v2] x [m2,0][m2,1][m2,2][m2,3]
[1] [m3,0][m3,1][m3,2][m3,3]
The result should be:
[x] [m0,0][v0] +[m0,1][v1] +[m0,2][v2] +[m0,3][1]
[y] [m1,0][v0] +[m1,1][v1] +[m1,2][v2] +[m1,3][1]
[z] = [m2,0][v0] +[m2,1][v1] +[m2,2][v2] +[m2,3][1]
[1] [m3,0][v0] +[m3,1][v1] +[m3,2][v2] +[m3,3][1]
The above function (in fact all of the vector x matrix functions) from
athrib.c do this:
[x] [m0,0][v0] +[m0,1][v0] +[m0,2][v0] +[m0,3][v0]
[y] [m1,0][v1] +[m1,1][v1] +[m1,2][v1] +[m1,3][v1]
[z] = [m2,0][v2] +[m2,1][v2] +[m2,2][v2] +[m2,3][v2]
[1] [m3,0][1] +[m3,1][1] +[m3,2][1] +[m3,3][1]
Am i missing something here?
More information about the Bf-python
mailing list