Skip to content

Commit

Permalink
handle exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
z3moon committed Sep 6, 2024
1 parent fa85afe commit be61308
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions samples/hellostereo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) {
try {
eyeCount = std::stoi(arg);
} catch (std::invalid_argument &e) { }
if (eyeCount >= 1 && eyeCount <= CONFIG_MAX_STEREOSCOPIC_EYES) {
if (eyeCount >= 2 && eyeCount <= CONFIG_MAX_STEREOSCOPIC_EYES) {
app->config.stereoscopicEyeCount = eyeCount;
} else {
std::cerr << "Eye count must be between 1 and CONFIG_MAX_STEREOSCOPIC_EYES ("
std::cerr << "Eye count must be between 2 and CONFIG_MAX_STEREOSCOPIC_EYES ("
<< (int)CONFIG_MAX_STEREOSCOPIC_EYES << ") (inclusive).\n";
exit(1);
}
break;
}
Expand Down Expand Up @@ -234,17 +235,21 @@ int main(int argc, char** argv) {
constexpr double projFar = 100;

mat4 projections[CONFIG_MAX_STEREOSCOPIC_EYES];
static_assert(CONFIG_MAX_STEREOSCOPIC_EYES == 4, "Update projections");
mat4 eyeModels[CONFIG_MAX_STEREOSCOPIC_EYES];
static_assert(CONFIG_MAX_STEREOSCOPIC_EYES == 4, "Update matrices");
projections[0] = Camera::projection(24, 1.0, projNear, projFar);
projections[1] = Camera::projection(70, 1.0, projNear, projFar);
projections[2] = Camera::projection(50, 1.0, projNear, projFar);
projections[3] = Camera::projection(35, 1.0, projNear, projFar);
app.stereoCamera->setCustomEyeProjection(projections, 4, projections[0], projNear, projFar);

app.stereoCamera->setEyeModelMatrix(0, mat4::lookAt(float3{-4, 0, 0}, monkeyPosition, upVector));
app.stereoCamera->setEyeModelMatrix(1, mat4::lookAt(float3{4, 0, 0}, monkeyPosition, upVector));
app.stereoCamera->setEyeModelMatrix(2, mat4::lookAt(float3{0, 3, 0}, monkeyPosition, upVector));
app.stereoCamera->setEyeModelMatrix(3, mat4::lookAt(float3{0, -3, 0}, monkeyPosition, upVector));
eyeModels[0] = mat4::lookAt(float3{ -4, 0, 0 }, monkeyPosition, upVector);
eyeModels[1] = mat4::lookAt(float3{ 4, 0, 0 }, monkeyPosition, upVector);
eyeModels[2] = mat4::lookAt(float3{ 0, 3, 0 }, monkeyPosition, upVector);
eyeModels[3] = mat4::lookAt(float3{ 0, -3, 0 }, monkeyPosition, upVector);
for (int i = 0; i < eyeCount; ++i) {
app.stereoCamera->setEyeModelMatrix(i, eyeModels[i]);
}

// Create a vertex buffer and an index buffer for a quad. This will be used to display the contents
// of each layer of the stereo texture.
Expand Down

0 comments on commit be61308

Please sign in to comment.