goat3dgfx

view src/geom.h @ 34:3eb6c8f89fe1

merge
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Mar 2014 17:41:10 +0200
parents 7d6b667821cf
children
line source
1 #ifndef GEOMOBJ_H_
2 #define GEOMOBJ_H_
4 #include "vmath/vmath.h"
6 namespace goatgfx {
8 class GeomObject;
10 struct HitPoint {
11 float dist; //< parametric distance along the ray
12 Vector3 pos; //< position of intersection (orig + dir * dist)
13 Vector3 normal; //< normal at the point of intersection
14 const void *obj; //< pointer to the intersected object
15 };
17 class GeomObject {
18 public:
19 virtual ~GeomObject();
21 virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0;
22 virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 0;
24 virtual bool contains(const Vector3 &pt) const = 0;
25 virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0;
26 };
28 class Sphere : public GeomObject {
29 public:
30 Vector3 center;
31 float radius;
33 Sphere();
34 Sphere(const Vector3 &center, float radius);
36 void set_union(const GeomObject *obj1, const GeomObject *obj2);
37 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
39 bool contains(const Vector3 &pt) const;
40 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
41 };
43 class AABox : public GeomObject {
44 public:
45 Vector3 min, max;
47 AABox();
48 AABox(const Vector3 &min, const Vector3 &max);
50 void set_union(const GeomObject *obj1, const GeomObject *obj2);
51 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
53 bool contains(const Vector3 &pt) const;
54 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
55 };
57 class Plane : public GeomObject {
58 public:
59 Vector3 pt, normal;
61 Plane();
62 Plane(const Vector3 &pt, const Vector3 &normal);
63 Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3);
64 Plane(const Vector3 &normal, float dist);
66 void set_union(const GeomObject *obj1, const GeomObject *obj2);
67 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
69 bool contains(const Vector3 &pt) const;
70 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
71 };
73 } // namespace goatgfx
75 #endif // GEOMOBJ_H_