diff options
author | Chris Xiong <chirs241097@gmail.com> | 2016-05-17 23:49:44 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2016-05-17 23:49:44 +0800 |
commit | d961ae306461e1606d37539f512a5d907490531b (patch) | |
tree | 346b7c15df4cd50a16e38594063e25b25cb22a30 /include | |
parent | 3b2a801f86f4ce7cdca8681b619fe3ff88307ef2 (diff) | |
download | SMELT-d961ae306461e1606d37539f512a5d907490531b.tar.xz |
Fixed a bug in smColorRGBA.
Fix and modify smMatrix::lookat.
Allow disabling z-test in 3d mode.
Add smvec4d.
Diffstat (limited to 'include')
-rw-r--r-- | include/smcolor.hpp | 2 | ||||
-rw-r--r-- | include/smelt.hpp | 2 | ||||
-rw-r--r-- | include/smmath.hpp | 44 |
3 files changed, 37 insertions, 11 deletions
diff --git a/include/smcolor.hpp b/include/smcolor.hpp index 94ff4f3..a7feb65 100644 --- a/include/smcolor.hpp +++ b/include/smcolor.hpp @@ -27,7 +27,7 @@ public: friend smColorRGBA operator *(smColorRGBA a,float b){return smColorRGBA(b*a.r,b*a.g,b*a.b,b*a.a);} friend smColorRGBA operator /(smColorRGBA a,float b){return smColorRGBA(a.r/b,a.g/b,a.b/b,a.a/b);} void setHWColor(DWORD col){a=GETA(col)/255.;r=GETR(col)/255.;g=GETG(col)/255.;b=GETB(col)/255.;} - DWORD getHWColor(){clamp();return RGBA(r,g,b,a);} + DWORD getHWColor(){clamp();return RGBA(r*255.,g*255.,b*255.,a*255.);} }; class smColorHSVA { diff --git a/include/smelt.hpp b/include/smelt.hpp index e9caeb3..5c9b013 100644 --- a/include/smelt.hpp +++ b/include/smelt.hpp @@ -350,7 +350,7 @@ public: virtual bool smGetInpEvent(smInpEvent *e)=0; virtual bool smRenderBegin2D(bool ztest=0,SMTRG trg=0)=0; - virtual bool smRenderBegin3D(float fov,SMTRG trg=0)=0; + virtual bool smRenderBegin3D(float fov,bool ztest=0,SMTRG trg=0)=0; virtual bool smRenderEnd()=0; virtual void sm3DCamera6f2v(float *pos,float *rot)=0; virtual void sm2DCamera5f3v(float *pos,float *dpos,float *rot)=0; diff --git a/include/smmath.hpp b/include/smmath.hpp index b9763b7..84ef315 100644 --- a/include/smmath.hpp +++ b/include/smmath.hpp @@ -54,7 +54,7 @@ class smvec3d public: double x,y,z; smvec3d(double _x,double _y,double _z){x=_x;y=_y;z=_z;} - smvec3d(smvec2d a){x=a.x;y=a.y;z=.0;} + smvec3d(smvec2d a,double _z=.0){x=a.x;y=a.y;z=_z;} smvec3d(){x=y=z=.0;} double l(){return sqrt(sqr(x)+sqr(y)+sqr(z));} void normalize(){double L=l();if(L<EPS)return;x/=L;y/=L;z/=L;} @@ -68,6 +68,26 @@ public: friend double operator ^(smvec3d a,smvec3d b){return (a|b)/a.l()/b.l();} }; +class smvec4d +{ +public: + double x,y,z,w; + smvec4d(double _x,double _y,double _z,double _w){x=_x;y=_y;z=_z;w=_w;} + smvec4d(smvec3d a,double _w=.0){x=a.x;y=a.y;z=a.z;w=_w;} + smvec4d(){x=y=z=w=.0;} + double l(){return sqrt(sqr(x)+sqr(y)+sqr(z)+sqr(w));} + void normalize(){double L=l();if(L<EPS)return;x/=L;y/=L;z/=L;w/=L;} + smvec4d getNormalized(){double L=l();if(L<EPS)return smvec4d(0,0,0,0);return smvec4d(x/L,y/L,z/L,w/L);} + 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. + 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);} + friend double operator ^(smvec4d a,smvec4d b){return (a|b)/a.l()/b.l();} +}; + class smMatrix { public: @@ -104,15 +124,14 @@ public: tmp[3][3]=1; *this=*this*tmp; } - void lookat(double *eye,double *at,double *up) + void lookat(smvec3d eye,smvec3d at,smvec3d up) { - smvec3d f=smvec3d(at[0],at[1],at[2])-smvec3d(eye[0],eye[1],eye[2]);f.normalize(); - smvec3d UP=smvec3d(up[0],up[1],up[2]);UP.normalize(); - smvec3d s=f*UP;smvec3d u=s.getNormalized()*f; - *this[0][0]= s.x;*this[1][0]= s.y;*this[2][0]= s.z;*this[3][0]=0; - *this[0][1]= u.x;*this[1][1]= u.y;*this[2][1]= u.z;*this[3][1]=0; - *this[0][2]=-f.x;*this[1][2]=-f.y;*this[2][2]=-f.z;*this[3][2]=0; - *this[0][3]= 0;*this[1][3]= 0;*this[2][3]= 0;*this[3][3]=1; + smvec3d f=at-eye;f.normalize();up.normalize(); + smvec3d s=f*up;smvec3d u=s.getNormalized()*f; + m[0]= s.x;m[4]= s.y;m[ 8]= s.z;m[12]=0; + m[1]= u.x;m[5]= u.y;m[ 9]= u.z;m[13]=0; + m[2]=-f.x;m[6]=-f.y;m[10]=-f.z;m[14]=0; + m[3]= 0;m[7]= 0;m[11]= 0;m[15]=1; } friend smMatrix operator *(smMatrix a,smMatrix b) { @@ -129,5 +148,12 @@ public: a[0][1]*b.x+a[1][1]*b.y+a[2][1]*b.z, a[0][2]*b.x+a[1][2]*b.y+a[2][2]*b.z); } + friend smvec4d operator *(smMatrix a,smvec4d b) + { + return smvec4d(a[0][0]*b.x+a[1][0]*b.y+a[2][0]*b.z+a[3][0]*b.w, + a[0][1]*b.x+a[1][1]*b.y+a[2][1]*b.z+a[3][1]*b.w, + a[0][2]*b.x+a[1][2]*b.y+a[2][2]*b.z+a[3][2]*b.w, + a[0][3]*b.x+a[1][3]*b.y+a[2][3]*b.z+a[3][3]*b.w); + } }; #endif |