summaryrefslogtreecommitdiffstats
path: root/dev/gfxtest/gfx_test.cc
diff options
context:
space:
mode:
authorRitchie <paulx161@umn.edu>2021-01-20 13:31:42 -0600
committerGitHub Enterprise <noreply-github@umn.edu>2021-01-20 13:31:42 -0600
commit9ef7449585f9e9e77516df31bcd6a90a72c20d16 (patch)
treeddecd4d13d9d9e6a0c4bc76cc45eef765567e4e3 /dev/gfxtest/gfx_test.cc
parentUpdated README.md (diff)
downloadcsci4611-9ef7449585f9e9e77516df31bcd6a90a72c20d16.tar
csci4611-9ef7449585f9e9e77516df31bcd6a90a72c20d16.tar.gz
csci4611-9ef7449585f9e9e77516df31bcd6a90a72c20d16.tar.bz2
csci4611-9ef7449585f9e9e77516df31bcd6a90a72c20d16.tar.lz
csci4611-9ef7449585f9e9e77516df31bcd6a90a72c20d16.tar.xz
csci4611-9ef7449585f9e9e77516df31bcd6a90a72c20d16.tar.zst
csci4611-9ef7449585f9e9e77516df31bcd6a90a72c20d16.zip
Added /dev/gfxtest/*
Diffstat (limited to 'dev/gfxtest/gfx_test.cc')
-rw-r--r--dev/gfxtest/gfx_test.cc72
1 files changed, 72 insertions, 0 deletions
diff --git a/dev/gfxtest/gfx_test.cc b/dev/gfxtest/gfx_test.cc
new file mode 100644
index 0000000..f96d80e
--- /dev/null
+++ b/dev/gfxtest/gfx_test.cc
@@ -0,0 +1,72 @@
+#include "gfx_test.h"
+
+#include <iostream>
+#include <sstream>
+
+GfxTest::GfxTest() : GraphicsApp(1024,768, "GfxTest"), playing_(true) {
+}
+
+
+GfxTest::~GfxTest() {
+}
+
+
+void GfxTest::InitNanoGUI() {
+ // Setup the GUI window
+ nanogui::Window *window = new nanogui::Window(screen(), "Controls");
+ window->setPosition(Eigen::Vector2i(10, 10));
+ window->setSize(Eigen::Vector2i(400,200));
+ window->setLayout(new nanogui::GroupLayout());
+
+ pauseBtn_ = new nanogui::Button(window, "Pause");
+ pauseBtn_->setCallback(std::bind(&GfxTest::OnPauseBtnPressed, this));
+ pauseBtn_->setTooltip("Toggle playback.");
+
+ screen()->performLayout();
+}
+
+
+
+void GfxTest::OnPauseBtnPressed() {
+ playing_ = !playing_;
+ if (playing_) {
+ pauseBtn_->setCaption("Pause");
+ }
+ else {
+ pauseBtn_->setCaption("Play");
+ }
+}
+
+
+void GfxTest::UpdateSimulation(double dt) {
+ static const float radians_per_sec = GfxMath::ToRadians(25.0);
+ if (playing_) {
+ rot_matrix_ = rot_matrix_ * Matrix4::RotationY((float)dt * radians_per_sec);
+ }
+}
+
+
+void GfxTest::InitOpenGL() {
+ // Set up the camera in a good position to see the entire field
+ proj_matrix_ = Matrix4::Perspective(60.0f, aspect_ratio(), 0.01f, 100.0f);
+ view_matrix_ = Matrix4::LookAt(Point3(0,0,4), Point3(0,0,0), Vector3(0,1,0));
+ glClearColor(0.0, 0.0, 0.0, 1);
+
+ teapot_.LoadFromOBJ(Platform::FindMinGfxDataFile("teapot.obj"));
+ shader_.Init();
+}
+
+
+void GfxTest::DrawUsingOpenGL() {
+ for (int r=-2; r<3; r++) {
+ for (int c=-2; c<3; c++) {
+ Matrix4 model_matrix = Matrix4::Translation(Vector3((float)r, (float)c, 0.0f)) * rot_matrix_;
+ shader_.Draw(model_matrix, view_matrix_, proj_matrix_, &teapot_, DefaultShader::MaterialProperties());
+ }
+ }
+}
+
+
+
+
+