Skip to content

Instantly share code, notes, and snippets.

@dubik
Last active April 8, 2023 18:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dubik/4412640 to your computer and use it in GitHub Desktop.
Save dubik/4412640 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;
}
@jjxtra
Copy link

jjxtra commented Nov 16, 2016

Great code. However, what are ray.m_min and ray.m_max?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment