diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/physics/physics.cpp | 16 | ||||
-rw-r--r-- | src/raytracer/raytracer.cpp | 2 |
2 files changed, 10 insertions, 8 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) diff --git a/src/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp index 3db0faa..6e47953 100644 --- a/src/raytracer/raytracer.cpp +++ b/src/raytracer/raytracer.cpp @@ -52,7 +52,7 @@ void RayTracer::render(RGBA *imageData, const RayTraceScene &scene) { if (settings.currentTime < settings.maxTime) { // still more to render // render the next frame settings.currentTime++; - settings.w++; + // settings.w++; // update physics Physics::updateShapePositions(m_metaData.shapes); |