Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 12 September 2003 - 11:24 PM
Posted 12 September 2003 - 11:32 PM
//#define _float double
#ifndef _float
#define _float float
#endif
class MATRIX{// Last row is 0, 0, 0, 1, else change class functions( remove // and /* ), frustum changes last row
union{
_float m[4*4]; // m[x][y]= [((x-1)*4) + (y-1)]
struct { // mxy !!!(in definition/here reversed)=>
_float m11, m12, m13, m14, // m11 m21 m31 m41
m21, m22, m23, m24, // m12 m22 m32 m42
m31, m32, m33, m34, // m13 m23 m33 m43
m41, m42, m43, m44; // m14 m24 m34 m44
};
};
...
_float MATRIX::GetM3Determinant(const MATRIX3 &matrix){
return ( matrix.x.x * (matrix.y.y * matrix.z.z - matrix.y.z * matrix.z.y) -
matrix.y.x * (matrix.x.y * matrix.z.z - matrix.x.z * matrix.z.y) +
matrix.z.x * (matrix.x.y * matrix.y.z - matrix.x.z * matrix.y.y) );
}
MATRIX::MATRIX3 MATRIX::GetSubMatrix(long x, long y){
MATRIX3 tmp;
long xoffset= 0;
for(long i=0; i < 4; i++)
if(i != x){
long yoffset= 0;
for(long j= 0; j < 4; j++)
if(j != y){
*( ((_float *) &tmp) + xoffset*3 + yoffset)= m[i*4 + j];
yoffset++;
}
xoffset++;
}
return tmp;
}
_float MATRIX::GetDeterminant(){
_float result= 0;
long i= 1;
MATRIX3 tmp;
for(long n= 0; n < 4; n++, i*=-1){
tmp= GetSubMatrix(0, n);
result+= m[n] * GetM3Determinant(tmp) * i;
}
return result;
}
MATRIX MATRIX::GetCorrectInverse(){
MATRIX inverse;
MATRIX3 tmp;
_float m4determinant= GetDeterminant();
if(fabs(m4determinant) < bias)
inverse= MATRIX(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);// Matrix has no inverse
else{
for( long i=0; i < 4; i++)
for(long j=0; j < 4; j++){
long sign= 1-((i+j)%2)*2;
tmp= GetSubMatrix(i, j);
inverse.m[i + j*4]= GetM3Determinant(tmp) * sign / m4determinant;
}
}
return inverse;
}
class VECTOR3D{
public:
_float x, y, z;
...
struct MATRIX3{
VECTOR3D x,y,z;
};
_float MATRIX::GetDeterminant(){//of a 4x4 Matrix!
_float result= 0;
long i= 1;
MATRIX3 tmp;
for(long n= 0; n < 4; n++, i*=-1){
tmp= GetSubMatrix(0, n);
result+= m[n] * GetM3Determinant(tmp) * i;
}
return result;
}
Posted 12 September 2003 - 11:58 PM
Posted 15 September 2003 - 05:18 AM
Posted 15 September 2003 - 11:21 AM
Posted 16 September 2003 - 03:30 AM
Posted 16 September 2003 - 05:31 AM
Posted 16 September 2003 - 07:06 AM
Posted 16 September 2003 - 02:11 PM
Posted 17 September 2003 - 05:05 AM
MatrixInvRotate(mtxin, mtxout);
void MatrixInvRotate(glMatrix mtxin, glMatrix mtxout)
{
for(int i=0 ; i<3; i++) {
for(int j=0; j<3; j++) {
mtxout[j][i] = mtxin[i][j];
}
}
}
msVec3 vTmp, vTmp2;
vTmp[0] = -mtxin[3][0];
vTmp[1] = -mtxin[3][1];
vTmp[2] = -mtxin[3][2];
VectorRotate(vTmp, mtxout, vTmp2);
void VectorRotate (const msVec3 vin, const glMatrix mtx, msVec3 vout)
{
vout[0] = vin[0]*mtx[0][0] + vin[1]*mtx[1][0] + vin[2]*mtx[2][0];
vout[1] = vin[0]*mtx[0][1] + vin[1]*mtx[1][1] + vin[2]*mtx[2][1];
vout[2] = vin[0]*mtx[0][2] + vin[1]*mtx[1][2] + vin[2]*mtx[2][2];
}
mtxout[3][0] = vTmp2[0];
mtxout[3][1] = vTmp2[1];
mtxout[3][2] = vTmp2[2];
mtxout[0][3] = mtxout[1][3] = mtxout[2][3] = 0.0f;
mtxout[3][3] = 1.0f;
Posted 18 September 2003 - 01:13 AM
quote:
I use inverse matrices for cameras, bone animation and skinning using bone weights, and object picking.
Posted 18 September 2003 - 01:50 AM
Posted 18 September 2003 - 03:02 AM
quote:
Original post by nfz
For bone animation the inverse matrix representing bone position and rotation is required for doing both forward and inverse kynematics.
quote:
Original post by nfz
The inverse matrix of the bone position and rotation is also required for skinning because I store the vertices in object space rather than bone space since each vertex can be attached to more than one bone.
quote:
Doing it this way makes for slightly simpler code that runs faster especially as a vertex program on a GPU(ie vertex shader).
Posted 18 September 2003 - 11:01 AM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.