conworlds
diff src/geom.h @ 13:283cdfa7dda2
added a crapload of code from goat3dgfx
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 24 Aug 2014 09:41:24 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/geom.h Sun Aug 24 09:41:24 2014 +0300 1.3 @@ -0,0 +1,71 @@ 1.4 +#ifndef GEOMOBJ_H_ 1.5 +#define GEOMOBJ_H_ 1.6 + 1.7 +#include "vmath/vmath.h" 1.8 + 1.9 +class GeomObject; 1.10 + 1.11 +struct HitPoint { 1.12 + float dist; //< parametric distance along the ray 1.13 + Vector3 pos; //< position of intersection (orig + dir * dist) 1.14 + Vector3 normal; //< normal at the point of intersection 1.15 + const void *obj; //< pointer to the intersected object 1.16 +}; 1.17 + 1.18 +class GeomObject { 1.19 +public: 1.20 + virtual ~GeomObject(); 1.21 + 1.22 + virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0; 1.23 + virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 0; 1.24 + 1.25 + virtual bool contains(const Vector3 &pt) const = 0; 1.26 + virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0; 1.27 +}; 1.28 + 1.29 +class Sphere : public GeomObject { 1.30 +public: 1.31 + Vector3 center; 1.32 + float radius; 1.33 + 1.34 + Sphere(); 1.35 + Sphere(const Vector3 ¢er, float radius); 1.36 + 1.37 + void set_union(const GeomObject *obj1, const GeomObject *obj2); 1.38 + void set_intersection(const GeomObject *obj1, const GeomObject *obj2); 1.39 + 1.40 + bool contains(const Vector3 &pt) const; 1.41 + bool intersect(const Ray &ray, HitPoint *hit = 0) const; 1.42 +}; 1.43 + 1.44 +class AABox : public GeomObject { 1.45 +public: 1.46 + Vector3 min, max; 1.47 + 1.48 + AABox(); 1.49 + AABox(const Vector3 &min, const Vector3 &max); 1.50 + 1.51 + void set_union(const GeomObject *obj1, const GeomObject *obj2); 1.52 + void set_intersection(const GeomObject *obj1, const GeomObject *obj2); 1.53 + 1.54 + bool contains(const Vector3 &pt) const; 1.55 + bool intersect(const Ray &ray, HitPoint *hit = 0) const; 1.56 +}; 1.57 + 1.58 +class Plane : public GeomObject { 1.59 +public: 1.60 + Vector3 pt, normal; 1.61 + 1.62 + Plane(); 1.63 + Plane(const Vector3 &pt, const Vector3 &normal); 1.64 + Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3); 1.65 + Plane(const Vector3 &normal, float dist); 1.66 + 1.67 + void set_union(const GeomObject *obj1, const GeomObject *obj2); 1.68 + void set_intersection(const GeomObject *obj1, const GeomObject *obj2); 1.69 + 1.70 + bool contains(const Vector3 &pt) const; 1.71 + bool intersect(const Ray &ray, HitPoint *hit = 0) const; 1.72 +}; 1.73 + 1.74 +#endif // GEOMOBJ_H_