1 /* This file is part of Dilay
2  * Copyright © 2015-2018 Alexander Bau
3  * Use and redistribute under the terms of the GNU General Public License
4  */
5 #ifndef DILAY_INTERSECTION
6 #define DILAY_INTERSECTION
7 
8 #include <glm/glm.hpp>
9 
10 class PrimAABox;
11 class PrimCone;
12 class PrimCylinder;
13 class PrimPlane;
14 class PrimRay;
15 class PrimSphere;
16 class PrimTriangle;
17 
18 class Intersection
19 {
20 public:
21   Intersection ();
22 
23   bool             isIntersection () const;
24   const glm::vec3& position () const;
25   const glm::vec3& normal () const;
26   float            distance () const;
27 
28   void reset ();
29   bool update (float, const glm::vec3&, const glm::vec3&);
30 
31   static Intersection& min (Intersection&, Intersection&);
32   static void          sort (Intersection&, Intersection&);
33 
34 private:
35   bool      _isIntersection;
36   float     _distance;
37   glm::vec3 _position;
38   glm::vec3 _normal;
39 };
40 
41 namespace IntersectionUtil
42 {
43   bool intersects (const PrimSphere&, const PrimTriangle&);
44   bool intersects (const PrimSphere&, const PrimAABox&);
45   bool intersects (const PrimSphere&, const PrimSphere&);
46   bool intersects (const PrimRay&, const PrimSphere&, float*);
47   bool intersects (const PrimRay&, const PrimPlane&, float*);
48   bool intersects (const PrimRay&, const PrimTriangle&, bool, float*);
49   bool intersects (const PrimRay&, const PrimAABox&, float*);
50   bool intersects (const PrimRay&, const PrimCylinder&, float*, float*);
51   bool intersects (const PrimRay&, const PrimCone&, float*, float*);
52   bool intersects (const PrimPlane&, const PrimAABox&);
53   bool intersects (const PrimPlane&, const PrimTriangle&);
54   bool intersects (const PrimCylinder&, const glm::vec3&);
55   bool intersects (const PrimCone&, const glm::vec3&);
56   bool intersects (const PrimAABox&, const PrimAABox&);
57   bool intersects (const PrimAABox&, const PrimTriangle&);
58 }
59 
60 #endif
61