Browse Source

update example application with camera changes

remotes/bxxa/master
cinnaboot 4 years ago
parent
commit
3ee554287b
  1. 41
      examples/main.cpp

41
examples/main.cpp

@ -202,6 +202,24 @@ testColoredVertices(RenderState* rs)
return true; 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 bool
loadScene(RenderState* rs) loadScene(RenderState* rs)
{ {
@ -214,19 +232,16 @@ loadScene(RenderState* rs)
LOGF(Error, "Error loading colored vertices\n"); LOGF(Error, "Error loading colored vertices\n");
return false; return false;
} }
#if 1
if (!loadSpaceShip(rs)) if (!loadSpaceShip(rs)) {
LOGF(Error, "Error loading ship modeln");
return false; return false;
#endif }
// NOTE: initilize the 'camera' if (!loadCamera(rs)) {
glm::vec3 cam_pos = { 0, 15, 40 }; LOGF(Error, "Error loading camera\n");
glm::vec3 look_pos = { 0, 0, 0 }; return false;
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);
return loadLights(rs); return loadLights(rs);
} }
@ -284,7 +299,7 @@ render_cb_pre(RenderState* rs)
} }
orbitPositionZ0(&cam_pos, 0.5 * M_PI / 180); 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)); glm::lookAt(glm::vec3(cam_pos), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
static GLBuffer* xform_ubo = nullptr; static GLBuffer* xform_ubo = nullptr;
@ -294,7 +309,7 @@ render_cb_pre(RenderState* rs)
assert(xform_ubo != nullptr); assert(xform_ubo != nullptr);
} }
updateGLBuffer(xform_ubo, rs->xforms); updateGLBuffer(xform_ubo, &rs->camera->xforms);
// NOTE: rotate cubes // NOTE: rotate cubes
RenderGroup* rg2 = getRenderGroupByName(rs, "textured_cubes"); RenderGroup* rg2 = getRenderGroupByName(rs, "textured_cubes");

Loading…
Cancel
Save