nuclear@7: #ifndef GEOM_H_ nuclear@7: #define GEOM_H_ nuclear@7: nuclear@7: #include nuclear@7: nuclear@7: class GeomShape; nuclear@7: nuclear@7: struct HitPoint { nuclear@7: float dist; nuclear@7: Vector3 pos; nuclear@7: Vector3 normal; nuclear@7: const GeomShape *shape; nuclear@7: void *data; nuclear@7: }; nuclear@7: nuclear@7: class GeomShape { nuclear@7: protected: nuclear@7: enum Type { GEOM_UNKNOWN, GEOM_SPHERE, GEOM_PLANE } type; nuclear@7: nuclear@7: public: nuclear@7: GeomShape(); nuclear@7: virtual ~GeomShape(); nuclear@7: nuclear@7: virtual Type get_type() const; nuclear@7: nuclear@7: virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0; nuclear@7: virtual bool collide(const GeomShape *geom, HitPoint *hit = 0) const = 0; nuclear@7: nuclear@7: virtual float distance(const Vector3 &pt) const = 0; nuclear@7: virtual float distance_sq(const Vector3 &pt) const = 0; nuclear@7: }; nuclear@7: nuclear@7: class Sphere : public GeomShape { nuclear@7: public: nuclear@7: Vector3 center; nuclear@7: float radius; nuclear@7: nuclear@7: Sphere(); nuclear@7: Sphere(const Vector3 &c, float rad); nuclear@7: nuclear@7: bool intersect(const Ray &ray, HitPoint *hit = 0) const; nuclear@7: bool collide(const GeomShape *geom, HitPoint *hit = 0) const; nuclear@7: nuclear@7: float distance(const Vector3 &pt) const; nuclear@7: float distance_sq(const Vector3 &pt) const; nuclear@7: }; nuclear@7: nuclear@7: class Plane : public GeomShape { nuclear@7: public: nuclear@7: Vector3 normal; nuclear@7: float dist; nuclear@7: nuclear@7: Plane(); nuclear@7: Plane(const Vector3 &n, float d); nuclear@7: Plane(float a, float b, float c, float d); nuclear@7: Plane(const Vector3 &pos, const Vector3 &norm); nuclear@7: Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3); nuclear@7: nuclear@7: bool intersect(const Ray &ray, HitPoint *hit = 0) const; nuclear@7: bool collide(const GeomShape *geom, HitPoint *hit = 0) const; nuclear@7: nuclear@7: float distance(const Vector3 &pt) const; nuclear@7: float distance_sq(const Vector3 &pt) const; nuclear@7: }; nuclear@7: nuclear@7: #endif // GEOM_H_