2014-07-22 20:46:47 -07:00
|
|
|
/* objectBox.hh
|
|
|
|
* vim: set tw=80:
|
|
|
|
* Eryn Wells <eryn@erynwells.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "basics.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "types.hh"
|
|
|
|
|
|
|
|
|
|
|
|
namespace charles {
|
|
|
|
|
|
|
|
struct Box
|
|
|
|
: public Object
|
|
|
|
{
|
|
|
|
Box();
|
|
|
|
Box(const Vector3& near, const Vector3& far);
|
|
|
|
|
2014-07-22 21:37:49 -07:00
|
|
|
Vector3& GetNear();
|
|
|
|
void SetNear(const Vector3& near);
|
|
|
|
Vector3& GetFar();
|
|
|
|
void SetFar(const Vector3& far);
|
|
|
|
|
2014-08-02 15:21:14 -07:00
|
|
|
bool DoesIntersect(const Ray& ray, TVector& t, Stats& stats) const;
|
2014-07-22 20:46:47 -07:00
|
|
|
bool point_is_on_surface(const Vector3 &p) const;
|
|
|
|
Vector3 compute_normal(const Vector3 &p) const;
|
|
|
|
|
2014-08-03 17:25:00 -07:00
|
|
|
/** @see charles::Object::Write */
|
|
|
|
void Write(std::ostream& ost) const;
|
|
|
|
|
2014-08-09 10:08:21 -07:00
|
|
|
protected:
|
|
|
|
bool DoIntersect(const basics::Ray& ray, TVector& t, Stats& stats) const;
|
|
|
|
|
2014-07-22 20:46:47 -07:00
|
|
|
private:
|
2014-08-03 12:23:19 -07:00
|
|
|
/**
|
|
|
|
* Perform the intersection test on a slab, defined by `slabHigh` and
|
|
|
|
* `slabLow`.
|
|
|
|
*
|
|
|
|
* @param [in] slabLow The lower bound of the slab
|
|
|
|
* @param [in] slabHigh The upper bound of the slab
|
|
|
|
* @param [in] rayOriginComponent The ray's origin component
|
|
|
|
* @param [in] rayDirectionComponent The ray's direction component
|
|
|
|
* @param [in,out] tNear The nearest intersection t value
|
|
|
|
* @param [in,out] tFar The farthest intersection t value
|
|
|
|
* @returns `true` if the box was hit on this slab
|
|
|
|
*/
|
|
|
|
bool IntersectSlab(const Double& slabLow,
|
|
|
|
const Double& slabHigh,
|
|
|
|
const Double& rayOriginComponent,
|
|
|
|
const Double& rayDirectionComponent,
|
|
|
|
Double& tNear,
|
|
|
|
Double& tFar) const;
|
|
|
|
|
2014-07-22 20:46:47 -07:00
|
|
|
/** The near, lower left corner. */
|
|
|
|
Vector3 mNear;
|
|
|
|
|
|
|
|
/** The far, upper right corner. */
|
|
|
|
Vector3 mFar;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace charles */
|