diff --git a/engine/include/GearSrc/GL.h b/engine/include/GearSrc/GL.h index 2a54cef..e7909fa 100644 --- a/engine/include/GearSrc/GL.h +++ b/engine/include/GearSrc/GL.h @@ -56,6 +56,7 @@ GSDECL void GSGLBegin2D(GSGL gl); GSDECL void GSGLEnd2D(GSGL gl); GSDECL void GSGLSetPosition(GSGL gl, GSVector3 pos); GSDECL void GSGLSetRotation(GSGL gl, GSVector3 rot); +GSDECL void GSGLSetRotation3x3(GSGL gl, GSMatrix3x3 rot); GSDECL void GSGLPushMatrix(GSGL gl); GSDECL void GSGLPopMatrix(GSGL gl); GSDECL GLuint GSGLBeginList(GSGL gl); diff --git a/engine/include/GearSrc/Math.h b/engine/include/GearSrc/Math.h index e577b1a..c0f8d97 100644 --- a/engine/include/GearSrc/Math.h +++ b/engine/include/GearSrc/Math.h @@ -19,10 +19,13 @@ GSDECL void GSMathNormalTriangle(GSVector3 r, GSVector3 v0, GSVector3 v1, GSVect GSDECL void GSMathNormalQuad(GSVector3 r, GSVector3 v0, GSVector3 v1, GSVector3 v2, GSVector3 v3); GSDECL void GSMathInvert4x4(GSMatrix4x4 out, GSMatrix4x4 in); GSDECL void GSMathRowToColumn4x4(GSMatrix4x4 out, GSMatrix4x4 in); +GSDECL void GSMathRowToColumn3x3(GSMatrix3x3 out, GSMatrix3x3 in); +GSDECL void GSMath3x3To4x4(GSMatrix4x4 out, GSMatrix3x3 in); GSDECL GSNumber GSMathCot(GSNumber x); GSDECL GSNumber GSMathClosestPOT(GSNumber x); #define GSMathColumnToRow4x4 GSMathRowToColumn4x4 +#define GSMathColumnToRow3x3 GSMathRowToColumn3x3 #ifdef __cplusplus } diff --git a/engine/src/gl/gl.c b/engine/src/gl/gl.c index 42635d3..7b671cc 100644 --- a/engine/src/gl/gl.c +++ b/engine/src/gl/gl.c @@ -1,5 +1,7 @@ #include +#include + GSGL GSGLCreate(GSClient client) { GLfloat lightamb[] = {0.5, 0.5, 0.5, 1.0}; GLfloat lightcol[] = {1.0, 1.0, 1.0, 1.0}; @@ -125,6 +127,17 @@ void GSGLSetRotation(GSGL gl, GSVector3 rot) { glRotatef(rot[2], 0, 0, 1); } +void GSGLSetRotation3x3(GSGL gl, GSMatrix3x3 rot) { + GSMatrix4x4 out, out2; + GLdouble mat[16]; + int i; + + GSMath3x3To4x4(out, rot); + GSMathRowToColumn4x4(out2, out); + for(i = 0; i < 16; i++) mat[i] = out2[i]; + glMultMatrixd(mat); +} + void GSGLPushMatrix(GSGL gl) { glPushMatrix(); } diff --git a/engine/src/math.c b/engine/src/math.c index 9c09c03..a45621c 100644 --- a/engine/src/math.c +++ b/engine/src/math.c @@ -99,6 +99,27 @@ void GSMathRowToColumn4x4(GSMatrix4x4 out, GSMatrix4x4 in) { } } +void GSMathRowToColumn3x3(GSMatrix3x3 out, GSMatrix3x3 in) { + int y, x; + for(y = 0; y < 3; y++) { + for(x = 0; x < 3; x++) { + out[3 * x + y] = in[3 * y + x]; + } + } +} + +void GSMath3x3To4x4(GSMatrix4x4 out, GSMatrix3x3 in) { + int y, x, i; + for(i = 0; i < 16; i++) out[i] = 0; + for(y = 0; y < 3; y++) { + for(x = 0; x < 3; x++) { + out[4 * y + x] = in[3 * y + x]; + } + } + + out[15] = 1; +} + void GSMathInvert4x4(GSMatrix4x4 out, GSMatrix4x4 in) { GSNumber inv[16], det; int i;