cubemapper

view src/geom.h @ 4:2bfafdced01a

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