diff options
Diffstat (limited to 'sdl/math3d.h')
-rw-r--r-- | sdl/math3d.h | 74 |
1 files changed, 27 insertions, 47 deletions
diff --git a/sdl/math3d.h b/sdl/math3d.h index ed72e56..4ebe092 100644 --- a/sdl/math3d.h +++ b/sdl/math3d.h @@ -16,44 +16,24 @@ #define m3dRadToDeg(x) ((x)*M3D_INV_PI_DIV_180) typedef float M3DMatrix44f[16]; /* 4x4 matrix */ +typedef float M3DMatrix33f[9]; /* 3x3 matrix */ +typedef float M3DVector4f[4]; /* vector of 4 floats */ typedef float M3DVector3f[3]; /* vector of 3 floats */ typedef float M3DVector2f[2]; /* vector of 2 floats */ -/* this is the targa header, pragmas are needed to do the voodoo magic */ -/* http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/ */ -#pragma pack(1) -typedef struct -{ - GLbyte identsize; /* Size of id field that follows header (0) */ - GLbyte imageType; /* 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8 = rle */ - GLbyte colorMapType; /* 0 = none, 1 = paletted */ - unsigned short colorMapStart; /* first colour map entry */ - unsigned short colorMapLength; /* number of colors */ - unsigned char colorMapBits; /* bits per palette entry */ - unsigned short xstart; /* image x origin */ - unsigned short ystart; /* image y origin */ - unsigned short width; /* width in pixels */ - unsigned short height; /* height in pixels */ - GLbyte bits; /* bits per pixel (8 16, 24, 32) */ - GLbyte descriptor; /* image descriptor */ -} TGAHEADER; -#pragma pack(1) - /* math function prototypes */ -void m3dFindNormal(M3DVector3f, const M3DVector3f, const M3DVector3f, +void m3dFindNormalf(M3DVector3f, const M3DVector3f, const M3DVector3f, const M3DVector3f); -void m3dLoadIdentity44(M3DMatrix44f); -void m3dRotationMatrix44(M3DMatrix44f, float, float, float, float); -void gltDrawTorus(GLfloat, GLfloat, GLint, GLint); -void DrawJet(int); -void gltDrawUnitAxes(void); -void m3dMatrixMultiply44(M3DMatrix44f, const M3DMatrix44f, const M3DMatrix44f); - -/* other function prototypes */ -GLint gltWriteTGA(const char *); -GLbyte *gltLoadTGA(const char *, GLint *, GLint *, GLint *, GLenum *); - -static inline void m3dCrossProduct(M3DVector3f result, const M3DVector3f u, +void m3dLoadIdentity33f(M3DMatrix33f m); +void m3dLoadIdentity44f(M3DMatrix44f); +void m3dGetPlaneEquationf(M3DVector4f planeEq, const M3DVector3f p1, + const M3DVector3f p2, const M3DVector3f p3); +void m3dRotationMatrix44f(M3DMatrix44f, float, float, float, float); +void m3dMakePlanarShadowMatrixf(M3DMatrix44f proj, const M3DVector4f planeEq, + const M3DVector3f vLightPos); +void m3dMatrixMultiply44f(M3DMatrix44f, const M3DMatrix44f, const M3DMatrix44f); + +static inline void m3dCrossProductf(M3DVector3f result, const M3DVector3f u, const M3DVector3f v) { result[0] = u[1] * v[2] - v[1] * u[2]; @@ -61,38 +41,37 @@ static inline void m3dCrossProduct(M3DVector3f result, const M3DVector3f u, result[2] = u[0] * v[1] - v[0] * u[1]; } -static inline void m3dTransformVector3(M3DVector3f vOut, const M3DVector3f v, +static inline void m3dTransformVector3f(M3DVector3f vOut, const M3DVector3f v, const M3DMatrix44f m) { - vOut[0] = m[0] * v[0] + m[4] * v[1] + m[8] * v[2] + m[12]; /* * v[3]; */ - vOut[1] = m[1] * v[0] + m[5] * v[1] + m[9] * v[2] + m[13]; /* * v[3]; */ - vOut[2] = m[2] * v[0] + m[6] * v[1] + m[10] * v[2] + m[14]; /* * v[3]; */ - /* vOut[3] = m[3] * v[0] + m[7] * v[1] + m[11] * v[2] + m[15] * v[3]; */ + vOut[0] = m[0] * v[0] + m[4] * v[1] + m[8] * v[2] + m[12]; + vOut[1] = m[1] * v[0] + m[5] * v[1] + m[9] * v[2] + m[13]; + vOut[2] = m[2] * v[0] + m[6] * v[1] + m[10] * v[2] + m[14]; } -static inline void m3dScaleVector3(M3DVector3f v, float scale) +static inline void m3dScaleVector3f(M3DVector3f v, float scale) { v[0] *= scale; v[1] *= scale; v[2] *= scale; } -static inline float m3dGetVectorLengthSquared(const M3DVector3f u) +static inline float m3dGetVectorLengthSquaredf(const M3DVector3f u) { return (u[0] * u[0]) + (u[1] * u[1]) + (u[2] * u[2]); } -static inline float m3dGetVectorLength(const M3DVector3f u) +static inline float m3dGetVectorLengthf(const M3DVector3f u) { - return (float) (sqrt((double) (m3dGetVectorLengthSquared(u)))); + return (float) (sqrt((double) (m3dGetVectorLengthSquaredf(u)))); } -static inline void m3dNormalizeVector(M3DVector3f u) +static inline void m3dNormalizeVectorf(M3DVector3f u) { - m3dScaleVector3(u, 1.0f / m3dGetVectorLength(u)); + m3dScaleVector3f(u, 1.0f / m3dGetVectorLengthf(u)); } -static inline void m3dTranslateMatrix44(M3DMatrix44f m, float x, float y, +static inline void m3dTranslateMatrix44f(M3DMatrix44f m, float x, float y, float z) { m[12] += x; @@ -100,7 +79,7 @@ static inline void m3dTranslateMatrix44(M3DMatrix44f m, float x, float y, m[14] += z; } -static inline void m3dScaleMatrix44(M3DMatrix44f m, float x, float y, float z) +static inline void m3dScaleMatrix44f(M3DMatrix44f m, float x, float y, float z) { m[0] *= x; m[5] *= y; @@ -120,10 +99,11 @@ static inline void m3dScaleMatrix44(M3DMatrix44f m, float x, float y, float z) } \ } -static inline void m3dTransposeMatrix44(M3DMatrix44f dst, +static inline void m3dTransposeMatrix44f(M3DMatrix44f dst, const M3DMatrix44f src) { TRANSPOSE44(dst, src); } #endif + |