X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fgeom.h;h=e110193ceb9e81968c7a36a019c15383bcfce342;hp=aabf266d74fe3715cf1255a1c3e869336b2e555d;hb=b7c92831285013b2a0783bccaf3d900545ebb5ba;hpb=a58455a92c7ecab980cbe1b7e282aeb6bfe7e889 diff --git a/src/geom.h b/src/geom.h index aabf266..e110193 100644 --- a/src/geom.h +++ b/src/geom.h @@ -1,28 +1,38 @@ #ifndef GEOMOBJ_H_ #define GEOMOBJ_H_ -#include "gmath/gmath.h" +#include + +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 { @@ -33,10 +43,15 @@ public: 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 { @@ -46,10 +61,15 @@ public: 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 { @@ -61,13 +81,15 @@ public: 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_