rev |
line source |
nuclear@7
|
1 #ifndef GEOM_H_
|
nuclear@7
|
2 #define GEOM_H_
|
nuclear@7
|
3
|
nuclear@7
|
4 #include <vmath/vmath.h>
|
nuclear@7
|
5
|
nuclear@7
|
6 class GeomShape;
|
nuclear@7
|
7
|
nuclear@7
|
8 struct HitPoint {
|
nuclear@7
|
9 float dist;
|
nuclear@7
|
10 Vector3 pos;
|
nuclear@7
|
11 Vector3 normal;
|
nuclear@7
|
12 const GeomShape *shape;
|
nuclear@7
|
13 void *data;
|
nuclear@7
|
14 };
|
nuclear@7
|
15
|
nuclear@7
|
16 class GeomShape {
|
nuclear@7
|
17 protected:
|
nuclear@7
|
18 enum Type { GEOM_UNKNOWN, GEOM_SPHERE, GEOM_PLANE } type;
|
nuclear@7
|
19
|
nuclear@7
|
20 public:
|
nuclear@7
|
21 GeomShape();
|
nuclear@7
|
22 virtual ~GeomShape();
|
nuclear@7
|
23
|
nuclear@7
|
24 virtual Type get_type() const;
|
nuclear@7
|
25
|
nuclear@7
|
26 virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0;
|
nuclear@7
|
27 virtual bool collide(const GeomShape *geom, HitPoint *hit = 0) const = 0;
|
nuclear@7
|
28
|
nuclear@7
|
29 virtual float distance(const Vector3 &pt) const = 0;
|
nuclear@7
|
30 virtual float distance_sq(const Vector3 &pt) const = 0;
|
nuclear@7
|
31 };
|
nuclear@7
|
32
|
nuclear@7
|
33 class Sphere : public GeomShape {
|
nuclear@7
|
34 public:
|
nuclear@7
|
35 Vector3 center;
|
nuclear@7
|
36 float radius;
|
nuclear@7
|
37
|
nuclear@7
|
38 Sphere();
|
nuclear@7
|
39 Sphere(const Vector3 &c, float rad);
|
nuclear@7
|
40
|
nuclear@7
|
41 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
|
nuclear@7
|
42 bool collide(const GeomShape *geom, HitPoint *hit = 0) const;
|
nuclear@7
|
43
|
nuclear@7
|
44 float distance(const Vector3 &pt) const;
|
nuclear@7
|
45 float distance_sq(const Vector3 &pt) const;
|
nuclear@7
|
46 };
|
nuclear@7
|
47
|
nuclear@7
|
48 class Plane : public GeomShape {
|
nuclear@7
|
49 public:
|
nuclear@7
|
50 Vector3 normal;
|
nuclear@7
|
51 float dist;
|
nuclear@7
|
52
|
nuclear@7
|
53 Plane();
|
nuclear@7
|
54 Plane(const Vector3 &n, float d);
|
nuclear@7
|
55 Plane(float a, float b, float c, float d);
|
nuclear@7
|
56 Plane(const Vector3 &pos, const Vector3 &norm);
|
nuclear@7
|
57 Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3);
|
nuclear@7
|
58
|
nuclear@7
|
59 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
|
nuclear@7
|
60 bool collide(const GeomShape *geom, HitPoint *hit = 0) const;
|
nuclear@7
|
61
|
nuclear@7
|
62 float distance(const Vector3 &pt) const;
|
nuclear@7
|
63 float distance_sq(const Vector3 &pt) const;
|
nuclear@7
|
64 };
|
nuclear@7
|
65
|
nuclear@7
|
66 #endif // GEOM_H_
|