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

BIN
data/mdl/crate.gsm Normal file

Binary file not shown.

Binary file not shown.

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) {

View file

@ -0,0 +1,12 @@
# Blender 5.0.1 MTL File: 'None'
# www.blender.org
newmtl Material
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.500000
d 1.000000
illum 2
map_Kd model.png

View file

@ -0,0 +1,28 @@
# Blender 5.0.1
# www.blender.org
v -0.500000 -0.500000 0.500000
v -0.500000 0.500000 0.500000
v -0.500000 -0.500000 -0.500000
v -0.500000 0.500000 -0.500000
v 0.500000 -0.500000 0.500000
v 0.500000 0.500000 0.500000
v 0.500000 -0.500000 -0.500000
v 0.500000 0.500000 -0.500000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -0.0000 -1.0000 -0.0000
vn -0.0000 1.0000 -0.0000
vt 0.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
s 0
usemtl Material
f 1/1/1 2/2/1 4/3/1 3/4/1
f 3/1/2 4/2/2 8/3/2 7/4/2
f 7/4/3 8/3/3 6/2/3 5/1/3
f 5/4/4 6/3/4 2/2/4 1/1/4
f 3/2/5 7/3/5 5/4/5 1/1/5
f 8/3/6 4/2/6 2/1/6 6/4/6

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB