summaryrefslogtreecommitdiffstats
path: root/dev/a2-carsoccer/car_soccer.cc
diff options
context:
space:
mode:
authorunknown <paulx161@umn.edu>2021-02-02 18:35:09 -0600
committerunknown <paulx161@umn.edu>2021-02-02 18:35:09 -0600
commit7ea1b2c0320d74152d33e74718a39319a7a0e507 (patch)
tree7c2995f547889f00e381449b5c91dbb0abd1a0c3 /dev/a2-carsoccer/car_soccer.cc
parentAdded /dev/gfxtest/* (diff)
downloadcsci4611-7ea1b2c0320d74152d33e74718a39319a7a0e507.tar
csci4611-7ea1b2c0320d74152d33e74718a39319a7a0e507.tar.gz
csci4611-7ea1b2c0320d74152d33e74718a39319a7a0e507.tar.bz2
csci4611-7ea1b2c0320d74152d33e74718a39319a7a0e507.tar.lz
csci4611-7ea1b2c0320d74152d33e74718a39319a7a0e507.tar.xz
csci4611-7ea1b2c0320d74152d33e74718a39319a7a0e507.tar.zst
csci4611-7ea1b2c0320d74152d33e74718a39319a7a0e507.zip
Added worksheet and support code for assignment 2
Diffstat (limited to 'dev/a2-carsoccer/car_soccer.cc')
-rw-r--r--dev/a2-carsoccer/car_soccer.cc104
1 files changed, 104 insertions, 0 deletions
diff --git a/dev/a2-carsoccer/car_soccer.cc b/dev/a2-carsoccer/car_soccer.cc
new file mode 100644
index 0000000..a9cea69
--- /dev/null
+++ b/dev/a2-carsoccer/car_soccer.cc
@@ -0,0 +1,104 @@
+/** CSci-4611 Assignment 2: Car Soccer
+ */
+
+#include "car_soccer.h"
+#include "config.h"
+
+
+CarSoccer::CarSoccer() : GraphicsApp(1024,768, "Car Soccer") {
+ // Define a search path for finding data files (images and shaders)
+ searchPath_.push_back(".");
+ searchPath_.push_back("./data");
+ searchPath_.push_back(DATA_DIR_INSTALL);
+ searchPath_.push_back(DATA_DIR_BUILD);
+}
+
+CarSoccer::~CarSoccer() {
+}
+
+
+Vector2 CarSoccer::joystick_direction() {
+ Vector2 dir;
+ if (IsKeyDown(GLFW_KEY_LEFT))
+ dir[0]--;
+ if (IsKeyDown(GLFW_KEY_RIGHT))
+ dir[0]++;
+ if (IsKeyDown(GLFW_KEY_UP))
+ dir[1]++;
+ if (IsKeyDown(GLFW_KEY_DOWN))
+ dir[1]--;
+ return dir;
+}
+
+
+void CarSoccer::OnSpecialKeyDown(int key, int scancode, int modifiers) {
+ if (key == GLFW_KEY_SPACE) {
+ // Here's where you could call some form of launch_ball();
+ }
+}
+
+
+void CarSoccer::UpdateSimulation(double timeStep) {
+ // Here's where you shound do your "simulation", updating the positions of the
+ // car and ball as needed and checking for collisions. Filling this routine
+ // in is the main part of the assignment.
+
+}
+
+
+void CarSoccer::InitOpenGL() {
+ // Set up the camera in a good position to see the entire field
+ projMatrix_ = Matrix4::Perspective(60, aspect_ratio(), 1, 1000);
+ modelMatrix_ = Matrix4::LookAt(Point3(0,60,70), Point3(0,0,10), Vector3(0,1,0));
+
+ // Set a background color for the screen
+ glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
+
+ // Load some image files we'll use
+ fieldTex_.InitFromFile(Platform::FindFile("pitch.png", searchPath_));
+ crowdTex_.InitFromFile(Platform::FindFile("crowd.png", searchPath_));
+}
+
+
+void CarSoccer::DrawUsingOpenGL() {
+ // Draw the crowd as a fullscreen background image
+ quickShapes_.DrawFullscreenTexture(Color(1,1,1), crowdTex_);
+
+ // Draw the field with the field texture on it.
+ Color col(16.0f/255.0f, 46.0f/255.0f, 9.0f/255.0f);
+ Matrix4 M = Matrix4::Translation(Vector3(0.0f, -0.201f, 0.0f)) * Matrix4::Scale(Vector3(50.0f, 1.0f, 60.0f));
+ quickShapes_.DrawSquare(modelMatrix_ * M, viewMatrix_, projMatrix_, col);
+ M = Matrix4::Translation(Vector3(0.0f, -0.2f, 0.0f)) * Matrix4::Scale(Vector3(40.0f, 1.0f, 50.0f));
+ quickShapes_.DrawSquare(modelMatrix_ * M, viewMatrix_, projMatrix_, Color(1,1,1), fieldTex_);
+
+ // Draw the car
+ Color carcol(0.8f, 0.2f, 0.2f);
+ Matrix4 Mcar =
+ Matrix4::Translation(car_.position() - Point3(0,0,0)) *
+ Matrix4::Scale(car_.size()) *
+ Matrix4::Scale(Vector3(0.5f, 0.5f, 0.5f));
+ quickShapes_.DrawCube(modelMatrix_ * Mcar, viewMatrix_, projMatrix_, carcol);
+
+
+ // Draw the ball
+ Color ballcol(1,1,1);
+ Matrix4 Mball =
+ Matrix4::Translation(ball_.position() - Point3(0,0,0)) *
+ Matrix4::Scale(Vector3(ball_.radius(), ball_.radius(), ball_.radius()));
+ quickShapes_.DrawSphere(modelMatrix_ * Mball, viewMatrix_, projMatrix_, ballcol);
+
+
+ // Draw the ball's shadow -- this is a bit of a hack, scaling Y by zero
+ // flattens the sphere into a pancake, which we then draw just a bit
+ // above the ground plane.
+ Color shadowcol(0.2f, 0.4f, 0.15f);
+ Matrix4 Mshadow =
+ Matrix4::Translation(Vector3(ball_.position()[0], -0.1f, ball_.position()[2])) *
+ Matrix4::Scale(Vector3(ball_.radius(), 0, ball_.radius())) *
+ Matrix4::RotationX(90);
+ quickShapes_.DrawSphere(modelMatrix_ * Mshadow, viewMatrix_, projMatrix_, shadowcol);
+
+
+ // You should add drawing the goals and the boundary of the playing area
+ // using quickShapes_.DrawLines()
+}