Skip to content
Snippets Groups Projects
Commit d196a38a authored by celeborn2bealive's avatar celeborn2bealive
Browse files

Camera: Implement default camera computation

parent 6478b622
No related branches found
No related tags found
No related merge requests found
......@@ -37,9 +37,16 @@ int ViewerApplication::run()
const auto normalMatrixLocation =
glGetUniformLocation(glslProgram.glId(), "uNormalMatrix");
tinygltf::Model model;
if (!loadGltfFile(model)) {
return -1;
}
glm::vec3 bboxMin, bboxMax;
computeSceneBounds(model, bboxMin, bboxMax);
// Build projection matrix
auto maxDistance = 500.f; // TODO use scene bounds instead to compute this
maxDistance = maxDistance > 0.f ? maxDistance : 100.f;
const auto diag = bboxMax - bboxMin;
auto maxDistance = glm::length(diag);
const auto projMatrix =
glm::perspective(70.f, float(m_nWindowWidth) / m_nWindowHeight,
0.001f * maxDistance, 1.5f * maxDistance);
......@@ -51,14 +58,11 @@ int ViewerApplication::run()
if (m_hasUserCamera) {
cameraController.setCamera(m_userCamera);
} else {
// TODO Use scene bounds to compute a better default camera
cameraController.setCamera(
Camera{glm::vec3(0, 0, 0), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0)});
}
tinygltf::Model model;
if (!loadGltfFile(model)) {
return -1;
const auto center = 0.5f * (bboxMax + bboxMin);
const auto up = glm::vec3(0, 1, 0);
const auto eye =
diag.z > 0 ? center + diag : center + 2.f * glm::cross(diag, up);
cameraController.setCamera(Camera{eye, center, up});
}
const auto bufferObjects = createBufferObjects(model);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment