Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXSpheref.h
1 /********************************************************************************
2 * *
3 * S i n g l e - P r e c i s i o n S p h e r e C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2004,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXSPHEREF_H
22 #define FXSPHEREF_H
23 
24 namespace FX {
25 
26 
27 class FXRangef;
28 class FXMat4f;
29 
30 
32 class FXAPI FXSpheref {
33 public:
34  FXVec3f center;
35  FXfloat radius;
36 public:
37 
40 
42  FXSpheref(const FXSpheref& sphere):center(sphere.center),radius(sphere.radius){}
43 
45  FXSpheref(const FXVec3f& cen,FXfloat rad=0.0f):center(cen),radius(rad){}
46 
48  FXSpheref(FXfloat x,FXfloat y,FXfloat z,FXfloat rad=0.0f):center(x,y,z),radius(rad){}
49 
51  FXSpheref(const FXRangef& bounds);
52 
54  FXSpheref& operator=(const FXSpheref& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
55 
57  FXSpheref& set(const FXSpheref& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
58 
60  FXSpheref& set(const FXVec3f& cen,FXfloat rad=0.0f){ center=cen; radius=rad; return *this; }
61 
63  FXSpheref& set(FXfloat x,FXfloat y,FXfloat z,FXfloat rad=0.0f){ center.set(x,y,z); radius=rad; return *this; }
64 
66  FXbool operator==(const FXSpheref& s) const { return center==s.center && radius==s.radius;}
67  FXbool operator!=(const FXSpheref& s) const { return center!=s.center || radius!=s.radius;}
68 
70  FXfloat diameter() const { return radius*2.0f; }
71 
73  FXfloat area() const { return radius*radius*12.5663706143591729538505735331f; }
74 
76  FXfloat volume() const { return radius*radius*radius*4.18879020478639098461685784437f; }
77 
79  FXbool empty() const { return radius<0.0f; }
80 
82  FXbool contains(FXfloat x,FXfloat y,FXfloat z) const;
83 
85  FXbool contains(const FXVec3f& p) const;
86 
88  FXbool contains(const FXRangef& box) const;
89 
91  FXbool contains(const FXSpheref& sphere) const;
92 
94  FXSpheref& include(FXfloat x,FXfloat y,FXfloat z);
95 
97  FXSpheref& include(const FXVec3f& p);
98 
100  FXSpheref& includeInRadius(FXfloat x,FXfloat y,FXfloat z);
101 
103  FXSpheref& includeInRadius(const FXVec3f& p);
104 
106  FXSpheref& include(const FXRangef& box);
107 
109  FXSpheref& includeInRadius(const FXRangef& box);
110 
112  FXSpheref& include(const FXSpheref& sphere);
113 
115  FXSpheref& includeInRadius(const FXSpheref& sphere);
116 
118  FXint intersect(const FXVec4f& plane) const;
119 
121  FXbool intersect(const FXVec3f& u,const FXVec3f& v) const;
122 
124  FXbool intersect(const FXVec3f& pos,const FXVec3f& dir,FXfloat hit[]) const;
125 
127  FXSpheref transform(const FXMat4f& mat) const;
128 
131  };
132 
133 
135 extern FXAPI FXbool overlap(const FXRangef& a,const FXSpheref& b);
136 
138 extern FXAPI FXbool overlap(const FXSpheref& a,const FXRangef& b);
139 
141 extern FXAPI FXbool overlap(const FXSpheref& a,const FXSpheref& b);
142 
144 extern FXAPI FXStream& operator<<(FXStream& store,const FXSpheref& sphere);
145 
147 extern FXAPI FXStream& operator>>(FXStream& store,FXSpheref& sphere);
148 
149 }
150 
151 #endif
FXSpheref(const FXSpheref &sphere)
Copy constructor.
Definition: FXSpheref.h:42
~FXSpheref()
Destructor.
Definition: FXSpheref.h:130
FXSpheref & operator=(const FXSpheref &sphere)
Assignment.
Definition: FXSpheref.h:54
FXbool operator==(const FXSpheref &s) const
Comparison.
Definition: FXSpheref.h:66
FXfloat volume() const
Volume of sphere.
Definition: FXSpheref.h:76
FXfloat diameter() const
Diameter of sphere.
Definition: FXSpheref.h:70
Definition: FX4Splitter.h:28
FXSpheref(const FXVec3f &cen, FXfloat rad=0.0f)
Initialize from center and radius.
Definition: FXSpheref.h:45
Single-precision 3-element vector.
Definition: FXVec3f.h:28
Single-precision 4x4 matrix.
Definition: FXMat4f.h:32
Spherical bounds.
Definition: FXSpheref.h:32
Bounds.
Definition: FXRangef.h:32
FXfloat area() const
Area of sphere.
Definition: FXSpheref.h:73
FXSpheref(FXfloat x, FXfloat y, FXfloat z, FXfloat rad=0.0f)
Initialize from center and radius.
Definition: FXSpheref.h:48
FXSpheref()
Default constructor; value is not initialized.
Definition: FXSpheref.h:39
FXVec3f & set(const FXVec3f &v)
Set value from another vector.
Definition: FXVec3f.h:63
FXbool empty() const
Test if empty.
Definition: FXSpheref.h:79
Single-precision 4-element vector.
Definition: FXVec4f.h:28

Copyright © 1997-2022 Jeroen van der Zijp