aboutsummaryrefslogtreecommitdiff
path: root/src/physics
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-12-13 05:57:27 -0500
committersotech117 <michael_foiani@brown.edu>2023-12-13 05:57:30 -0500
commit54d7f8b46e71f67a8d0c08447299aadb0920abe4 (patch)
tree20827aeea710352453e8dff79dd56876b953aa4c /src/physics
parent27a87d3bf34040e8178274123373141221bc8a10 (diff)
getting clsoer to collision
Diffstat (limited to 'src/physics')
-rw-r--r--src/physics/physics.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp
index 9c9a513..a624bc5 100644
--- a/src/physics/physics.cpp
+++ b/src/physics/physics.cpp
@@ -1,6 +1,7 @@
//
// Created by Michael Foiani on 12/13/23.
//
+#include <iostream>
#include "physics.h"
bool Physics::checkForSphereCollision(RenderShapeData &currentShape, RenderShapeData &shape)
@@ -8,19 +9,20 @@ bool Physics::checkForSphereCollision(RenderShapeData &currentShape, RenderShape
glm::vec4 currentCenter = currentShape.translation4d;
glm::vec4 shapeCenter = shape.translation4d;
// define a radius vector
- glm::vec4 radiusVector = {.5f, 0, 0, 0};
- glm::vec4 r1 = currentShape.ctm * radiusVector;
- glm::vec4 r2 = shape.ctm * radiusVector;
+ float radius = .5;
float distance = glm::distance(currentCenter, shapeCenter);
+ // std::cout << "distance: " << distance << std::endl;
+
// update velocity
- if (distance <= r1.x + r2.x)
+ if (distance <= radius + radius)
{
- currentShape.velocity = -currentShape.velocity;
- shape.velocity = -shape.velocity;
+ currentShape.velocity *= -1.f;
+ // move a little in other direction so it doesn't flip again
+ currentShape.translation4d = currentShape.velocity;
}
- return distance <= r1.x + r2.x;
+ return distance <= radius + radius;
}
bool Physics::checkForConeCollision(RenderShapeData &currentShape, RenderShapeData &shape)