diff --git a/examples/main.cpp b/examples/main.cpp index cb62320..f174bcf 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -202,6 +202,24 @@ testColoredVertices(RenderState* rs) return true; } +bool +loadCamera(RenderState* rs) +{ + Camera* cam = rs->camera; + glm::vec3 cam_pos = { 0, 15, 40 }; + glm::vec3 look_pos = { 0, 0, 0 }; + glm::vec3 up = { 0, 1, 0 }; + cameraInitPerspective(cam, cam_pos, look_pos, up); + GLBuffer* xforms_ubo = getUBOByName(rs->gl_ctx, "matrices"); + + if (!xforms_ubo) + return false; + + updateGLBuffer(xforms_ubo, &cam->xforms); + + return true; +} + bool loadScene(RenderState* rs) { @@ -214,19 +232,16 @@ loadScene(RenderState* rs) LOGF(Error, "Error loading colored vertices\n"); return false; } -#if 1 - if (!loadSpaceShip(rs)) + + if (!loadSpaceShip(rs)) { + LOGF(Error, "Error loading ship modeln"); return false; -#endif + } - // NOTE: initilize the 'camera' - glm::vec3 cam_pos = { 0, 15, 40 }; - glm::vec3 look_pos = { 0, 0, 0 }; - glm::vec3 up = { 0, 1, 0 }; - rs->xforms->view_xform = glm::lookAt(cam_pos, look_pos, up); - GLBuffer* xforms_ubo = getUBOByName(rs->gl_ctx, "matrices"); - assert(xforms_ubo); - updateGLBuffer(xforms_ubo, rs->xforms); + if (!loadCamera(rs)) { + LOGF(Error, "Error loading camera\n"); + return false; + } return loadLights(rs); } @@ -284,7 +299,7 @@ render_cb_pre(RenderState* rs) } orbitPositionZ0(&cam_pos, 0.5 * M_PI / 180); - rs->xforms->view_xform = + rs->camera->xforms.view = glm::lookAt(glm::vec3(cam_pos), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); static GLBuffer* xform_ubo = nullptr; @@ -294,7 +309,7 @@ render_cb_pre(RenderState* rs) assert(xform_ubo != nullptr); } - updateGLBuffer(xform_ubo, rs->xforms); + updateGLBuffer(xform_ubo, &rs->camera->xforms); // NOTE: rotate cubes RenderGroup* rg2 = getRenderGroupByName(rs, "textured_cubes");