OSGPlane.inl

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2003 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
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_