aboutsummaryrefslogtreecommitdiff
path: root/include/smmath.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/smmath.hpp')
-rw-r--r--include/smmath.hpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/include/smmath.hpp b/include/smmath.hpp
index 84ef315..d5ed80e 100644
--- a/include/smmath.hpp
+++ b/include/smmath.hpp
@@ -81,7 +81,7 @@ public:
friend smvec4d operator -(smvec4d a,smvec4d b){return smvec4d(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);}
friend smvec4d operator +(smvec4d a,smvec4d b){return smvec4d(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);}
friend double operator |(smvec4d a,smvec4d b){return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w;}
- //Note: this doesn't do a real cross product.
+ //Note: this doesn't do a real 4d cross product.
friend smvec4d operator *(smvec4d a,smvec4d b){return smvec4d(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x,1);}
friend smvec4d operator *(double a,smvec4d b){return smvec4d(a*b.x,a*b.y,a*b.z,a*b.w);}
friend smvec4d operator *(smvec4d a,double b){return smvec4d(b*a.x,b*a.y,b*a.z,b*a.w);}
@@ -103,6 +103,12 @@ public:
double* operator [](int s){if(s>=0&&s<4)return m+s*4;else return NULL;}
void clear(){for(int i=0;i<16;++i)m[i]=.0;}
void loadIdentity(){clear();m[0]=m[5]=m[10]=m[15]=1.;}
+ void translate(double x,double y,double z)
+ {
+ smMatrix tmp;tmp.loadIdentity();
+ tmp.m[12]=x;tmp.m[13]=y;tmp.m[14]=z;
+ *this=*this*tmp;
+ }
void rotate(double a,double x,double y,double z)
{
if(smvec3d(x,y,z).l()<=EPS)return;
@@ -112,16 +118,17 @@ public:
x=a.x;y=a.y;z=a.z;
}
smMatrix tmp;
- tmp[0][0]=x*x*(1-cos(a))+cos(a);
- tmp[1][0]=x*y*(1-cos(a))-z*sin(a);
- tmp[2][0]=x*z*(1-cos(a))+y*sin(a);
- tmp[0][1]=y*x*(1-cos(a))+z*sin(a);
- tmp[1][1]=y*y*(1-cos(a))+cos(a);
- tmp[2][1]=y*z*(1-cos(a))-x*sin(a);
- tmp[0][2]=x*z*(1-cos(a))-y*sin(a);
- tmp[1][2]=y*z*(1-cos(a))+x*sin(a);
- tmp[2][2]=z*z*(1-cos(a))+cos(a);
- tmp[3][3]=1;
+ double c=cos(a),s=sin(a);
+ tmp.m[ 0]=x*x*(1-c)+c;
+ tmp.m[ 4]=x*y*(1-c)-z*s;
+ tmp.m[ 8]=x*z*(1-c)+y*s;
+ tmp.m[ 1]=y*x*(1-c)+z*s;
+ tmp.m[ 5]=y*y*(1-c)+c;
+ tmp.m[ 9]=y*z*(1-c)-x*s;
+ tmp.m[ 2]=x*z*(1-c)-y*s;
+ tmp.m[ 6]=y*z*(1-c)+x*s;
+ tmp.m[10]=z*z*(1-c)+c;
+ tmp.m[15]=1;
*this=*this*tmp;
}
void lookat(smvec3d eye,smvec3d at,smvec3d up)
@@ -139,7 +146,7 @@ public:
for(int i=0;i<4;++i)
for(int j=0;j<4;++j)
for(int k=0;k<4;++k)
- ret[i][j]+=a[i][k]*b[k][j];
+ ret[j][i]+=a[k][i]*b[j][k];
return ret;
}
friend smvec3d operator *(smMatrix a,smvec3d b)