add crate model

This commit is contained in:
Nishi 2026-01-19 13:53:52 +09:00
commit d738cf21f7
10 changed files with 60 additions and 18 deletions

View file

@ -44,7 +44,8 @@ GSDECL void GSGLPolygon(GSGL gl, int pairs, GSVector3* vert, GSVector2* tex, G
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, GSVector3 rot);
GSDECL void GSGLSetPosition(GSGL gl, GSVector3 pos);
GSDECL void GSGLSetRotation(GSGL gl, GSVector3 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, GSVector3 pos, GSVector3 rot);
GSDECL void GSModelDraw(GSModel model);
GSDECL void GSModelClose(GSModel model);
#ifdef __cplusplus

View file

@ -14,7 +14,7 @@ GSClient GSClientCreate(GSEngine engine) {
client->engine = engine;
client->camera[0] = 0;
client->camera[1] = 1;
client->camera[1] = 2;
client->camera[2] = 5;
client->look_at[0] = 0;
@ -52,7 +52,7 @@ static void scene(GSClient client) {
int i;
int a = 1;
if(m == NULL) m = GSModelOpen(client->engine, "game:/mdl/tetopear.gsm");
if(m == NULL) m = GSModelOpen(client->engine, "game:/mdl/crate.gsm");
rot[1] = r;
for(i = -a; i <= a; i++) {
@ -61,7 +61,12 @@ static void scene(GSClient client) {
pos[0] = i * 1.5;
for(j = -a; j <= a; j++) {
pos[2] = j * 1.5;
GSModelDraw(m, pos, rot);
GSGLPushMatrix(client->gl);
GSGLSetPosition(client->gl, pos);
GSGLSetRotation(client->gl, rot);
GSModelDraw(m);
GSGLPopMatrix(client->gl);
}
}
r++;

View file

@ -111,8 +111,11 @@ void GSGLEnd2D(GSGL gl) {
GSGLCareDepth(gl);
}
void GSGLSetPosition(GSGL gl, GSVector3 pos, GSVector3 rot) {
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);

View file

@ -135,9 +135,9 @@ static void parse_obj(GSModel model, char* txt) {
if(c == 3 || c == 4) {
for(i = 0; i < c; i++) {
if(arrlen(model->vertex) > varr[i] * 3) {
face.vertex[i][0] = model->vertex[varr[i] * 3 + 0] / sc;
face.vertex[i][1] = (model->vertex[varr[i] * 3 + 1] + dm) / sc;
face.vertex[i][2] = model->vertex[varr[i] * 3 + 2] / sc;
face.vertex[i][0] = (model->vertex[varr[i] * 3 + 0] - lm - lr / 2) / sc;
face.vertex[i][1] = (model->vertex[varr[i] * 3 + 1] - dm - ud / 2) / sc;
face.vertex[i][2] = (model->vertex[varr[i] * 3 + 2] - bm - bf / 2) / sc;
}
if(arrlen(model->texcoord) > tarr[i] * 2) {
@ -274,10 +274,8 @@ GSModel GSModelOpen(GSEngine engine, const char* path) {
/* TODO: check for animation */
if(gl != NULL) {
GSVector3 pos = {0, 0, 0};
GSVector3 rot = {0, 0, 0};
GLuint list = GSGLBeginList(gl);
GSModelDraw(model, pos, rot);
GSModelDraw(model);
GSGLEndList(gl);
model->call_list = list;
@ -286,13 +284,10 @@ GSModel GSModelOpen(GSEngine engine, const char* path) {
return model;
}
void GSModelDraw(GSModel model, GSVector3 pos, GSVector3 rot) {
void GSModelDraw(GSModel model) {
GSGL gl = model->engine->client->gl;
int i;
GSGLPushMatrix(gl);
GSGLSetPosition(gl, pos, rot);
if(model->call_list == 0) {
char* k = "default";
@ -312,8 +307,6 @@ void GSModelDraw(GSModel model, GSVector3 pos, GSVector3 rot) {
} else {
GSGLCallList(gl, model->call_list);
}
GSGLPopMatrix(gl);
}
void GSModelClose(GSModel model) {