conworlds
view src/geom.h @ 18:e4257df067a1
oh yeah, now the tracking is solid. Wasn't rendering the correct part of the texture before.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 26 Aug 2014 12:59:15 +0300 |
parents | |
children |
line source
1 #ifndef GEOMOBJ_H_
2 #define GEOMOBJ_H_
4 #include "vmath/vmath.h"
6 class GeomObject;
8 struct HitPoint {
9 float dist; //< parametric distance along the ray
10 Vector3 pos; //< position of intersection (orig + dir * dist)
11 Vector3 normal; //< normal at the point of intersection
12 const void *obj; //< pointer to the intersected object
13 };
15 class GeomObject {
16 public:
17 virtual ~GeomObject();
19 virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0;
20 virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 0;
22 virtual bool contains(const Vector3 &pt) const = 0;
23 virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0;
24 };
26 class Sphere : public GeomObject {
27 public:
28 Vector3 center;
29 float radius;
31 Sphere();
32 Sphere(const Vector3 ¢er, float radius);
34 void set_union(const GeomObject *obj1, const GeomObject *obj2);
35 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
37 bool contains(const Vector3 &pt) const;
38 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
39 };
41 class AABox : public GeomObject {
42 public:
43 Vector3 min, max;
45 AABox();
46 AABox(const Vector3 &min, const Vector3 &max);
48 void set_union(const GeomObject *obj1, const GeomObject *obj2);
49 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
51 bool contains(const Vector3 &pt) const;
52 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
53 };
55 class Plane : public GeomObject {
56 public:
57 Vector3 pt, normal;
59 Plane();
60 Plane(const Vector3 &pt, const Vector3 &normal);
61 Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3);
62 Plane(const Vector3 &normal, float dist);
64 void set_union(const GeomObject *obj1, const GeomObject *obj2);
65 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
67 bool contains(const Vector3 &pt) const;
68 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
69 };
71 #endif // GEOMOBJ_H_