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
00044 #include "OSGConfig.h"
00045
00046 #include <assert.h>
00047
00048 #include <OSGPlane.h>
00049 #include <OSGVolume.h>
00050
00051 #include "OSGCylinderVolume.h"
00052
00053 OSG_USING_NAMESPACE
00054
00055
00056 void CylinderVolume::getCenter(Pnt3f ¢er) const
00057 {
00058 center = _axisPos + _axisDir * .5;
00059 }
00060
00061
00062 Real32 CylinderVolume::getScalarVolume(void) const
00063 {
00064 return isEmpty() ? 0.0f : (_radius * _radius * Pi * _axisDir.length());
00065 }
00066
00069 void CylinderVolume::getBounds(Pnt3f &min, Pnt3f &max) const
00070 {
00071
00072
00073 if(_axisDir[0] < 0)
00074 {
00075 min[0] = _axisPos[0] + _axisDir[0] - _radius;
00076 max[0] = _axisPos[0] - _axisDir[0] + _radius;
00077 }
00078 else
00079 {
00080 min[0] = _axisPos[0] - _axisDir[0] - _radius;
00081 max[0] = _axisPos[0] + _axisDir[0] + _radius;
00082 }
00083
00084 if(_axisDir[1] < 0)
00085 {
00086 min[1] = _axisPos[1] + _axisDir[1] - _radius;
00087 max[1] = _axisPos[1] - _axisDir[1] + _radius;
00088 }
00089 else
00090 {
00091 min[1] = _axisPos[1] - _axisDir[1] - _radius;
00092 max[1] = _axisPos[1] + _axisDir[1] + _radius;
00093 }
00094
00095 if(_axisDir[2] < 0)
00096 {
00097 min[2] = _axisPos[2] + _axisDir[2] - _radius;
00098 max[2] = _axisPos[2] - _axisDir[2] + _radius;
00099 }
00100 else
00101 {
00102 min[2] = _axisPos[2] - _axisDir[2] - _radius;
00103 max[2] = _axisPos[2] + _axisDir[2] + _radius;
00104 }
00105 }
00106
00107
00108
00109 #ifdef __sgi
00110 #pragma set woff 1209
00111 #endif
00112
00115 void CylinderVolume::extendBy(const Pnt3f &OSG_CHECK_ARG(pt))
00116 {
00117 assert(false);
00118 }
00119
00120
00121 void CylinderVolume::extendBy(const Volume &volume)
00122 {
00123 OSG::extend(*this, volume);
00124 }
00125
00126 #ifdef __sgi
00127 #pragma reset woff 1209
00128 #endif
00129
00130
00131
00132
00137 bool CylinderVolume::intersect(const Pnt3f &point) const
00138 {
00139 Real32 dist = Line(_axisPos, _axisDir).distance(point);
00140
00141 if(dist > _radius)
00142 return false;
00143
00144 Plane bottom( _axisDir, _axisPos );
00145 Plane top (-_axisDir, _axisPos + _axisDir);
00146
00147 bool inspace = bottom.isInHalfSpace(point) && top.isInHalfSpace(point);
00148
00149 return inspace;
00150 }
00151
00152
00155 bool CylinderVolume::intersect(const Line &line) const
00156 {
00157 return line.intersect(*this);
00158 }
00159
00162 bool CylinderVolume::intersect(const Line &line,
00163 Real32 &enter,
00164 Real32 &exit ) const
00165 {
00166 return line.intersect(*this, enter, exit);
00167 }
00168
00169 bool CylinderVolume::intersect(const Volume &volume) const
00170 {
00171 return OSG::intersect(*this,volume);
00172 }
00173
00174
00175 bool CylinderVolume::isOnSurface(const Pnt3f &point) const
00176 {
00177 Real32 dist = Line(_axisPos, _axisDir).distance(point);
00178
00179 if(dist > _radius)
00180 return false;
00181
00182 Plane bottom(-_axisDir, _axisPos );
00183 Plane top ( _axisDir, _axisPos + _axisDir);
00184
00185 bool onplane = bottom.isOnPlane(point) || top.isOnPlane(point);
00186
00187 return ( onplane && dist <= _radius ) ||
00188 (!onplane && osgabs(dist - _radius) < Eps);
00189 }
00190
00191
00192
00193 #ifdef __sgi
00194 #pragma set woff 1209
00195 #endif
00196
00199 void CylinderVolume::transform(const Matrix &OSG_CHECK_ARG(mat))
00200 {
00201 assert(false);
00202 }
00203
00204 #ifdef __sgi
00205 #pragma reset woff 1209
00206 #endif
00207
00209
00210 void CylinderVolume::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00211 const BitVector OSG_CHECK_ARG(bvFlags )) const
00212 {
00213 PLOG << "Cylinder("
00214 << _axisPos
00215 << "|"
00216 << _axisDir
00217 << "|"
00218 << _radius
00219 << ")";
00220 }
00221