diff options
Diffstat (limited to 'src/physics/physics.cpp')
-rw-r--r-- | src/physics/physics.cpp | 16 |
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 ¤tShape, RenderShapeData &shape) @@ -8,19 +9,20 @@ bool Physics::checkForSphereCollision(RenderShapeData ¤tShape, 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 ¤tShape, RenderShapeData &shape) |