rev |
line source |
nuclear@4
|
1 /*
|
nuclear@4
|
2 Cubemapper - a program for converting panoramic images into cubemaps
|
nuclear@4
|
3 Copyright (C) 2017 John Tsiombikas <nuclear@member.fsf.org>
|
nuclear@4
|
4
|
nuclear@4
|
5 This program is free software: you can redistribute it and/or modify
|
nuclear@4
|
6 it under the terms of the GNU General Public License as published by
|
nuclear@4
|
7 the Free Software Foundation, either version 3 of the License, or
|
nuclear@4
|
8 (at your option) any later version.
|
nuclear@4
|
9
|
nuclear@4
|
10 This program is distributed in the hope that it will be useful,
|
nuclear@4
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
nuclear@4
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
nuclear@4
|
13 GNU General Public License for more details.
|
nuclear@4
|
14
|
nuclear@4
|
15 You should have received a copy of the GNU General Public License
|
nuclear@4
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
nuclear@4
|
17 */
|
nuclear@0
|
18 #ifndef GEOMOBJ_H_
|
nuclear@0
|
19 #define GEOMOBJ_H_
|
nuclear@0
|
20
|
nuclear@0
|
21 #include <gmath/gmath.h>
|
nuclear@0
|
22
|
nuclear@0
|
23 class GeomObject;
|
nuclear@0
|
24 class SceneNode;
|
nuclear@0
|
25
|
nuclear@0
|
26 struct HitPoint {
|
nuclear@0
|
27 float dist; //< parametric distance along the ray
|
nuclear@0
|
28 Vec3 pos; //< position of intersection (orig + dir * dist)
|
nuclear@0
|
29 Vec3 normal; //< normal at the point of intersection
|
nuclear@0
|
30 const void *obj; //< pointer to the intersected object
|
nuclear@0
|
31 const SceneNode *node;
|
nuclear@0
|
32 Ray ray;
|
nuclear@0
|
33 };
|
nuclear@0
|
34
|
nuclear@0
|
35 class GeomObject {
|
nuclear@0
|
36 public:
|
nuclear@0
|
37 virtual ~GeomObject();
|
nuclear@0
|
38
|
nuclear@0
|
39 virtual void set_union(const GeomObject *obj1, const GeomObject *obj2) = 0;
|
nuclear@0
|
40 virtual void set_intersection(const GeomObject *obj1, const GeomObject *obj2) = 0;
|
nuclear@0
|
41
|
nuclear@0
|
42 virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const = 0;
|
nuclear@0
|
43 };
|
nuclear@0
|
44
|
nuclear@0
|
45 class Sphere : public GeomObject {
|
nuclear@0
|
46 public:
|
nuclear@0
|
47 Vec3 center;
|
nuclear@0
|
48 float radius;
|
nuclear@0
|
49
|
nuclear@0
|
50 Sphere();
|
nuclear@0
|
51 Sphere(const Vec3 ¢er, float radius);
|
nuclear@0
|
52
|
nuclear@0
|
53 void set_union(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@0
|
54 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@0
|
55
|
nuclear@0
|
56 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
|
nuclear@0
|
57 };
|
nuclear@0
|
58
|
nuclear@0
|
59 class AABox : public GeomObject {
|
nuclear@0
|
60 public:
|
nuclear@0
|
61 Vec3 min, max;
|
nuclear@0
|
62
|
nuclear@0
|
63 AABox();
|
nuclear@0
|
64 AABox(const Vec3 &min, const Vec3 &max);
|
nuclear@0
|
65
|
nuclear@0
|
66 void set_union(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@0
|
67 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@0
|
68
|
nuclear@0
|
69 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
|
nuclear@0
|
70 };
|
nuclear@0
|
71
|
nuclear@0
|
72 class Plane : public GeomObject {
|
nuclear@0
|
73 public:
|
nuclear@0
|
74 Vec3 pt, normal;
|
nuclear@0
|
75
|
nuclear@0
|
76 Plane();
|
nuclear@0
|
77 Plane(const Vec3 &pt, const Vec3 &normal);
|
nuclear@0
|
78 Plane(const Vec3 &p1, const Vec3 &p2, const Vec3 &p3);
|
nuclear@0
|
79 Plane(const Vec3 &normal, float dist);
|
nuclear@0
|
80
|
nuclear@0
|
81 void set_union(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@0
|
82 void set_intersection(const GeomObject *obj1, const GeomObject *obj2);
|
nuclear@0
|
83
|
nuclear@0
|
84 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
|
nuclear@0
|
85 };
|
nuclear@0
|
86
|
nuclear@0
|
87 float sphere_distance(const Vec3 ¢, float rad, const Vec3 &pt);
|
nuclear@0
|
88 float capsule_distance(const Vec3 &a, float ra, const Vec3 &b, float rb, const Vec3 &pt);
|
nuclear@0
|
89
|
nuclear@0
|
90 #endif // GEOMOBJ_H_
|