summary refs log tree commit diff
path: root/src/Math/AABB.cpp
blob: aa814a12b0124c8cc12003b6bd6d4121739a5654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// This file breaks the Ray.hpp <-> AABB.hpp dependency cycle.

#include "AABB.hpp"
#include "Ray.hpp"

AABB AABB::cast_box(Vector<3> v, AABB against) const {
    auto ray = Ray{center(), v};

    auto expanded_target = against.sum(*this);
    auto raycast = ray.cast(expanded_target);
    if (!raycast.hit) return *this;

    auto result_from = raycast.point - size() / 2.0;
    auto result_to = result_from + size();

    return {result_from, result_to};
}