OSGPlane.inl
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 #ifndef _OSGPLANE_INL_
00040 #define _OSGPLANE_INL_
00041
00042 OSG_BEGIN_NAMESPACE
00043
00044
00047 inline
00048 Real Plane::distance(const Pnt3r &pnt) const
00049 {
00050 return _normalVec.dot(pnt) - _distance;
00051 }
00052
00055 inline
00056 bool Plane::isOnPlane(const Pnt3r &point) const
00057 {
00058 Real scalar = _normalVec.dot(point) - _distance;
00059
00060 return osgAbs(scalar) < Eps ? true : false;
00061 }
00062
00063
00066 inline
00067 bool Plane::isInHalfSpace(const Pnt3r &point) const
00068 {
00069 Real scalar = _normalVec.dot(point) - _distance;
00070
00071 return scalar >= 0.f ? true : false;
00072 }
00073
00076 inline
00077 bool Plane::isInHalfSpace(const Pnt3r &min, const Pnt3r &max) const
00078 {
00079 Pnt3r p;
00080
00081 setDirectionIndexPoint(min, max, _directionIndex, p);
00082
00083 return isInHalfSpace(p);
00084 }
00085
00088 inline
00089 bool Plane::isOutHalfSpace(const Pnt3r &min, const Pnt3r &max) const
00090 {
00091 Pnt3r p;
00092
00093 setDirectionIndexPoint(min, max, _directionIndex ^ 7, p);
00094
00095 return !isInHalfSpace(p);
00096 }
00097
00098
00102 inline
00103 void Plane::set(const Vec3r &normal, Real distance)
00104 {
00105 _normalVec = normal;
00106 _distance = distance;
00107
00108 updateDirectionIndex();
00109 }
00110
00111
00116 inline
00117 void Plane::set(Real x,
00118 Real y,
00119 Real z,
00120 Real distance)
00121 {
00122 _normalVec.setValues(x, y, z);
00123
00124 _distance = distance;
00125
00126 updateDirectionIndex();
00127 }
00128
00129
00134 inline
00135 void Plane::set(const Vec4r &plane)
00136 {
00137 _normalVec.setValues(plane[0], plane[1], plane[2]);
00138
00139 _distance = plane[3];
00140
00141 updateDirectionIndex();
00142 }
00143
00144
00145 inline
00146 const Vec3r &Plane::getNormal(void) const
00147 {
00148 return _normalVec;
00149 }
00150
00151
00152 inline
00153 Real Plane::getDistanceFromOrigin(void) const
00154 {
00155 return _distance;
00156 }
00157
00158
00159 inline
00160 bool Plane::operator !=(const Plane &rhs) const
00161 {
00162 return !(*this == rhs);
00163 }
00164
00165 inline
00166 void Plane::setDirectionIndexPoint(const Pnt3r &min,
00167 const Pnt3r &max,
00168 const UInt8 index,
00169 Pnt3r &pnt) const
00170 {
00171 if(index & 0x1)
00172 {
00173 pnt[0] = min[0];
00174 }
00175 else
00176 {
00177 pnt[0] = max[0];
00178 }
00179
00180 if(index & 0x2)
00181 {
00182 pnt[1] = min[1];
00183 }
00184 else
00185 {
00186 pnt[1] = max[1];
00187 }
00188
00189 if(index & 0x4)
00190 {
00191 pnt[2] = min[2];
00192 }
00193 else
00194 {
00195 pnt[2] = max[2];
00196 }
00197 }
00198
00199
00200 OSG_END_NAMESPACE
00201
00202 #endif // _OSGPLANE_INL_