nuclear@25: #ifndef GEOMOBJ_H_ nuclear@25: #define GEOMOBJ_H_ nuclear@25: nuclear@25: #include "vmath/vmath.h" nuclear@25: nuclear@25: class GeomObject; nuclear@25: nuclear@25: struct HitPoint { nuclear@25: float dist; //< parametric distance along the ray nuclear@25: Vector3 pos; //< position of intersection (orig + dir * dist) nuclear@25: Vector3 normal; //< normal at the point of intersection nuclear@25: const void *obj; //< pointer to the intersected object nuclear@25: }; nuclear@25: nuclear@25: class GeomObject { nuclear@25: public: nuclear@25: virtual ~GeomObject(); nuclear@25: nuclear@25: virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0; nuclear@25: virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 0; nuclear@25: nuclear@25: virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0; nuclear@25: }; nuclear@25: nuclear@25: class Sphere : public GeomObject { nuclear@25: public: nuclear@25: Vector3 center; nuclear@25: float radius; nuclear@25: nuclear@25: Sphere(); nuclear@25: Sphere(const Vector3 ¢er, float radius); nuclear@25: nuclear@25: void set_union(const GeomObject *obj1, const GeomObject *obj2); nuclear@25: void set_intersection(const GeomObject *obj1, const GeomObject *obj2); nuclear@25: nuclear@25: bool intersect(const Ray &ray, HitPoint *hit = 0) const; nuclear@25: }; nuclear@25: nuclear@25: class AABox : public GeomObject { nuclear@25: public: nuclear@25: Vector3 min, max; nuclear@25: nuclear@25: AABox(); nuclear@25: AABox(const Vector3 &min, const Vector3 &max); nuclear@25: nuclear@25: void set_union(const GeomObject *obj1, const GeomObject *obj2); nuclear@25: void set_intersection(const GeomObject *obj1, const GeomObject *obj2); nuclear@25: nuclear@25: bool intersect(const Ray &ray, HitPoint *hit = 0) const; nuclear@25: }; nuclear@25: nuclear@25: class Plane : public GeomObject { nuclear@25: public: nuclear@25: Vector3 pt, normal; nuclear@25: nuclear@25: Plane(); nuclear@25: Plane(const Vector3 &pt, const Vector3 &normal); nuclear@25: Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3); nuclear@25: Plane(const Vector3 &normal, float dist); nuclear@25: nuclear@25: void set_union(const GeomObject *obj1, const GeomObject *obj2); nuclear@25: void set_intersection(const GeomObject *obj1, const GeomObject *obj2); nuclear@25: nuclear@25: bool intersect(const Ray &ray, HitPoint *hit = 0) const; nuclear@25: }; nuclear@25: nuclear@25: #endif // GEOMOBJ_H_