goat3dgfx

view src/geom.h @ 10:b4c9a24c946e

wrote an awesome configure script added "main" 3d engine source file with global init/cleanup
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Nov 2013 13:30:44 +0200
parents
children 7d6b667821cf
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 intersect(const Ray &ray, HitPoint *hit = 0) const = 0;
23 };
25 class Sphere : public GeomObject {
26 public:
27 Vector3 center;
28 float radius;
30 Sphere();
31 Sphere(const Vector3 &center, float radius);
33 void set_union(const GeomObject *obj1, const GeomObject *obj2);
34 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
36 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
37 };
39 class AABox : public GeomObject {
40 public:
41 Vector3 min, max;
43 AABox();
44 AABox(const Vector3 &min, const Vector3 &max);
46 void set_union(const GeomObject *obj1, const GeomObject *obj2);
47 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
49 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
50 };
52 class Plane : public GeomObject {
53 public:
54 Vector3 pt, normal;
56 Plane();
57 Plane(const Vector3 &pt, const Vector3 &normal);
58 Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3);
59 Plane(const Vector3 &normal, float dist);
61 void set_union(const GeomObject *obj1, const GeomObject *obj2);
62 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
64 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
65 };
67 #endif // GEOMOBJ_H_