Skip to content

Instantly share code, notes, and snippets.

@lolriven
Forked from dubik/BBox.cpp
Created April 8, 2023 18:04
Show Gist options
  • Save lolriven/dabdbb88f009c9e1c8ddd9f55eac0bf1 to your computer and use it in GitHub Desktop.
Save lolriven/dabdbb88f009c9e1c8ddd9f55eac0bf1 to your computer and use it in GitHub Desktop.
// Vectormath https://github.com/erwincoumans/sce_vectormath
class Ray
{
public:
Ray();
public:
Vectormath::Aos::Vector3 m_pos;
Vectormath::Aos::Vector3 m_dir;
Vectormath::Aos::Vector3 m_invDir; // 1.0f / m_dir per elem
float m_min;
float m_max;
};
bool BBox::Intersect(const Ray &ray) const
{
using namespace Vectormath;
Aos::Vector3 t1(Aos::mulPerElem(m_min - ray.m_pos, ray.m_invDir));
Aos::Vector3 t2(Aos::mulPerElem(m_max - ray.m_pos, ray.m_invDir));
Aos::Vector3 tmin1(Aos::minPerElem(t1, t2));
Aos::Vector3 tmax1(Aos::maxPerElem(t1, t2));
float tmin = Aos::maxElem(tmin1);
float tmax = Aos::minElem(tmax1);
return tmax >= std::max(ray.m_min, tmin) && tmin < ray.m_max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment