Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/gue-ni/OpenGL_Flightsim into…
Browse files Browse the repository at this point in the history
… dev
  • Loading branch information
gue-ni committed Feb 23, 2023
2 parents 6ddead9 + 26c520e commit f2e6de4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions OpenGL_Flightsim/collisions.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace collisions {
// test collision between a ray and a sphere
bool test_collision(const Ray& r, const Sphere& s, float *t)
{
// page 178
assert(std::abs(glm::length(r.direction) - 1.0f) < EPSILON);

auto m = r.origin - s.center;
Expand Down Expand Up @@ -129,12 +130,12 @@ namespace collisions {
*t = (-b - std::sqrt(d)) / a;
return true;
#else
Sphere sphere = { .center = s1.center, .radius = s0.radius + s1.radius };

// page 226
auto v = velocity0 - velocity1;
auto vlen = glm::length(v);

Ray ray = { .origin = s0.center, .direction = v / vlen };
Sphere sphere = { .center = s1.center, .radius = s0.radius + s1.radius };

if (test_collision(ray, sphere, t))
return *t <= vlen;
Expand Down

0 comments on commit f2e6de4

Please sign in to comment.