#ifndef GEOMOBJ_H_
#define GEOMOBJ_H_
-#include "gmath/gmath.h"
+#include <gmath/gmath.h>
+
+enum GeomObjectType {
+ GOBJ_UNKNOWN,
+ GOBJ_SPHERE,
+ GOBJ_AABOX,
+ GOBJ_PLANE
+};
class GeomObject;
-class SceneNode;
struct HitPoint {
- float dist; //< parametric distance along the ray
- Vec3 pos; //< position of intersection (orig + dir * dist)
- Vec3 normal; //< normal at the point of intersection
- const void *obj; //< pointer to the intersected object
- const SceneNode *node;
- Ray ray;
+ float dist; // parametric distance along the ray
+ Vec3 pos; // position of intersection (orig + dir * dist)
+ Vec3 normal; // normal at the point of intersection
+ Ray ray, local_ray;
+ const GeomObject *obj; // pointer to the intersected geom-object
+ void *data; // place to hang extra data
};
class GeomObject {
public:
virtual ~GeomObject();
+ virtual GeomObjectType get_type() const = 0;
virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0;
virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 0;
virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0;
+ virtual bool contains(const Vec3 &pt) const = 0;
+
+ virtual float distance(const Vec3 &v) const = 0;
};
class Sphere : public GeomObject {
Sphere();
Sphere(const Vec3 ¢er, float radius);
+ GeomObjectType get_type() const;
+
void set_union(const GeomObject *obj1, const GeomObject *obj2);
void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
bool intersect(const Ray &ray, HitPoint *hit = 0) const;
+ bool contains(const Vec3 &pt) const;
+
+ float distance(const Vec3 &v) const;
};
class AABox : public GeomObject {
AABox();
AABox(const Vec3 &min, const Vec3 &max);
+ GeomObjectType get_type() const;
+
void set_union(const GeomObject *obj1, const GeomObject *obj2);
void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
bool intersect(const Ray &ray, HitPoint *hit = 0) const;
+ bool contains(const Vec3 &pt) const;
+
+ float distance(const Vec3 &v) const;
};
class Plane : public GeomObject {
Plane(const Vec3 &p1, const Vec3 &p2, const Vec3 &p3);
Plane(const Vec3 &normal, float dist);
+ GeomObjectType get_type() const;
+
void set_union(const GeomObject *obj1, const GeomObject *obj2);
void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
bool intersect(const Ray &ray, HitPoint *hit = 0) const;
-};
+ bool contains(const Vec3 &pt) const;
-float sphere_distance(const Vec3 ¢, float rad, const Vec3 &pt);
-float capsule_distance(const Vec3 &a, float ra, const Vec3 &b, float rb, const Vec3 &pt);
+ float distance(const Vec3 &v) const;
+};
#endif // GEOMOBJ_H_