From 1b2546a99a266662b5c4b9c985a5257c211ecea7 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Mon, 4 Oct 2021 21:38:36 -0500 Subject: Do a2 --- dev/a2-carsoccer/ball.cc | 2 +- dev/a2-carsoccer/ball.h | 1 + dev/a2-carsoccer/car.cc | 3 + dev/a2-carsoccer/car_soccer.cc | 157 ++++++++++++++++++++++++++++++++++++++--- 4 files changed, 151 insertions(+), 12 deletions(-) diff --git a/dev/a2-carsoccer/ball.cc b/dev/a2-carsoccer/ball.cc index 10c70df..9e41447 100644 --- a/dev/a2-carsoccer/ball.cc +++ b/dev/a2-carsoccer/ball.cc @@ -7,7 +7,7 @@ Ball::Ball() : radius_(2.6f) { } Ball::~Ball() { - + Reset(); } diff --git a/dev/a2-carsoccer/ball.h b/dev/a2-carsoccer/ball.h index a43eb31..77344eb 100644 --- a/dev/a2-carsoccer/ball.h +++ b/dev/a2-carsoccer/ball.h @@ -27,6 +27,7 @@ public: // Resets the ball's position and velocity to initial values. void Reset(); + void Draw(QuickShapes quickShapes, Matrix4 modelMatrix, Matrix4 viewMatrix, Matrix4 projMatrix); diff --git a/dev/a2-carsoccer/car.cc b/dev/a2-carsoccer/car.cc index 4b27cfe..ae1a857 100644 --- a/dev/a2-carsoccer/car.cc +++ b/dev/a2-carsoccer/car.cc @@ -8,6 +8,7 @@ Car::Car() : size_(3,2,4), collision_radius_(2.5) { } Car::~Car() { + } @@ -41,6 +42,8 @@ float Car::speed() { } void Car::set_speed(float s) { + if (s > 50) + s = 50; speed_ = s; } diff --git a/dev/a2-carsoccer/car_soccer.cc b/dev/a2-carsoccer/car_soccer.cc index 9fac102..c4de304 100644 --- a/dev/a2-carsoccer/car_soccer.cc +++ b/dev/a2-carsoccer/car_soccer.cc @@ -85,17 +85,99 @@ Vector2 CarSoccer::joystick_direction() { // dt is for "Delta Time", the elapsed time in seconds since the last frame void CarSoccer::UpdateSimulation(double dt) { Vector2 dpad_dir = joystick_direction(); - std::cout << "D-Pad Direction: " << dpad_dir << std::endl; + //std::cout << "D-Pad Direction: " << dpad_dir << std::endl; // Here's where you shound do your "simulation", updating the positions of the // car and ball based on the elapsed time and checking for collisions. Filling // in this routine is the main part of the assignment. - // Example: This is not the "correct way" to drive the car, but this code - // will at least move the car around for testing - float metersPerSec = 10.0f; - car_.set_position(car_.position() + metersPerSec * Vector3(dpad_dir[0], 0, -dpad_dir[1]) * dt); - + /* Ball Routines */ + // ball collision with car + if ((ball_.position() - car_.position()).Length() <= ball_.radius() + car_.collision_radius()) { + Vector3 normal = (ball_.position() - car_.position()).ToUnit(); + // collision displacement + while ((car_.position() - ball_.position()).Length() < ball_.radius() + car_.collision_radius()) { + ball_.set_position(ball_.position() + normal * 0.1); + } + // bounce backwards + Vector3 carBounce = ball_.velocity() - car_.velocity(); + ball_.set_velocity(0.8 * (car_.velocity() + carBounce - 2 * (carBounce.Dot(normal) * normal))); + } + // ball collision with various things + // there's probably a way to do this with less boilerplate but it works + if (ball_.position().y() - ball_.radius() <= 0) { + // ground + ball_.set_position(Point3(ball_.position().x(), ball_.radius(), ball_.position().z())); + ball_.set_velocity(0.8 * (ball_.velocity() - 2 * (ball_.velocity().Dot(Vector3(0, 1, 0)) * Vector3(0, 1, 0)))); + } + if (ball_.position().y() - ball_.radius() >= 35) { + // ceiling + ball_.set_position(Point3(ball_.position().x(), 35-ball_.radius(), ball_.position().z())); + ball_.set_velocity(0.8*(ball_.velocity() - 2 * (ball_.velocity().Dot(Vector3(0, -1, 0)) * Vector3(0, -1, 0)))); + } + if (ball_.position().z() + ball_.radius() >= 50) { + // home + ball_.set_position(Point3(ball_.position().x(), ball_.position().y(),50 - ball_.radius())); + ball_.set_velocity(0.8 * (ball_.velocity() - 2 * (ball_.velocity().Dot(Vector3(0, 0, -1)) * Vector3(0, 0, -1)))); + } + if (ball_.position().z() + ball_.radius() <= -50) { + // away + ball_.set_position(Point3(ball_.position().x(), ball_.position().y(), ball_.radius() - 50)); + ball_.set_velocity(0.8 * (ball_.velocity() - 2 * (ball_.velocity().Dot(Vector3(0, 0, 1)) * Vector3(0, 0, 1)))); + } + if (ball_.position().x() + ball_.radius() <= -40) { + // left + ball_.set_position(Point3(ball_.radius() - 40, ball_.position().y(), ball_.position().z())); + ball_.set_velocity(0.8 * (ball_.velocity() - 2 * (ball_.velocity().Dot(Vector3(1, 0, 0)) * Vector3(1, 0, 0)))); + } + if (ball_.position().x() + ball_.radius() >= 40) { + // right + ball_.set_position(Point3(40 - ball_.radius(), ball_.position().y(), ball_.position().z())); + ball_.set_velocity(0.8 * (ball_.velocity() - 2 * (ball_.velocity().Dot(Vector3(-1, 0, 0)) * Vector3(-1, 0, 0)))); + } + // ball gravity + Vector3 gravity = 30 * Vector3(0, -1, 0); + ball_.set_velocity(ball_.velocity() + gravity * dt); + ball_.set_position(ball_.position() + dt * ball_.velocity()); + + /* Car Routines */ + car_.set_speed(car_.speed() + 20.0f * dt); + car_.set_forward(Vector3(dpad_dir[0], 0, -dpad_dir[1])); + car_.set_position(car_.position() + car_.speed() * Vector3(dpad_dir[0], 0, -dpad_dir[1]) * dt); + if (car_.position().z() + car_.collision_radius() >= 50) { + // home + car_.set_position(Point3(car_.position().x(), car_.position().y(), 50 - car_.collision_radius())); + } + if (car_.position().z() + car_.collision_radius() <= -50) { + // away + car_.set_position(Point3(car_.position().x(), car_.position().y(), car_.collision_radius() - 50)); + } + if (car_.position().x() + car_.collision_radius() <= -40) { + // left + std::cout << "left collide" << std::endl; + car_.set_position(Point3(car_.collision_radius() - 40, car_.position().y(), car_.position().z())); + } + if (car_.position().x() + car_.collision_radius() >= 40) { + // right + car_.set_position(Point3(40 - car_.collision_radius(), car_.position().y(), car_.position().z())); + } + + /* Goal Routines */ + if (ball_.position().x() + ball_.radius() >= -20 && ball_.position().x() + ball_.radius() <= 20 + && ball_.position().y() - ball_.radius() >= 0 && ball_.position().y() - ball_.radius() <= 10 + && ball_.position().z() + ball_.radius() >= 50) { + //Goal scenario: home + ball_.Reset(); + car_.Reset(); + } + if (ball_.position().x() + ball_.radius() >= -20 && ball_.position().x() + ball_.radius() <= 20 + && ball_.position().y() - ball_.radius() >= 0 && ball_.position().y() - ball_.radius() <= 10 + && ball_.position().z() + ball_.radius() <= -50) { + //Goal scenario: away + ball_.Reset(); + car_.Reset(); + } + } @@ -115,20 +197,73 @@ void CarSoccer::InitOpenGL() { void CarSoccer::DrawUsingOpenGL() { // Draw the crowd as a fullscreen background image - quickShapes_.DrawFullscreenTexture(Color(1,1,1), crowdTex_); + quickShapes_.DrawFullscreenTexture(Color(1, 1, 1), crowdTex_); // Draw the car and the ball car_.Draw(quickShapes_, modelMatrix_, viewMatrix_, projMatrix_); ball_.Draw(quickShapes_, modelMatrix_, viewMatrix_, projMatrix_); - + // Draw the field with the field texture on it. - Color col(16.0f/255.0f, 46.0f/255.0f, 9.0f/255.0f); + 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_); - + quickShapes_.DrawSquare(modelMatrix_ * M, viewMatrix_, projMatrix_, Color(1, 1, 1), fieldTex_); + // You should add drawing the goals and the boundary of the playing area // using quickShapes_.DrawLines() + + // Bounding box + std::vector line; + line.push_back(Point3(1.0, 0.0, 1.0)); line.push_back(Point3(1.0, 35.0, 1.0)); + line.push_back(Point3(-1.0, 0.0, -1.0)); line.push_back(Point3(-1.0, 35.0, -1.0)); + line.push_back(Point3(-1.0, 0.0, 1.0)); line.push_back(Point3(-1.0, 35.0, 1.0)); + line.push_back(Point3(1.0, 0.0, -1.0)); line.push_back(Point3(1.0, 35.0, -1.0)); + line.push_back(Point3(-1.0, 35.0, 1.0)); line.push_back(Point3(1.0, 35.0, 1.0)); + line.push_back(Point3(1.0, 35.0, 1.0)); line.push_back(Point3(1.0, 35.0, -1.0)); + line.push_back(Point3(1.0, 35.0, -1.0)); line.push_back(Point3(-1.0, 35.0, -1.0)); + line.push_back(Point3(-1.0, 35.0, -1.0)); line.push_back(Point3(-1.0, 35.0, 1.0)); + quickShapes_.DrawLines(modelMatrix_ * M, viewMatrix_, projMatrix_, Color(1, 1, 1, 0.1), line, QuickShapes::LinesType::LINES, 0.001); + + // Away Goal + std::vector awayBounds; + awayBounds.push_back(Point3(20.0 / 80.0, 0.0, -1)); + awayBounds.push_back(Point3(20.0 / 80.0, 10.0, -1)); + awayBounds.push_back(Point3(-20.0 / 80.0, 10.0, -1)); + awayBounds.push_back(Point3(-20.0 / 80.0, 0.0, -1)); + quickShapes_.DrawLines(modelMatrix_ * M, viewMatrix_, projMatrix_, Color(0, 0, 1), awayBounds, QuickShapes::LinesType::LINE_LOOP, .01); + + std::vector awayGrid; + for (int i = 0; i < 10; i++) { + //Vertial grid + awayGrid.push_back(Point3(-20.0 / 80.0 + i / 20.0, 0.0, -1)); + awayGrid.push_back(Point3(-20.0 / 80.0 + i / 20.0, 10.0, -1)); + } + for (int j = 0; j < 10; j++) { + //Horz grid + awayGrid.push_back(Point3(-20.0 / 80.0, j, -1)); + awayGrid.push_back(Point3(20.0 / 80.0, j, -1)); + } quickShapes_.DrawLines(modelMatrix_ * M, viewMatrix_, projMatrix_, Color(0, 0, 1, 0.2), awayGrid, QuickShapes::LinesType::LINES, .003); + + + // Home Goal + std::vector homeBounds; + homeBounds.push_back(Point3(20.0 / 80.0, 0.0, 1)); + homeBounds.push_back(Point3(20.0 / 80.0, 10.0, 1)); + homeBounds.push_back(Point3(-20.0 / 80.0, 10.0, 1)); + homeBounds.push_back(Point3(-20.0 / 80.0, 0.0, 1)); + quickShapes_.DrawLines(modelMatrix_ * M, viewMatrix_, projMatrix_, Color(1, 0, 0), homeBounds, QuickShapes::LinesType::LINE_LOOP, .01); + std::vector homeGrid; + for (int i = 0; i < 10; i++) { + //Vertial grid + homeGrid.push_back(Point3(-20.0 / 80.0 + i / 20.0, 0.0, 1)); + homeGrid.push_back(Point3(-20.0 / 80.0 + i / 20.0, 10.0, 1)); + } + for (int j = 0; j < 10; j++) { + //Horz grid + homeGrid.push_back(Point3(-20.0 / 80.0, j, 1)); + homeGrid.push_back(Point3(20.0 / 80.0, j, 1)); + } quickShapes_.DrawLines(modelMatrix_ * M, viewMatrix_, projMatrix_, Color(1, 0, 0, 0.2), homeGrid, QuickShapes::LinesType::LINES, .003); + } -- cgit v1.2.3 From ea12bd0d8e956299682b4270de46f6c8ba7df364 Mon Sep 17 00:00:00 2001 From: dfk Date: Tue, 5 Oct 2021 09:36:08 -0500 Subject: Pushed feedback file submission-w2.0 --- grades/submission-w2.0.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 grades/submission-w2.0.md diff --git a/grades/submission-w2.0.md b/grades/submission-w2.0.md new file mode 100644 index 0000000..a47754a --- /dev/null +++ b/grades/submission-w2.0.md @@ -0,0 +1 @@ +Grade: 100/100. Nice Work! \ No newline at end of file -- cgit v1.2.3 From 9b29349c5c54bfece455f69c4415595ff14e6d34 Mon Sep 17 00:00:00 2001 From: dfk Date: Mon, 11 Oct 2021 15:42:13 -0500 Subject: Pushed feedback file submission-p2 --- grades/submission-p2.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 grades/submission-p2.md diff --git a/grades/submission-p2.md b/grades/submission-p2.md new file mode 100644 index 0000000..5e5277e --- /dev/null +++ b/grades/submission-p2.md @@ -0,0 +1,5 @@ +# Grade: 98/100. + +### Late penalty: 0 (0 flexible extension days used, 14 remaining) + +**[10/10] Project compiles:**
Feedback:

**[60/60] Project has noticeable work done:**
Feedback:

**[2/2] C Range: Draw lines around the field boundary:**
Feedback:

**[1/1] C Range: Draw a grid of lines for each goal:**
Feedback:

**[2/2] C Range: Ball moves in a random initial velocity:**
Feedback:

**[1/1] C Range: Pressing SPACEBAR relaunches the ball:**
Feedback:

**[2/2] C Range: Ball is affected by gravity:**
Feedback:

**[2/2] C Range: Ball bounces correctly off the ground:**
Feedback:

**[2/2] B Range: Ball bounces correctly off the walls and ceiling:**
Feedback:

**[3/3] B Range: Ball slows down when bouncing:**
Feedback:

**[3/3] B Range: Car can be controlled with the arrow keys (or mouse):**
Feedback:

**[2/2] B Range: Car cannot leave the boundary of the field:**
Feedback:

**[1/1] A Range: UP and DOWN keys change the car's speed:**
Feedback:

**[0/2] A Range: LEFT and RIGHT keys turn the car in proportion to the car's speed:**
Feedback: Car should keep the turn direction when left/right keys are released

**[3/3] A Range: Ball bounces correctly off the car:**
Feedback:

**[2/2] A Range: The velocity of the car affects the velocity of the ball after collision:**
Feedback:

**[2/2] A Range: Landing a goal resets the position of the car and the ball:**
Feedback:

**[0/0] Miscellaneous:**
Feedback:

\ No newline at end of file -- cgit v1.2.3