OSGSphereVolume.cpp
Go to the documentation of this file.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 <cassert>
00046
00047 #include "OSGSphereVolume.h"
00048
00049 #include "OSGQuaternion.h"
00050 #include "OSGLine.h"
00051 #include "OSGBoxVolume.h"
00052 #include "OSGLog.h"
00053 #include "OSGMatrix.h"
00054
00055 OSG_BEGIN_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(Pnt3r ¢er) const
00073 {
00074 center = _center;
00075 }
00076
00077
00078 Real 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(Pnt3r &min, Pnt3r &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 Pnt3r &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 Real 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 Pnt3r &point) const
00127 {
00128 Real 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 Real &enter,
00147 Real &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 Pnt3r &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 void SphereVolume::transform(const Matrixr &mat)
00171 {
00172
00173 Pnt3r hull(_center);
00174
00175 hull += Vec3r(0.f, _radius, 0.f);
00176
00177 mat.mult(_center, _center);
00178 mat.mult(hull, hull );
00179
00180 _radius = (hull - _center).length();
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 }
00191
00192
00193
00194
00195 SphereVolume &SphereVolume::operator =(const SphereVolume &rhs)
00196 {
00197 if(this == &rhs)
00198 return *this;
00199
00200 _center = rhs._center;
00201 _radius = rhs._radius;
00202
00203 return *this;
00204 }
00205
00206 bool SphereVolume::operator ==(const SphereVolume &rhs) const
00207 {
00208 return (_center == rhs._center) && (_radius == rhs._radius);
00209 }
00210
00212 void SphereVolume::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00213 const BitVector OSG_CHECK_ARG(bvFlags)) const
00214 {
00215 print(PLOG);
00216 }
00217
00218 void SphereVolume::print(std::ostream &os) const
00219 {
00220 os << "Sphere (" << _center << "|" << _radius << ") ";
00221 printState(os);
00222 }
00223
00224 OSG_END_NAMESPACE