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

FXSpheref.h
Go to the documentation of this file.
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,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (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 GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXSpheref.h,v 1.18 2006/01/22 17:58:09 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXSPHEREF_H
25 #define FXSPHEREF_H
26 
27 
28 namespace FX {
29 
30 
31 class FXRangef;
32 
33 
34 /// Spherical bounds
36 public:
39 public:
40 
41  /// Default constructor
43 
44  /// Copy constructor
45  FXSpheref(const FXSpheref& sphere):center(sphere.center),radius(sphere.radius){}
46 
47  /// Initialize from center and radius
48  FXSpheref(const FXVec3f& cen,FXfloat rad=0.0f):center(cen),radius(rad){}
49 
50  /// Initialize from center and radius
51  FXSpheref(FXfloat x,FXfloat y,FXfloat z,FXfloat rad=0.0f):center(x,y,z),radius(rad){}
52 
53  /// Initialize sphere to fully contain the given bounding box
54  FXSpheref(const FXRangef& bounds);
55 
56  /// Assignment
57  FXSpheref& operator=(const FXSpheref& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
58 
59  /// Set value from another sphere
60  FXSpheref& set(const FXSpheref& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
61 
62  /// Set value from center and radius
63  FXSpheref& set(const FXVec3f& cen,FXfloat rad){ center=cen; radius=rad; return *this; }
64 
65  /// Set value from center and radius
66  FXSpheref& set(FXfloat x,FXfloat y,FXfloat z,FXfloat rad){ center.set(x,y,z); radius=rad; return *this; }
67 
68  /// Comparison
69  bool operator==(const FXSpheref& s) const { return center==s.center && radius==s.radius;}
70  bool operator!=(const FXSpheref& s) const { return center!=s.center || radius!=s.radius;}
71 
72  /// Diameter of sphere
73  FXfloat diameter() const { return radius*2.0f; }
74 
75  /// Test if empty
76  bool empty() const { return radius<0.0f; }
77 
78  /// Test if sphere contains point x,y,z
79  bool contains(FXfloat x,FXfloat y,FXfloat z) const;
80 
81  /// Test if sphere contains point p
82  bool contains(const FXVec3f& p) const;
83 
84  /// Test if sphere properly contains another box
85  bool contains(const FXRangef& box) const;
86 
87  /// Test if sphere properly contains another sphere
88  bool contains(const FXSpheref& sphere) const;
89 
90  /// Include point
91  FXSpheref& include(FXfloat x,FXfloat y,FXfloat z);
92 
93  /// Include point
94  FXSpheref& include(const FXVec3f& p);
95 
96  /// Expand radius to include point
97  FXSpheref& includeInRadius(FXfloat x,FXfloat y,FXfloat z);
98 
99  /// Expand radius to include point
100  FXSpheref& includeInRadius(const FXVec3f& p);
101 
102  /// Include given range into this one
103  FXSpheref& include(const FXRangef& box);
104 
105  /// Expand radius to include box
106  FXSpheref& includeInRadius(const FXRangef& box);
107 
108  /// Include given sphere into this one
109  FXSpheref& include(const FXSpheref& sphere);
110 
111  /// Expand radius to include sphere
112  FXSpheref& includeInRadius(const FXSpheref& sphere);
113 
114  /// Intersect sphere with normalized plane ax+by+cz+w; returns -1,0,+1
115  FXint intersect(const FXVec4f& plane) const;
116 
117  /// Intersect sphere with ray u-v
118  bool intersect(const FXVec3f& u,const FXVec3f& v) const;
119 
120  /// Test if box overlaps with sphere
121  friend FXAPI bool overlap(const FXRangef& a,const FXSpheref& b);
122 
123  /// Test if sphere overlaps with box
124  friend FXAPI bool overlap(const FXSpheref& a,const FXRangef& b);
125 
126  /// Test if spheres overlap
127  friend FXAPI bool overlap(const FXSpheref& a,const FXSpheref& b);
128 
129  /// Save object to a stream
130  friend FXAPI FXStream& operator<<(FXStream& store,const FXSpheref& sphere);
131 
132  /// Load object from a stream
133  friend FXAPI FXStream& operator>>(FXStream& store,FXSpheref& sphere);
134  };
135 
136 
137 extern FXAPI bool overlap(const FXRangef& a,const FXSpheref& b);
138 extern FXAPI bool overlap(const FXSpheref& a,const FXRangef& b);
139 extern FXAPI bool overlap(const FXSpheref& a,const FXSpheref& b);
140 
141 extern FXAPI FXStream& operator<<(FXStream& store,const FXSpheref& sphere);
142 extern FXAPI FXStream& operator>>(FXStream& store,FXSpheref& sphere);
143 
144 }
145 
146 #endif
FXStream & operator>>(FXStream &store, FXDate &d)
FXSpheref(const FXSpheref &sphere)
Copy constructor.
Definition: FXSpheref.h:45
FXSpheref & operator=(const FXSpheref &sphere)
Assignment.
Definition: FXSpheref.h:57
FXExtentd intersect(const FXExtentd &a, const FXExtentd &b)
bool operator==(const FXSpheref &s) const
Comparison.
Definition: FXSpheref.h:69
#define FXAPI
Definition: fxdefs.h:122
FXfloat diameter() const
Diameter of sphere.
Definition: FXSpheref.h:73
FXfloat radius
Definition: FXSpheref.h:38
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:397
bool overlap(const FXExtentd &a, const FXExtentd &b)
FXSpheref(const FXVec3f &cen, FXfloat rad=0.0f)
Initialize from center and radius.
Definition: FXSpheref.h:48
FXSpheref & set(const FXSpheref &sphere)
Set value from another sphere.
Definition: FXSpheref.h:60
Single-precision 3-element vector.
Definition: FXVec3f.h:36
bool operator!=(const FXSpheref &s) const
Definition: FXSpheref.h:70
Spherical bounds.
Definition: FXSpheref.h:35
Bounds.
Definition: FXRangef.h:35
float FXfloat
Definition: fxdefs.h:398
FXVec3f center
Definition: FXSpheref.h:37
FXSpheref & set(const FXVec3f &cen, FXfloat rad)
Set value from center and radius.
Definition: FXSpheref.h:63
FXSpheref(FXfloat x, FXfloat y, FXfloat z, FXfloat rad=0.0f)
Initialize from center and radius.
Definition: FXSpheref.h:51
FXVec4d plane(const FXVec4d &vec)
FXStream & operator<<(FXStream &store, const FXDate &d)
FXSpheref()
Default constructor.
Definition: FXSpheref.h:42
FXVec3f & set(const FXVec3f &v)
Set value from another vector.
Definition: FXVec3f.h:74
bool empty() const
Test if empty.
Definition: FXSpheref.h:76
FXSpheref & set(FXfloat x, FXfloat y, FXfloat z, FXfloat rad)
Set value from center and radius.
Definition: FXSpheref.h:66
Single-precision 4-element vector.
Definition: FXVec4f.h:35

Copyright © 1997-2005 Jeroen van der Zijp