2 This file is part of the n3dmath2 library.
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
6 The n3dmath2 library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 The n3dmath2 library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the n3dmath2 library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _N3DMATH2_QDR_HPP_
22 #define _N3DMATH2_QDR_HPP_
24 #include "n3dmath2.hpp"
26 /* used to store intersections of a ray on the surface
27 * of a quadratic object
30 Vector3 pos, normal; // position and normal of surface at this position
31 scalar_t t; // parametric distance of intersection along ray
32 scalar_t pre_ior, post_ior; // obviously these come handy with raytracing
35 // Abstract base class for surfaces
42 Surface(const Vector3 &pos=Vector3(0,0,0));
45 virtual void set_position(const Vector3 &pos);
46 virtual Vector3 get_position() const;
48 virtual void set_rotation(const Quaternion &rot);
49 virtual Quaternion get_rotation() const;
51 virtual Vector2 inv_map(const Vector3 &pt) const = 0;
53 virtual bool check_intersection(const Ray &ray) const = 0;
54 virtual bool find_intersection(const Ray &ray, SurfPoint *isect) const = 0;
57 // sphere (x² + y² + z² = r²)
58 class Sphere : public Surface {
63 Sphere(const Vector3 &pos=Vector3(0,0,0), scalar_t rad=1.0);
66 virtual void set_radius(scalar_t rad);
67 virtual scalar_t get_radius() const;
69 virtual Vector2 inv_map(const Vector3 &pt) const;
71 virtual bool check_intersection(const Ray &ray) const;
72 virtual bool find_intersection(const Ray &ray, SurfPoint *isect) const;
75 // plane (ax + by + cz + d = 0)
76 class Plane : public Surface {
81 Plane(const Vector3 &pos=Vector3(0,0,0), const Vector3 &normal=Vector3(0,0,-1));
82 Plane(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3);
85 virtual void set_normal(const Vector3 &normal);
86 virtual Vector3 get_normal() const;
88 virtual Vector2 inv_map(const Vector3 &pt) const;
90 virtual bool check_intersection(const Ray &ray) const;
91 virtual bool find_intersection(const Ray &ray, SurfPoint *isect) const;
94 class Box : public Surface {
99 Box(const Vector3 &min_vec = Vector3(-1,-1,-1), const Vector3 &max_vec = Vector3(1,1,1));
100 Box(const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3,
101 const Vector3 &v4, const Vector3 &v5, const Vector3 &v6, const Vector3 &v7);
102 Box(const Vector3 *array);
104 virtual Vector2 inv_map(const Vector3 &pt) const;
106 virtual bool check_intersection(const Ray &ray) const;
107 virtual bool find_intersection(const Ray &ray, SurfPoint *isect) const;
111 bool point_over_plane(const Plane &plane, const Vector3 &point);
112 bool check_tri_ray_intersection(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Ray &ray);
114 #endif // _N3DMATH2_QDR_HPP_