/
Zamar_Terrier
/
TigorEngineWeb
Обзор
Документация
Войти
/
Zamar_Terrier
/
TigorEngineWeb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/models.c
139 строк
4 KB
Ilia Zamaruev
Adding obj loader
30 окт 2025, 16:46
30 окт 2025, 16:46
3de2761
Код
Авторство
О чём код?
#include "models.h" #include "gameObject.h" #include "e_math.h" #include "e_vertex.h" #include "e_memory.h" #include "e_camera.h" #include "e_texture.h" #include "math.h" #include "objLoader.h" extern TEngine engine; void ModelDefaultDraw(ModelObject3D* mo, void *command){ for(int i=0; i < mo->num_draw_nodes;i++){ for(int j=0; j < mo->nodes[i].num_models; j++){ GameObject3D *model = &mo->nodes[i].models[j]; GameObjectDraw((GameObject *)model); } } } void ModelUpdateModel(ModelObject3D *mo, GameObject3D *model, uint32_t model_indx){ Camera3D* cam = (Camera3D*) engine.cam3D; vec3 cameraUp = {0.0f, 1.0f, 0.0f}; // draw our first triangle glUseProgram(model->self.shaderProgram); mat4 model_m = m4_transform(mo->transform.position, mo->transform.scale, mo->transform.rotation); unsigned int tMat = glGetUniformLocation(model->self.shaderProgram, "u_model"); glUniformMatrix4fv(tMat, 1, GL_FALSE, (const float*) &model_m); mat4 view = m4_look_at(cam->position, v3_add(cam->position, cam->rotation), cameraUp); tMat = glGetUniformLocation(model->self.shaderProgram, "u_view"); glUniformMatrix4fv(tMat, 1, GL_FALSE, (const float*) &view); mat4 proj = m4_perspective(engine.width, engine.height, cam->view_angle, cam->view_near, cam->view_distance); tMat = glGetUniformLocation(model->self.shaderProgram, "u_proj"); glUniformMatrix4fv(tMat, 1, GL_FALSE, (const float*) &proj); } void ModelDefaultUpdate(ModelObject3D *mo) { Camera3D* cam = (Camera3D*) engine.cam3D; for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { GameObject3D *model = &mo->nodes[i].models[j]; ModelUpdateModel(mo, model, i); } } } void ModelClean(ModelObject3D* mo){ for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { GameObject3D *model = &mo->nodes[i].models[j]; GameObjectClean((GameObject *)model); } } } void ModelRecreate(ModelObject3D* mo){ for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { GameObject3D *model = &mo->nodes[i].models[j]; GameObjectRecreate((GameObject *)model); } } } void ModelNextFrame(ModelObject3D *mo, double time, int num_animation){ /*if(mo->type == TIGOR_MODEL_TYPE_FBX) Load3DFBXNextFrame(mo, time, num_animation); else if(mo->type == TIGOR_MODEL_TYPE_GLTF) Load3DglTFNextFrame(mo, time, num_animation);*/ } void ModelDestroy(ModelObject3D* mo){ for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { GameObject3D *model = &mo->nodes[i].models[j]; GameObjectDestroy((GameObject *)model); } } } void ModelPopulateVertex3D(GameObject3D *model) { uint32_t num = model->graphObj.num_shapes; ModelVertex3D *m_verts = model->graphObj.shapes[0].vParam.vertices; uint32_t count = model->graphObj.shapes[0].vParam.count; Vertex3D *verts = AllocateMemory(count, sizeof(Vertex3D)); for(int i=0;i < count;i++) { verts[i].position = m_verts[i].position; verts[i].normal = m_verts[i].normal; verts[i].texCoord = m_verts[i].texCoord; } GraphicsObjectSetVertex(&model->graphObj, verts, count, model->graphObj.shapes[0].iParam.indices, model->graphObj.shapes[0].iParam.count, TIGOR_VERTEX_TYPE_3D_OBJECT); } void ModelDefaultInit(ModelObject3D *mo, GameObjectType type){ for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0; j < mo->nodes[i].num_models;j++) { GameObjectInit((GameObject *)&mo->nodes[i].models[j]); } } mo->self.flags |= TIGOR_GAME_OBJECT_FLAG_INIT; }