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 00026 #include "OgreBspNode.h" 00027 #include "OgreBspLevel.h" 00028 #include "OgreException.h" 00029 #include "OgreLogManager.h" 00030 00031 namespace Ogre { 00032 00033 //----------------------------------------------------------------------- 00034 BspNode::BspNode(BspLevel* owner, bool isLeaf) 00035 { 00036 mOwner = owner; 00037 mIsLeaf = isLeaf; 00038 00039 } 00040 00041 //----------------------------------------------------------------------- 00042 BspNode::BspNode() 00043 { 00044 } 00045 //----------------------------------------------------------------------- 00046 BspNode::~BspNode() 00047 { 00048 } 00049 00050 //----------------------------------------------------------------------- 00051 bool BspNode::isLeaf(void) const 00052 { 00053 return mIsLeaf; 00054 } 00055 00056 //----------------------------------------------------------------------- 00057 BspNode* BspNode::getFront(void) const 00058 { 00059 if (mIsLeaf) 00060 throw Exception(Exception::ERR_INVALIDPARAMS, 00061 "This method is not valid on a leaf node.", 00062 "BspNode::getFront"); 00063 return mFront; 00064 } 00065 00066 //----------------------------------------------------------------------- 00067 BspNode* BspNode::getBack(void) const 00068 { 00069 if (mIsLeaf) 00070 throw Exception(Exception::ERR_INVALIDPARAMS, 00071 "This method is not valid on a leaf node.", 00072 "BspNode::getBack"); 00073 return mBack; 00074 } 00075 00076 //----------------------------------------------------------------------- 00077 Plane BspNode::getSplitPlane(void) 00078 { 00079 if (mIsLeaf) 00080 throw Exception(Exception::ERR_INVALIDPARAMS, 00081 "This method is not valid on a leaf node.", 00082 "BspNode::getSplitPlane"); 00083 00084 return mSplitPlane; 00085 00086 } 00087 00088 //----------------------------------------------------------------------- 00089 AxisAlignedBox& BspNode::getBoundingBox(void) 00090 { 00091 if (!mIsLeaf) 00092 throw Exception(Exception::ERR_INVALIDPARAMS, 00093 "This method is only valid on a leaf node.", 00094 "BspNode::getBoundingBox"); 00095 return mBounds; 00096 00097 } 00098 00099 //----------------------------------------------------------------------- 00100 int BspNode::getNumFaceGroups(void) 00101 { 00102 if (!mIsLeaf) 00103 throw Exception(Exception::ERR_INVALIDPARAMS, 00104 "This method is only valid on a leaf node.", 00105 "BspNode::getNumFaces"); 00106 return mNumFaceGroups; 00107 } 00108 00109 //----------------------------------------------------------------------- 00110 int BspNode::getFaceGroupStart(void) 00111 { 00112 if (!mIsLeaf) 00113 throw Exception(Exception::ERR_INVALIDPARAMS, 00114 "This method is only valid on a leaf node.", 00115 "BspNode::getFaces"); 00116 return mFaceGroupStart; 00117 } 00118 00119 //----------------------------------------------------------------------- 00120 bool BspNode::isLeafVisible(const BspNode* leaf) 00121 { 00122 return mOwner->isLeafVisible(this, leaf); 00123 } 00124 //----------------------------------------------------------------------- 00125 Plane::Side BspNode::getSide (const Vector3& point) const 00126 { 00127 if (mIsLeaf) 00128 throw Exception(Exception::ERR_INVALIDPARAMS, 00129 "This method is not valid on a leaf node.", 00130 "BspNode::getSide"); 00131 00132 return mSplitPlane.getSide(point); 00133 00134 } 00135 //----------------------------------------------------------------------- 00136 BspNode* BspNode::getNextNode(const Vector3& point) const 00137 { 00138 00139 if (mIsLeaf) 00140 throw Exception(Exception::ERR_INVALIDPARAMS, 00141 "This method is not valid on a leaf node.", 00142 "BspNode::getNextNode"); 00143 00144 Plane::Side sd = getSide(point); 00145 if (sd == Plane::NEGATIVE_SIDE) 00146 { 00147 //LogManager::getSingleton().logMessage("back"); 00148 return getBack(); 00149 } 00150 else 00151 { 00152 //LogManager::getSingleton().logMessage("front"); 00153 return getFront(); 00154 } 00155 00156 00157 00158 } 00159 //----------------------------------------------------------------------- 00160 void BspNode::_addMovable(const MovableObject* mov) 00161 { 00162 mMovables.insert(mov); 00163 } 00164 //----------------------------------------------------------------------- 00165 void BspNode::_removeMovable(const MovableObject* mov) 00166 { 00167 mMovables.erase(mov); 00168 } 00169 //----------------------------------------------------------------------- 00170 Real BspNode::getDistance(const Vector3& pos) 00171 { 00172 if (mIsLeaf) 00173 throw Exception(Exception::ERR_INVALIDPARAMS, 00174 "This method is not valid on a leaf node.", 00175 "BspNode::getSide"); 00176 00177 return mSplitPlane.getDistance(pos); 00178 00179 } 00180 //----------------------------------------------------------------------- 00181 const BspNode::NodeBrushList& BspNode::getSolidBrushes(void) 00182 { 00183 return mSolidBrushes; 00184 } 00185 //----------------------------------------------------------------------- 00186 std::ostream& operator<< (std::ostream& o, BspNode& n) 00187 { 00188 o << "BspNode("; 00189 if (n.mIsLeaf) 00190 { 00191 o << "leaf, bbox=" << n.mBounds << ", cluster=" << n.mVisCluster; 00192 o << ", faceGrps=" << n.mNumFaceGroups << ", faceStart=" << n.mFaceGroupStart << ")"; 00193 } 00194 else 00195 { 00196 o << "splitter, plane=" << n.mSplitPlane << ")"; 00197 } 00198 return o; 00199 00200 } 00201 00202 }
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:16 2004