new math func

This commit is contained in:
Nishi 2026-01-30 08:44:11 +09:00
commit 68e1228193
Signed by: nishi
GPG key ID: 27EF69B208EB9343
4 changed files with 38 additions and 0 deletions

View file

@ -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);

View file

@ -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
}

View file

@ -1,5 +1,7 @@
#include <GearSrc/GL.h>
#include <GearSrc/Math.h>
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();
}

View file

@ -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;