coeng
diff src/geom.h @ 8:8cce82794f90
seems to work nicely
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 15 Feb 2015 05:14:20 +0200 |
parents | af24cfbdf9b6 |
children |
line diff
1.1 --- a/src/geom.h Sat Feb 14 10:08:00 2015 +0200 1.2 +++ b/src/geom.h Sun Feb 15 05:14:20 2015 +0200 1.3 @@ -14,8 +14,12 @@ 1.4 }; 1.5 1.6 class GeomShape { 1.7 +public: 1.8 + enum Type { GEOM_UNKNOWN, GEOM_SPHERE, GEOM_PLANE, GEOM_AABOX }; 1.9 + 1.10 protected: 1.11 - enum Type { GEOM_UNKNOWN, GEOM_SPHERE, GEOM_PLANE } type; 1.12 + Matrix4x4 xform, inv_xform; 1.13 + Type type; 1.14 1.15 public: 1.16 GeomShape(); 1.17 @@ -23,11 +27,20 @@ 1.18 1.19 virtual Type get_type() const; 1.20 1.21 + // apply an arbitrary transformation before testing intersections and collisions 1.22 + virtual void set_transform(const Matrix4x4 &m); 1.23 + virtual const Matrix4x4 &get_transform() const; 1.24 + virtual const Matrix4x4 &get_inv_transform() const; 1.25 + 1.26 + virtual bool contains(const Vector3 &pt) const = 0; 1.27 virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0; 1.28 virtual bool collide(const GeomShape *geom, HitPoint *hit = 0) const = 0; 1.29 1.30 virtual float distance(const Vector3 &pt) const = 0; 1.31 virtual float distance_sq(const Vector3 &pt) const = 0; 1.32 + 1.33 + // visualize the shape 1.34 + virtual void draw() const = 0; 1.35 }; 1.36 1.37 class Sphere : public GeomShape { 1.38 @@ -38,11 +51,14 @@ 1.39 Sphere(); 1.40 Sphere(const Vector3 &c, float rad); 1.41 1.42 + bool contains(const Vector3 &pt) const; 1.43 bool intersect(const Ray &ray, HitPoint *hit = 0) const; 1.44 bool collide(const GeomShape *geom, HitPoint *hit = 0) const; 1.45 1.46 float distance(const Vector3 &pt) const; 1.47 float distance_sq(const Vector3 &pt) const; 1.48 + 1.49 + void draw() const; 1.50 }; 1.51 1.52 class Plane : public GeomShape { 1.53 @@ -56,11 +72,34 @@ 1.54 Plane(const Vector3 &pos, const Vector3 &norm); 1.55 Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3); 1.56 1.57 + bool contains(const Vector3 &pt) const; 1.58 bool intersect(const Ray &ray, HitPoint *hit = 0) const; 1.59 bool collide(const GeomShape *geom, HitPoint *hit = 0) const; 1.60 1.61 float distance(const Vector3 &pt) const; 1.62 float distance_sq(const Vector3 &pt) const; 1.63 + 1.64 + void draw() const; 1.65 +}; 1.66 + 1.67 +class AABox : public GeomShape { 1.68 +public: 1.69 + Vector3 min, max; 1.70 + 1.71 + AABox(); 1.72 + AABox(const Vector3 &min, const Vector3 &max); 1.73 + 1.74 + void set_union(const GeomShape *obj1, const GeomShape *obj2); 1.75 + void set_intersection(const GeomShape *obj1, const GeomShape *obj2); 1.76 + 1.77 + bool contains(const Vector3 &pt) const; 1.78 + bool intersect(const Ray &ray, HitPoint *hit = 0) const; 1.79 + bool collide(const GeomShape *geom, HitPoint *hit = 0) const; 1.80 + 1.81 + float distance(const Vector3 &pt) const; 1.82 + float distance_sq(const Vector3 &pt) const; 1.83 + 1.84 + void draw() const; 1.85 }; 1.86 1.87 #endif // GEOM_H_