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