rev |
line source |
nuclear@25
|
1 #ifndef GEOMOBJ_H_
|
nuclear@25
|
2 #define GEOMOBJ_H_
|
nuclear@25
|
3
|
nuclear@25
|
4 #include "vmath/vmath.h"
|
nuclear@25
|
5
|
nuclear@25
|
6 class GeomObject;
|
nuclear@25
|
7
|
nuclear@25
|
8 struct HitPoint {
|
nuclear@25
|
9 float dist; //< parametric distance along the ray
|
nuclear@25
|
10 Vector3 pos; //< position of intersection (orig + dir * dist)
|
nuclear@25
|
11 Vector3 normal; //< normal at the point of intersection
|
nuclear@25
|
12 const void *obj; //< pointer to the intersected object
|
nuclear@25
|
13 };
|
nuclear@25
|
14
|
nuclear@25
|
15 class GeomObject {
|
nuclear@25
|
16 public:
|
nuclear@25
|
17 virtual ~GeomObject();
|
nuclear@25
|
18
|
nuclear@25
|
19 virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0;
|
nuclear@25
|
20 virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 0;
|
nuclear@25
|
21
|
nuclear@25
|
22 virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0;
|
nuclear@25
|
23 };
|
nuclear@25
|
24
|
nuclear@25
|
25 class Sphere : public GeomObject {
|
nuclear@25
|
26 public:
|
nuclear@25
|
27 Vector3 center;
|
nuclear@25
|
28 float radius;
|
nuclear@25
|
29
|
nuclear@25
|
30 Sphere();
|
nuclear@25
|
31 Sphere(const Vector3 ¢er, float radius);
|
nuclear@25
|
32
|
nuclear@25
|
33 void set_union(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@25
|
34 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@25
|
35
|
nuclear@25
|
36 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
|
nuclear@25
|
37 };
|
nuclear@25
|
38
|
nuclear@25
|
39 class AABox : public GeomObject {
|
nuclear@25
|
40 public:
|
nuclear@25
|
41 Vector3 min, max;
|
nuclear@25
|
42
|
nuclear@25
|
43 AABox();
|
nuclear@25
|
44 AABox(const Vector3 &min, const Vector3 &max);
|
nuclear@25
|
45
|
nuclear@25
|
46 void set_union(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@25
|
47 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@25
|
48
|
nuclear@25
|
49 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
|
nuclear@25
|
50 };
|
nuclear@25
|
51
|
nuclear@25
|
52 class Plane : public GeomObject {
|
nuclear@25
|
53 public:
|
nuclear@25
|
54 Vector3 pt, normal;
|
nuclear@25
|
55
|
nuclear@25
|
56 Plane();
|
nuclear@25
|
57 Plane(const Vector3 &pt, const Vector3 &normal);
|
nuclear@25
|
58 Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3);
|
nuclear@25
|
59 Plane(const Vector3 &normal, float dist);
|
nuclear@25
|
60
|
nuclear@25
|
61 void set_union(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@25
|
62 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@25
|
63
|
nuclear@25
|
64 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
|
nuclear@25
|
65 };
|
nuclear@25
|
66
|
nuclear@25
|
67 #endif // GEOMOBJ_H_
|