From fee4cbf40b07e17eca676b4687c51313f7cfdd2e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 Feb 2021 18:37:17 -0600 Subject: Added example projects from lecture --- dev/rays/example.cc | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 dev/rays/example.cc (limited to 'dev/rays/example.cc') diff --git a/dev/rays/example.cc b/dev/rays/example.cc new file mode 100644 index 0000000..bfccb05 --- /dev/null +++ b/dev/rays/example.cc @@ -0,0 +1,80 @@ +/** CSci-4611 In-Class Example */ + +#include "example.h" + +#include "config.h" + +#include +#include + + + +Example::Example() : GraphicsApp(1024,768, "MinGfx Example") { + // Define a search path for finding data files (images and shaders) + search_path_.push_back("."); + search_path_.push_back("./data"); + search_path_.push_back(DATA_DIR_INSTALL); + search_path_.push_back(DATA_DIR_BUILD); +} + + +Example::~Example() { +} + + +void Example::UpdateSimulation(double dt) { + cam_.UpdateSimulation(dt, window()); +} + +// You can look around, like in minecraft, by dragging with the right mouse button. +void Example::OnRightMouseDrag(const Point2& mouse_in_pixels, const Vector2& delta_in_pixels) { + Vector2 delta_in_ndc = PixelsToNormalizedDeviceCoords(delta_in_pixels); + cam_.OnMouseMove(delta_in_ndc); +} + + + + +void Example::OnLeftMouseDown(const Point2& mouse_in_pixels) { + +} + +void Example::OnLeftMouseDrag(const Point2& mouse_in_pixels, const Vector2& delta_in_pixels) { + +} + +void Example::OnLeftMouseUp(const Point2& mouse_in_pixels) { + +} + + + + + + +void Example::InitOpenGL() { + // Set up the camera in a good position to see the entire scene + proj_matrix_ = Matrix4::Perspective(60.0f, aspect_ratio(), 0.01f, 100.0f); + cam_.set_view_matrix(Matrix4::LookAt(Point3(0,0,3), Point3(0,0,0), Vector3(0,1,0))); + glClearColor(1,1,1,1); + + // load textures and shaders + dart_tex_.InitFromFile(Platform::FindFile("dartboard.jpg", search_path_)); +} + + +void Example::DrawUsingOpenGL() { + Matrix4 view_matrix = cam_.view_matrix(); + + // draws a set of axes at the world origin, since we are passing the identity + // matrix for the "model" matrix. + Matrix4 identity; + quick_shapes_.DrawAxes(identity, view_matrix, proj_matrix_); + + Matrix4 boardTransform = Matrix4::RotationX(GfxMath::ToRadians(90)); + quick_shapes_.DrawSquare(boardTransform, view_matrix, proj_matrix_, Color(1, 1, 1), dart_tex_); +} + + + + -- cgit v1.2.3