diff --git a/data/mdl/crate.gsm b/data/mdl/crate.gsm new file mode 100644 index 0000000..6172778 Binary files /dev/null and b/data/mdl/crate.gsm differ diff --git a/data/mdl/tetopear.gsm b/data/mdl/tetopear.gsm index 6bdbd80..81b8ec5 100644 Binary files a/data/mdl/tetopear.gsm and b/data/mdl/tetopear.gsm differ diff --git a/engine/include/GearSrc/GL.h b/engine/include/GearSrc/GL.h index 1f6a9cf..337d461 100644 --- a/engine/include/GearSrc/GL.h +++ b/engine/include/GearSrc/GL.h @@ -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); diff --git a/engine/include/GearSrc/Model.h b/engine/include/GearSrc/Model.h index 4883909..a7f3f3e 100644 --- a/engine/include/GearSrc/Model.h +++ b/engine/include/GearSrc/Model.h @@ -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 diff --git a/engine/src/client.c b/engine/src/client.c index 0b3739e..35ea400 100644 --- a/engine/src/client.c +++ b/engine/src/client.c @@ -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++; diff --git a/engine/src/gl.c b/engine/src/gl.c index 190afcb..1f46d6f 100644 --- a/engine/src/gl.c +++ b/engine/src/gl.c @@ -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); diff --git a/engine/src/model.c b/engine/src/model.c index f29cd1a..f94b888 100644 --- a/engine/src/model.c +++ b/engine/src/model.c @@ -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) { diff --git a/resource/model/crate/model.mtl b/resource/model/crate/model.mtl new file mode 100644 index 0000000..9c62152 --- /dev/null +++ b/resource/model/crate/model.mtl @@ -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 diff --git a/resource/model/crate/model.obj b/resource/model/crate/model.obj new file mode 100644 index 0000000..18e8c39 --- /dev/null +++ b/resource/model/crate/model.obj @@ -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 diff --git a/resource/model/crate/model.png b/resource/model/crate/model.png new file mode 100644 index 0000000..1ce3321 Binary files /dev/null and b/resource/model/crate/model.png differ