aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/smcolor.hpp2
-rw-r--r--include/smelt.hpp2
-rw-r--r--include/smmath.hpp44
-rw-r--r--smelt/sdl/gfx_sdl.cpp6
-rw-r--r--smelt/sdl/smelt_internal.hpp2
5 files changed, 41 insertions, 15 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
diff --git a/smelt/sdl/gfx_sdl.cpp b/smelt/sdl/gfx_sdl.cpp
index 1c8545f..ae50db2 100644
--- a/smelt/sdl/gfx_sdl.cpp
+++ b/smelt/sdl/gfx_sdl.cpp
@@ -47,7 +47,7 @@ bool SMELT_IMPL::smRenderBegin2D(bool ztest,SMTRG trg)
vertexArray=vertexBuf;
return true;
}
-bool SMELT_IMPL::smRenderBegin3D(float fov,SMTRG trg)
+bool SMELT_IMPL::smRenderBegin3D(float fov,bool ztest,SMTRG trg)
{
TRenderTargetList *targ=(TRenderTargetList*)trg;
if(vertexArray)
@@ -55,8 +55,8 @@ bool SMELT_IMPL::smRenderBegin3D(float fov,SMTRG trg)
if(pOpenGLDevice->have_GL_EXT_framebuffer_object)
pOpenGLDevice->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,(targ)?targ->frame:0);
pOpenGLDevice->glDepthFunc(GL_LESS);
- pOpenGLDevice->glEnable(GL_DEPTH_TEST);
- zbufenabled=true;
+ ztest?pOpenGLDevice->glEnable(GL_DEPTH_TEST):pOpenGLDevice->glDisable(GL_DEPTH_TEST);
+ zbufenabled=ztest;
if(targ)
{
pOpenGLDevice->glScissor(0,0,targ->w,targ->h);
diff --git a/smelt/sdl/smelt_internal.hpp b/smelt/sdl/smelt_internal.hpp
index f514c54..a14e151 100644
--- a/smelt/sdl/smelt_internal.hpp
+++ b/smelt/sdl/smelt_internal.hpp
@@ -144,7 +144,7 @@ public:
virtual bool smGetInpEvent(smInpEvent *e);
virtual bool smRenderBegin2D(bool ztest=0,SMTRG trg=0);
- virtual bool smRenderBegin3D(float fov,SMTRG trg=0);
+ virtual bool smRenderBegin3D(float fov,bool ztest=0,SMTRG trg=0);
virtual bool smRenderEnd();
virtual void sm3DCamera6f2v(float *pos,float *rot);
virtual void sm2DCamera5f3v(float *pos,float *dpos,float *rot);