dbf-halloween2015

view src/geom.h @ 3:c37fe5d8a4ed

windows port
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 06:04:28 +0200
parents
children
line source
1 #ifndef GEOMOBJ_H_
2 #define GEOMOBJ_H_
4 #include "vmath/vmath.h"
6 class GeomObject;
7 class SceneNode;
9 struct HitPoint {
10 float dist; //< parametric distance along the ray
11 Vector3 pos; //< position of intersection (orig + dir * dist)
12 Vector3 normal; //< normal at the point of intersection
13 const void *obj; //< pointer to the intersected object
14 const SceneNode *node;
15 Ray ray;
16 };
18 class GeomObject {
19 public:
20 virtual ~GeomObject();
22 virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0;
23 virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 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 intersect(const Ray &ray, HitPoint *hit = 0) const;
40 };
42 class AABox : public GeomObject {
43 public:
44 Vector3 min, max;
46 AABox();
47 AABox(const Vector3 &min, const Vector3 &max);
49 void set_union(const GeomObject *obj1, const GeomObject *obj2);
50 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
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 intersect(const Ray &ray, HitPoint *hit = 0) const;
68 };
70 #endif // GEOMOBJ_H_