This commit is contained in:
Nishi 2026-02-03 10:13:49 +09:00
commit a1e4c9ab2c
Signed by: nishi
GPG key ID: 27EF69B208EB9343
10 changed files with 68 additions and 45 deletions

View file

@ -56,16 +56,14 @@ static void render(GSEngine self){
for(i = 0; i < sizeof(obj) / sizeof(obj[0]); i++){
GSVector3 rv;
GSMatrix3x3 rm;
GSRotation rot;
rot.use_matrix = GSTrue;
GSPhysicsGetPosition(obj[i], rv);
GSPhysicsGetRotation(obj[i], rm);
GSPhysicsGetRotation(obj[i], rot.u.matrix);
GSGLPushMatrix(gl);
GSGLSetPosition(gl, rv);
GSGLSetRotation3x3(gl, rm);
GSModelDraw(mdl);
GSGLPopMatrix(gl);
GSModelDraw(mdl, rv, &rot);
}
GSGLSetColor(gl, col2);
@ -106,7 +104,7 @@ int main(int argc, char** argv){
GSVector3 pos = {0, 1, 0};
GSVector3 sz = {1, 1, 1};
mdl = GSModelOpen(engine, "game:/mdl/fish.gsm");
mdl = GSModelOpen(engine, "game:/mdl/tetopear.gsm");
for(i = 0; i < sizeof(obj) / sizeof(obj[0]); i++){
obj[i] = GSPhysicsCreateSphere(GSServerGetPhysics(GSEngineGetServer(engine)), 1, 0.5);

View file

@ -45,7 +45,7 @@ GSDECL void GSGLShadowEnd(GSGL gl);
GSDECL void GSGLShadowDeinit(GSGL gl);
GSDECL void GSGLShadowDisable(GSGL gl);
GSDECL void GSGLShadowEnable(GSGL gl);
GSDECL int GSGLShadowCascadeSteps(GSGL gl);
GSDECL int GSGLShadowCascadeSteps(GSGL gl);
/* gl.c */
GSDECL GSGL GSGLCreate(GSClient client);
@ -59,8 +59,7 @@ GSDECL void GSGLPolygon2D(GSGL gl, int pairs, GSVector2* vert, GSVector2* tex)
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 GSGLSetRotation(GSGL gl, GSRotation* rot);
GSDECL void GSGLPushMatrix(GSGL gl);
GSDECL void GSGLPopMatrix(GSGL gl);
GSDECL GLuint GSGLBeginList(GSGL gl);

View file

@ -9,7 +9,7 @@ extern "C" {
#endif
GSDECL GSModel GSModelOpen(GSEngine engine, const char* path);
GSDECL void GSModelDraw(GSModel model);
GSDECL void GSModelDraw(GSModel model, GSVector3 pos, GSRotation* rot);
GSDECL void GSModelClose(GSModel model);
#ifdef __cplusplus

View file

@ -51,6 +51,8 @@ typedef struct _GSNetAddress GSNetAddress;
typedef struct _GSBinary GSBinary;
typedef struct _GSNetState GSNetState;
typedef struct _GSNetKV GSNetKV;
typedef union _GSRotationUnion GSRotationUnion;
typedef struct _GSRotation GSRotation;
#ifdef _GEARSRC
typedef struct _GSClient* GSClient;
typedef struct _GSServer* GSServer;
@ -176,6 +178,16 @@ struct _GSNetKV {
GSNetState value;
};
union _GSRotationUnion {
GSVector3 vector;
GSMatrix3x3 matrix;
};
struct _GSRotation {
GSBool use_matrix;
GSRotationUnion u;
};
#ifdef _GEARSRC
#include <GearSrc/GL/GL.h>
#include <miniaudio.h>

View file

@ -16,7 +16,7 @@
#include <stb_ds.h>
#ifdef _WIN32
static void init_winsock(void){
static void init_winsock(void) {
WSADATA wsa;
WSAStartup(MAKEWORD(1, 1), &wsa);

View file

@ -121,21 +121,21 @@ void GSGLSetPosition(GSGL gl, GSVector3 pos) {
glTranslatef(pos[0], pos[1], -pos[2]);
}
void GSGLSetRotation(GSGL gl, GSVector3 rot) {
glRotatef(rot[0], 1, 0, 0);
glRotatef(rot[1], 0, 1, 0);
glRotatef(rot[2], 0, 0, 1);
}
void GSGLSetRotation(GSGL gl, GSRotation* rot) {
if(rot->use_matrix) {
GSMatrix4x4 out, out2;
GLdouble mat[16];
int i;
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);
GSMath3x3To4x4(out, rot->u.matrix);
GSMathRowToColumn4x4(out2, out);
for(i = 0; i < 16; i++) mat[i] = out2[i];
glMultMatrixd(mat);
} else {
glRotatef(rot->u.vector[0], 1, 0, 0);
glRotatef(rot->u.vector[1], 0, 1, 0);
glRotatef(rot->u.vector[2], 0, 0, 1);
}
}
void GSGLPushMatrix(GSGL gl) {

View file

@ -64,7 +64,7 @@ void GSGLCameraLookAt(GSGL gl, GSVector3 camera, GSVector3 look_at) {
glMultMatrixd(matrix);
glTranslated(-camera[0], -camera[1], camera[2]);
if(gl->shadow_use_shader){
if(gl->shadow_use_shader) {
glUseProgram(gl->shadow_shader);
glUniform3f(glGetUniformLocation(gl->shadow_shader, "camera"), camera[0], camera[1], camera[2]);
glUseProgram(0);

View file

@ -179,11 +179,11 @@ void GSGLTetrakis(GSGL gl, GSNumber scale, GSVector4 col1, GSVector4 col2) {
{0, 1, 0},
{-0.75, 0.75, -0.75},
{0.75, 0.75, -0.75}};
GSVector3 n;
GSVector3 rot2 = {0, 90, 0};
GSVector3 rot3 = {0, 0, 90};
GSVector3 rot4 = {90, 0, 0};
int i, j, k = 0;
GSVector3 n;
GSRotation rot2 = {0, {0, 90, 0}};
GSRotation rot3 = {0, {0, 0, 90}};
GSRotation rot4 = {0, {90, 0, 0}};
int i, j, k = 0;
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) v[i][j] *= scale;
@ -197,17 +197,17 @@ void GSGLTetrakis(GSGL gl, GSNumber scale, GSVector4 col1, GSVector4 col2) {
GSGLSetColor(gl, ((k + j) % 2) ? col2 : col1);
GSGLPolygon(gl, 3, v, NULL, n);
GSGLSetRotation(gl, rot2);
GSGLSetRotation(gl, &rot2);
}
if(i == 3) {
GSGLSetRotation(gl, rot4);
GSGLSetRotation(gl, &rot4);
k++;
} else if(i == 4) {
GSGLSetRotation(gl, rot4);
GSGLSetRotation(gl, rot4);
GSGLSetRotation(gl, &rot4);
GSGLSetRotation(gl, &rot4);
} else {
GSGLSetRotation(gl, rot3);
GSGLSetRotation(gl, &rot3);
k++;
}
}

View file

@ -74,7 +74,7 @@ GSBool GSGLShadowBegin(GSGL gl) {
return GSTrue;
}
int GSGLShadowCascadeSteps(GSGL gl){
int GSGLShadowCascadeSteps(GSGL gl) {
if(gl->engine->client->light0[3]) return 1;
return GSGL_SHADOW_CASCADES;
@ -92,8 +92,10 @@ void GSGLShadowCascade(GSGL gl, int cascade) {
// Simple cascade sizing
if(cascade == 0) size = 10;
else if(cascade == 1) size = 40;
else size = 100; // Covers max distance roughly
else if(cascade == 1)
size = 40;
else
size = 100; // Covers max distance roughly
// If light is directional (light0[3] == 0)
// Current existing code logic:

View file

@ -274,8 +274,16 @@ GSModel GSModelOpen(GSEngine engine, const char* path) {
/* TODO: check for animation */
if(gl != NULL) {
GLuint list = GSGLBeginList(gl);
GSModelDraw(model);
GLuint list = GSGLBeginList(gl);
GSVector3 pos = {0, 0, 0};
GSRotation rot;
rot.use_matrix = GSFalse;
rot.u.vector[0] = 0;
rot.u.vector[1] = 0;
rot.u.vector[2] = 0;
GSModelDraw(model, pos, &rot);
GSGLEndList(gl);
model->call_list = list;
@ -284,10 +292,13 @@ GSModel GSModelOpen(GSEngine engine, const char* path) {
return model;
}
void GSModelDraw(GSModel model) {
void GSModelDraw(GSModel model, GSVector3 pos, GSRotation* rot) {
GSGL gl = model->engine->client->gl;
int i;
GSGLPushMatrix(gl);
GSGLSetPosition(gl, pos);
GSGLSetRotation(gl, rot);
if(model->call_list == 0) {
char* k = "default";
@ -307,6 +318,7 @@ void GSModelDraw(GSModel model) {
} else {
GSGLCallList(gl, model->call_list);
}
GSGLPopMatrix(gl);
}
void GSModelClose(GSModel model) {