dbf-halloween2015
diff src/geom.h @ 0:50683c78264e
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 01 Nov 2015 00:09:12 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/geom.h Sun Nov 01 00:09:12 2015 +0200 1.3 @@ -0,0 +1,70 @@ 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 +class SceneNode; 1.11 + 1.12 +struct HitPoint { 1.13 + float dist; //< parametric distance along the ray 1.14 + Vector3 pos; //< position of intersection (orig + dir * dist) 1.15 + Vector3 normal; //< normal at the point of intersection 1.16 + const void *obj; //< pointer to the intersected object 1.17 + const SceneNode *node; 1.18 + Ray ray; 1.19 +}; 1.20 + 1.21 +class GeomObject { 1.22 +public: 1.23 + virtual ~GeomObject(); 1.24 + 1.25 + virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0; 1.26 + virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 0; 1.27 + 1.28 + virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0; 1.29 +}; 1.30 + 1.31 +class Sphere : public GeomObject { 1.32 +public: 1.33 + Vector3 center; 1.34 + float radius; 1.35 + 1.36 + Sphere(); 1.37 + Sphere(const Vector3 ¢er, float radius); 1.38 + 1.39 + void set_union(const GeomObject *obj1, const GeomObject *obj2); 1.40 + void set_intersection(const GeomObject *obj1, const GeomObject *obj2); 1.41 + 1.42 + bool intersect(const Ray &ray, HitPoint *hit = 0) const; 1.43 +}; 1.44 + 1.45 +class AABox : public GeomObject { 1.46 +public: 1.47 + Vector3 min, max; 1.48 + 1.49 + AABox(); 1.50 + AABox(const Vector3 &min, const Vector3 &max); 1.51 + 1.52 + void set_union(const GeomObject *obj1, const GeomObject *obj2); 1.53 + void set_intersection(const GeomObject *obj1, const GeomObject *obj2); 1.54 + 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 intersect(const Ray &ray, HitPoint *hit = 0) const; 1.71 +}; 1.72 + 1.73 +#endif // GEOMOBJ_H_