00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #include "OgreStableHeaders.h" 00026 #include "OgrePlane.h" 00027 00028 namespace Ogre { 00029 //----------------------------------------------------------------------- 00030 Plane::Plane () 00031 { 00032 normal = Vector3::ZERO; 00033 d = 0.0; 00034 } 00035 //----------------------------------------------------------------------- 00036 Plane::Plane (const Plane& rhs) 00037 { 00038 normal = rhs.normal; 00039 d = rhs.d; 00040 } 00041 //----------------------------------------------------------------------- 00042 Plane::Plane (const Vector3& rkNormal, Real fConstant) 00043 { 00044 normal = rkNormal; 00045 d = -fConstant; 00046 } 00047 //----------------------------------------------------------------------- 00048 Plane::Plane (const Vector3& rkNormal, const Vector3& rkPoint) 00049 { 00050 normal = rkNormal; 00051 d = -rkNormal.dotProduct(rkPoint); 00052 } 00053 //----------------------------------------------------------------------- 00054 Plane::Plane (const Vector3& rkPoint0, const Vector3& rkPoint1, 00055 const Vector3& rkPoint2) 00056 { 00057 redefine(rkPoint0, rkPoint1, rkPoint2); 00058 } 00059 //----------------------------------------------------------------------- 00060 Real Plane::getDistance (const Vector3& rkPoint) const 00061 { 00062 return normal.dotProduct(rkPoint) + d; 00063 } 00064 //----------------------------------------------------------------------- 00065 Plane::Side Plane::getSide (const Vector3& rkPoint) const 00066 { 00067 Real fDistance = getDistance(rkPoint); 00068 00069 if ( fDistance < 0.0 ) 00070 return Plane::NEGATIVE_SIDE; 00071 00072 if ( fDistance > 0.0 ) 00073 return Plane::POSITIVE_SIDE; 00074 00075 return Plane::NO_SIDE; 00076 } 00077 //----------------------------------------------------------------------- 00078 void Plane::redefine(const Vector3& rkPoint0, const Vector3& rkPoint1, 00079 const Vector3& rkPoint2) 00080 { 00081 Vector3 kEdge1 = rkPoint1 - rkPoint0; 00082 Vector3 kEdge2 = rkPoint2 - rkPoint0; 00083 normal = kEdge1.crossProduct(kEdge2); 00084 normal.normalise(); 00085 d = -normal.dotProduct(rkPoint0); 00086 } 00087 //----------------------------------------------------------------------- 00088 std::ostream& operator<< (std::ostream& o, Plane& p) 00089 { 00090 o << "Plane(normal=" << p.normal << ", d=" << p.d << ")"; 00091 return o; 00092 } 00093 } // namespace Ogre
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:39 2004