00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "OSGConfig.h"
00044
00045 #include <assert.h>
00046
00047 #include "OSGBaseTypes.h"
00048
00049 #include "OSGQuaternion.h"
00050 #include "OSGLine.h"
00051 #include "OSGBoxVolume.h"
00052
00053 #include "OSGSphereVolume.h"
00054
00055 OSG_USING_NAMESPACE
00056
00057 #if 0
00058
00059 void SphereVolume::circumscribe(const BoxVolume &box)
00060 {
00061 float radius = 0.5 * (box.getMax() - box.getMin()).length();
00062 Vec3f center;
00063
00064 box.getCenter(center);
00065
00066 setValue(center, radius);
00067 }
00068 #endif
00069
00072 void SphereVolume::getCenter(Pnt3f ¢er) const
00073 {
00074 center = _center;
00075 }
00076
00077
00078 Real32 SphereVolume::getScalarVolume (void) const
00079 {
00080 return isEmpty() ? 0.0f : (4.f / 3.f * Pi * _radius * _radius * _radius);
00081 }
00082
00083
00084 void SphereVolume::getBounds(Pnt3f &min, Pnt3f &max) const
00085 {
00086 min.setValues(_center[0] - _radius,
00087 _center[1] - _radius,
00088 _center[2] - _radius);
00089 max.setValues(_center[0] + _radius,
00090 _center[1] + _radius,
00091 _center[2] + _radius);
00092 }
00093
00094
00095 void SphereVolume::extendBy(const Pnt3f &pt)
00096 {
00097 if(isUntouchable() == true)
00098 return;
00099
00100 if(isEmpty() == true)
00101 {
00102 _center = pt;
00103 _radius = 0.f;
00104
00105 setEmpty(false);
00106 }
00107 else
00108 {
00109 Real32 d = (_center - pt).length();
00110
00111 if(d > _radius)
00112 _radius = d;
00113 }
00114 }
00115
00116
00117 void SphereVolume::extendBy(const Volume &volume)
00118 {
00119 OSG::extend(*this, volume);
00120 }
00121
00122
00123
00126 bool SphereVolume::intersect(const Pnt3f &point) const
00127 {
00128 Real32 d = (_center - point).length();
00129
00130 if(d <= _radius)
00131 return true;
00132 else
00133 return false;
00134 }
00135
00138 bool SphereVolume::intersect(const Line &line) const
00139 {
00140 return line.intersect(*this);
00141 }
00142
00145 bool SphereVolume::intersect(const Line &line,
00146 Real32 &enter,
00147 Real32 &exit ) const
00148 {
00149 return line.intersect(*this, enter, exit);
00150 }
00151
00152
00153 bool SphereVolume::intersect(const Volume &volume) const
00154 {
00155 return OSG::intersect(*this, volume);
00156 }
00157
00158
00159 bool SphereVolume::isOnSurface (const Pnt3f &point) const
00160 {
00161 if(osgabs((point - _center).length() - _radius) < Eps)
00162 return true;
00163 else
00164 return false;
00165 }
00166
00167
00168
00169
00170 #ifdef __sgi
00171 #pragma set woff 1209
00172 #endif
00173
00174 void SphereVolume::transform(const Matrix &mat)
00175 {
00176
00177 Pnt3f hull(_center);
00178 hull += Vec3f(0, _radius, 0);
00179
00180 mat.mult(_center);
00181 mat.mult(hull);
00182 _radius = (hull - _center).length();
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 }
00193
00194 #ifdef __sgi
00195 #pragma reset woff 1209
00196 #endif
00197
00199 void SphereVolume::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00200 const BitVector OSG_CHECK_ARG(bvFlags)) const
00201 {
00202 PLOG << "Sphere(" << _center << "|" << _radius << ")";
00203 }