5 changed files with 81 additions and 62 deletions
@ -0,0 +1,46 @@ |
|||||||
|
|
||||||
|
#include <glm/gtc/matrix_transform.hpp> |
||||||
|
|
||||||
|
#include "entity.h" |
||||||
|
|
||||||
|
|
||||||
|
bool |
||||||
|
initEntity(Entity* e, |
||||||
|
MemoryArena* arena, |
||||||
|
model* mdl, |
||||||
|
u32 num_attrib_mappings, |
||||||
|
GLBufferToAttribMapping* attrib_mappings, |
||||||
|
const char* name) |
||||||
|
{ |
||||||
|
e->num_meshes = mdl->num_meshes; |
||||||
|
e->meshes = ARENA_ALLOC(arena, GLmesh, e->num_meshes); |
||||||
|
e->xform = ARENA_ALLOC(arena, glm::mat4, 1); |
||||||
|
*e->xform = glm::mat4(1.f); |
||||||
|
e->name = arenaCopyCStr(arena, name); |
||||||
|
|
||||||
|
for (u32 i = 0; i< e->num_meshes; i++) { |
||||||
|
GLmesh* glm = &e->meshes[i]; |
||||||
|
*glm = loadGLMesh(mdl->meshes[i], GL_TRIANGLES, glm::vec3(0, 0, 0), |
||||||
|
num_attrib_mappings, attrib_mappings); |
||||||
|
|
||||||
|
if (glm->vao_id == 0) { |
||||||
|
printf("%s(), error initializing entity\n", __FUNCTION__); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
setEntityPosition(Entity* e, glm::vec3 pos) |
||||||
|
{ |
||||||
|
*e->xform = glm::translate(*e->xform, pos); |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
rotateEntity(Entity* e, glm::vec3 axis, float radians) |
||||||
|
{ |
||||||
|
*e->xform = glm::rotate(*e->xform, radians, axis); |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,30 @@ |
|||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "asset.h" |
||||||
|
#include "shader.h" |
||||||
|
#include "types.h" |
||||||
|
#include "util.h" |
||||||
|
|
||||||
|
|
||||||
|
struct Entity |
||||||
|
{ |
||||||
|
u32 num_meshes; |
||||||
|
GLmesh* meshes; |
||||||
|
GLTexture* diffuse_texture; // NOTE: pointer into gl_ctx->textures array
|
||||||
|
glm::mat4* xform; |
||||||
|
char* name; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
bool initEntity(Entity* e, |
||||||
|
MemoryArena* arena, |
||||||
|
model* mdl, |
||||||
|
u32 num_attrib_mappings, |
||||||
|
GLBufferToAttribMapping* attrib_mappings, |
||||||
|
const char* name = ""); |
||||||
|
|
||||||
|
void setEntityPosition(Entity* e, glm::vec3 pos); |
||||||
|
|
||||||
|
void rotateEntity(Entity* e, glm::vec3 axis, float radians); |
||||||
|
|
||||||
Loading…
Reference in new issue