diff options
author | unknown <paulx161@umn.edu> | 2021-02-03 14:22:28 -0600 |
---|---|---|
committer | unknown <paulx161@umn.edu> | 2021-02-03 14:22:28 -0600 |
commit | 9b83919815f6a6ce5d73da1c28483970d0ca5589 (patch) | |
tree | 4558864445dccc1605e5315e0bb11c46d2018da1 /dev/MinGfx/example/CircleViewer.cpp | |
parent | Added worksheet and support code for assignment 2 (diff) | |
download | csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.gz csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.bz2 csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.lz csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.xz csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.tar.zst csci4611-9b83919815f6a6ce5d73da1c28483970d0ca5589.zip |
added dev/MinGfx/
Diffstat (limited to 'dev/MinGfx/example/CircleViewer.cpp')
-rw-r--r-- | dev/MinGfx/example/CircleViewer.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/dev/MinGfx/example/CircleViewer.cpp b/dev/MinGfx/example/CircleViewer.cpp new file mode 100644 index 0000000..9bf50b9 --- /dev/null +++ b/dev/MinGfx/example/CircleViewer.cpp @@ -0,0 +1,122 @@ + +#include "CircleViewer.h" + +#include <nanogui/nanogui.h> +#include <iostream> + + +CircleViewer::CircleViewer() : GraphicsApp(1024,768, "Circle Simulation") { + simTime_ = 0.0; + paused_ = false; + + //InitGraphicsContext(); +} + + +CircleViewer::~CircleViewer() { + +} + +void CircleViewer::InitNanoGUI() { + nanogui::FormHelper *gui = new nanogui::FormHelper(screen()); + nanogui::ref<nanogui::Window> window = gui->addWindow(Eigen::Vector2i(10, 10), "Simulation Controls"); + pauseBtn_ = gui->addButton("Pause", std::bind(&CircleViewer::OnPauseBtnPressed, this)); + gui->addButton("Restart", std::bind(&CircleViewer::OnRestartBtnPressed, this)); + + screen()->performLayout(); +} + +void CircleViewer::UpdateSimulation(double dt) { + if (!paused_) { + simTime_ += dt; + std::cout << "Update Simulation " << simTime_ << std::endl; + } +} + + +void CircleViewer::OnRestartBtnPressed() { + simTime_ = 0.0; +} + +void CircleViewer::OnPauseBtnPressed() { + paused_ = !paused_; + if (paused_) { + pauseBtn_->setCaption("Play"); + } + else { + pauseBtn_->setCaption("Pause"); + } +} + + +void CircleViewer::OnMouseMove(const Point2 &pos, const Vector2 &delta) { + std::cout << "Mouse moved by " << delta << " to reach " << pos << std::endl; +} + + +void CircleViewer::OnLeftMouseDown(const Point2 &pos) { + std::cout << "Left mouse button DOWN at " << pos << std::endl; +} + +void CircleViewer::OnLeftMouseDrag(const Point2 &pos, const Vector2 &delta) { + std::cout << "Mouse dragged (left button) by " << delta << " to reach " << pos << std::endl; +} + +void CircleViewer::OnLeftMouseUp(const Point2 &pos) { + std::cout << "Left mouse button UP at " << pos << std::endl; +} + + +void CircleViewer::OnRightMouseDown(const Point2 &pos) { + std::cout << "Right mouse button DOWN at " << pos << std::endl; +} + +void CircleViewer::OnRightMouseDrag(const Point2 &pos, const Vector2 &delta) { + std::cout << "Mouse dragged (right button) by " << delta << " to reach " << pos << std::endl; +} + +void CircleViewer::OnRightMouseUp(const Point2 &pos) { + std::cout << "Right mouse button UP at " << pos << std::endl; +} + + +void CircleViewer::OnKeyDown(const char *c, int modifiers) { + std::cout << "Key DOWN (" << c << ") modifiers=" << modifiers << std::endl; +} + +void CircleViewer::OnKeyUp(const char *c, int modifiers) { + std::cout << "Key UP (" << c << ") modifiers=" << modifiers << std::endl; +} + + +void CircleViewer::OnSpecialKeyDown(int key, int scancode, int modifiers) { + std::cout << "Special Key DOWN key=" << key << " scancode=" << scancode << " modifiers=" << modifiers << std::endl; +} + +void CircleViewer::OnSpecialKeyUp(int key, int scancode, int modifiers) { + std::cout << "Special Key UP key=" << key << " scancode=" << scancode << " modifiers=" << modifiers << std::endl; +} + + +void CircleViewer::DrawUsingNanoVG(NVGcontext *ctx) { + // example of drawing some circles + + nvgBeginPath(ctx); + nvgCircle(ctx, 512+50.0*cos(simTime_), 350+200.0*sin(simTime_), 50); + nvgFillColor(ctx, nvgRGBA(100,100,255,200)); + nvgFill(ctx); + nvgStrokeColor(ctx, nvgRGBA(0,0,0,255)); + nvgStroke(ctx); + + nvgBeginPath(ctx); + nvgCircle(ctx, 512+200.0*cos(simTime_), 350+50.0*sin(simTime_), 50); + nvgFillColor(ctx, nvgRGBA(255,100,100,200)); + nvgFill(ctx); + nvgStrokeColor(ctx, nvgRGBA(0,0,0,255)); + nvgStroke(ctx); +} + +void CircleViewer::DrawUsingOpenGL() { + +} + |