diff --git a/examples/common/bounds.cpp b/examples/common/bounds.cpp index 2481b74ee..010709c09 100644 --- a/examples/common/bounds.cpp +++ b/examples/common/bounds.cpp @@ -423,11 +423,6 @@ Ray makeRay(float _x, float _y, const float* _invVp) return ray; } -inline Vec3 getPointAt(const Ray& _ray, float _t) -{ - return mad(_ray.dir, _t, _ray.pos); -} - bool intersect(const Ray& _ray, const Aabb& _aabb, Hit* _hit) { const Vec3 invDir = rcp(_ray.dir); @@ -717,16 +712,13 @@ bool intersect(const Ray& _ray, const Cone& _cone, Hit* _hit) return true; } -bool intersect(const Ray& _ray, const Plane& _plane, Hit* _hit) +bool intersect(const Ray& _ray, const Plane& _plane, bool _doublesided, Hit* _hit) { - const float dist = distance(_plane, _ray.pos); - if (0.0f > dist) - { - return false; - } - + const float dist = distance(_plane, _ray.pos); const float ndotd = dot(_ray.dir, _plane.normal); - if (0.0f < ndotd) + + if (!_doublesided + && (0.0f > dist || 0.0f < ndotd) ) { return false; } diff --git a/examples/common/bounds.h b/examples/common/bounds.h index 936a244d5..bf810adbd 100644 --- a/examples/common/bounds.h +++ b/examples/common/bounds.h @@ -82,6 +82,9 @@ struct Hit bx::Plane plane = bx::init::None; }; +/// +bx::Vec3 getPointAt(const Ray& _ray, float _t); + /// bx::Vec3 getCenter(const Aabb& _aabb); @@ -169,6 +172,9 @@ bool intersect(const Ray& _ray, const Disk& _disk, Hit* _hit = NULL); /// Intersect ray / plane. bool intersect(const Ray& _ray, const bx::Plane& _plane, Hit* _hit = NULL); +/// Intersect ray / plane. +bool intersect(const Ray& _ray, const bx::Plane& _plane, bool _doublesided, Hit* _hit = NULL); + /// Intersect ray / sphere. bool intersect(const Ray& _ray, const Sphere& _sphere, Hit* _hit = NULL); diff --git a/examples/common/bounds.inl b/examples/common/bounds.inl index ee915d47c..00753f537 100644 --- a/examples/common/bounds.inl +++ b/examples/common/bounds.inl @@ -7,6 +7,16 @@ # error "Must be included from bounds.h!" #endif // BOUNDS_H_HEADER_GUARD +inline bx::Vec3 getPointAt(const Ray& _ray, float _t) +{ + return bx::mad(_ray.dir, _t, _ray.pos); +} + +inline bool intersect(const Ray& _ray, const bx::Plane& _plane, Hit* _hit) +{ + return intersect(_ray, _plane, false, _hit); +} + inline bool overlap(const Aabb& _aabb, const Sphere& _sphere) { return overlap(_sphere, _aabb);