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 #ifndef _OSGPLANE_INL_
00029 #define _OSGPLANE_INL_
00030
00031 #include "OSGConfig.h"
00032
00033 OSG_BEGIN_NAMESPACE
00034
00035
00038 inline
00039 Real32 Plane::distance(const Pnt3f &pnt) const
00040 {
00041 return _normalVec.dot(pnt) - _distance;
00042 }
00043
00046 inline
00047 bool Plane::isOnPlane(const Pnt3f &point) const
00048 {
00049 Real32 scalar = _normalVec.dot(point) - _distance;
00050
00051 return osgabs(scalar) < Eps ? true : false;
00052 }
00053
00054
00057 inline
00058 bool Plane::isInHalfSpace(const Pnt3f &point) const
00059 {
00060 Real32 scalar = _normalVec.dot(point) - _distance;
00061
00062 return scalar >= 0 ? true : false;
00063 }
00064
00067 inline
00068 bool Plane::isInHalfSpace(const Pnt3f &min, const Pnt3f &max) const
00069 {
00070 Pnt3f p;
00071
00072 setDirectionIndexPoint(min, max, _directionIndex, p);
00073
00074 return isInHalfSpace(p);
00075 }
00076
00079 inline
00080 bool Plane::isOutHalfSpace(const Pnt3f &min, const Pnt3f &max) const
00081 {
00082 Pnt3f p;
00083
00084 setDirectionIndexPoint(min, max, _directionIndex ^ 7, p);
00085
00086 return !isInHalfSpace(p);
00087 }
00088
00089
00093 inline
00094 void Plane::set(const Vec3f &normal, Real32 distance)
00095 {
00096 _normalVec = normal;
00097 _distance = distance;
00098
00099 updateDirectionIndex();
00100 }
00101
00102
00107 inline
00108 void Plane::set(Real32 x, Real32 y, Real32 z, Real32 distance)
00109 {
00110 _normalVec.setValues(x, y, z);
00111
00112 _distance = distance;
00113
00114 updateDirectionIndex();
00115 }
00116
00117
00122 inline
00123 void Plane::set(const Vec4f &plane)
00124 {
00125 _normalVec.setValues(plane[0], plane[1], plane[2]);
00126
00127 _distance = plane[3];
00128
00129 updateDirectionIndex();
00130 }
00131
00132
00133 inline
00134 const Vec3f &Plane::getNormal(void) const
00135 {
00136 return _normalVec;
00137 }
00138
00139
00140 inline
00141 Real32 Plane::getDistanceFromOrigin(void) const
00142 {
00143 return _distance;
00144 }
00145
00146
00147 inline
00148 bool operator!=(const Plane &p1, const Plane &p2)
00149 {
00150 return !(p1 == p2);
00151 }
00152
00153 inline
00154 void Plane::setDirectionIndexPoint(const Pnt3f &min, const Pnt3f & max,
00155 const UInt8 index, Pnt3f &pnt) const
00156 {
00157 if(index & 0x1)
00158 {
00159 pnt[0] = min[0];
00160 }
00161 else
00162 {
00163 pnt[0] = max[0];
00164 }
00165
00166 if(index & 0x2)
00167 {
00168 pnt[1] = min[1];
00169 }
00170 else
00171 {
00172 pnt[1] = max[1];
00173 }
00174
00175 if(index & 0x4)
00176 {
00177 pnt[2] = min[2];
00178 }
00179 else
00180 {
00181 pnt[2] = max[2];
00182 }
00183 }
00184
00185
00186 OSG_END_NAMESPACE
00187
00188 #endif // _OSGPLANE_INL_