1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | |
---|
30 | #include "OgreBspNode.h" |
---|
31 | #include "OgreBspLevel.h" |
---|
32 | #include "OgreException.h" |
---|
33 | #include "OgreLogManager.h" |
---|
34 | |
---|
35 | namespace Ogre { |
---|
36 | |
---|
37 | //----------------------------------------------------------------------- |
---|
38 | BspNode::BspNode(BspLevel* owner, bool isLeaf) |
---|
39 | { |
---|
40 | mOwner = owner; |
---|
41 | mIsLeaf = isLeaf; |
---|
42 | |
---|
43 | } |
---|
44 | |
---|
45 | //----------------------------------------------------------------------- |
---|
46 | BspNode::BspNode() |
---|
47 | { |
---|
48 | } |
---|
49 | //----------------------------------------------------------------------- |
---|
50 | BspNode::~BspNode() |
---|
51 | { |
---|
52 | } |
---|
53 | |
---|
54 | //----------------------------------------------------------------------- |
---|
55 | bool BspNode::isLeaf(void) const |
---|
56 | { |
---|
57 | return mIsLeaf; |
---|
58 | } |
---|
59 | |
---|
60 | //----------------------------------------------------------------------- |
---|
61 | BspNode* BspNode::getFront(void) const |
---|
62 | { |
---|
63 | if (mIsLeaf) |
---|
64 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
65 | "This method is not valid on a leaf node.", |
---|
66 | "BspNode::getFront"); |
---|
67 | return mFront; |
---|
68 | } |
---|
69 | |
---|
70 | //----------------------------------------------------------------------- |
---|
71 | BspNode* BspNode::getBack(void) const |
---|
72 | { |
---|
73 | if (mIsLeaf) |
---|
74 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
75 | "This method is not valid on a leaf node.", |
---|
76 | "BspNode::getBack"); |
---|
77 | return mBack; |
---|
78 | } |
---|
79 | |
---|
80 | //----------------------------------------------------------------------- |
---|
81 | const Plane& BspNode::getSplitPlane(void) const |
---|
82 | { |
---|
83 | if (mIsLeaf) |
---|
84 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
85 | "This method is not valid on a leaf node.", |
---|
86 | "BspNode::getSplitPlane"); |
---|
87 | |
---|
88 | return mSplitPlane; |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | //----------------------------------------------------------------------- |
---|
93 | const AxisAlignedBox& BspNode::getBoundingBox(void) const |
---|
94 | { |
---|
95 | if (!mIsLeaf) |
---|
96 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
97 | "This method is only valid on a leaf node.", |
---|
98 | "BspNode::getBoundingBox"); |
---|
99 | return mBounds; |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | //----------------------------------------------------------------------- |
---|
104 | int BspNode::getNumFaceGroups(void) const |
---|
105 | { |
---|
106 | if (!mIsLeaf) |
---|
107 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
108 | "This method is only valid on a leaf node.", |
---|
109 | "BspNode::getNumFaces"); |
---|
110 | return mNumFaceGroups; |
---|
111 | } |
---|
112 | |
---|
113 | //----------------------------------------------------------------------- |
---|
114 | int BspNode::getFaceGroupStart(void) const |
---|
115 | { |
---|
116 | if (!mIsLeaf) |
---|
117 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
118 | "This method is only valid on a leaf node.", |
---|
119 | "BspNode::getFaces"); |
---|
120 | return mFaceGroupStart; |
---|
121 | } |
---|
122 | |
---|
123 | //----------------------------------------------------------------------- |
---|
124 | bool BspNode::isLeafVisible(const BspNode* leaf) const |
---|
125 | { |
---|
126 | return mOwner->isLeafVisible(this, leaf); |
---|
127 | } |
---|
128 | //----------------------------------------------------------------------- |
---|
129 | Plane::Side BspNode::getSide (const Vector3& point) const |
---|
130 | { |
---|
131 | if (mIsLeaf) |
---|
132 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
133 | "This method is not valid on a leaf node.", |
---|
134 | "BspNode::getSide"); |
---|
135 | |
---|
136 | return mSplitPlane.getSide(point); |
---|
137 | |
---|
138 | } |
---|
139 | //----------------------------------------------------------------------- |
---|
140 | BspNode* BspNode::getNextNode(const Vector3& point) const |
---|
141 | { |
---|
142 | |
---|
143 | if (mIsLeaf) |
---|
144 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
145 | "This method is not valid on a leaf node.", |
---|
146 | "BspNode::getNextNode"); |
---|
147 | |
---|
148 | Plane::Side sd = getSide(point); |
---|
149 | if (sd == Plane::NEGATIVE_SIDE) |
---|
150 | { |
---|
151 | //LogManager::getSingleton().logMessage("back"); |
---|
152 | return getBack(); |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | //LogManager::getSingleton().logMessage("front"); |
---|
157 | return getFront(); |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | } |
---|
163 | //----------------------------------------------------------------------- |
---|
164 | void BspNode::_addMovable(const MovableObject* mov) |
---|
165 | { |
---|
166 | mMovables.insert(mov); |
---|
167 | } |
---|
168 | //----------------------------------------------------------------------- |
---|
169 | void BspNode::_removeMovable(const MovableObject* mov) |
---|
170 | { |
---|
171 | mMovables.erase(mov); |
---|
172 | } |
---|
173 | //----------------------------------------------------------------------- |
---|
174 | Real BspNode::getDistance(const Vector3& pos) const |
---|
175 | { |
---|
176 | if (mIsLeaf) |
---|
177 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
---|
178 | "This method is not valid on a leaf node.", |
---|
179 | "BspNode::getSide"); |
---|
180 | |
---|
181 | return mSplitPlane.getDistance(pos); |
---|
182 | |
---|
183 | } |
---|
184 | //----------------------------------------------------------------------- |
---|
185 | const BspNode::NodeBrushList& BspNode::getSolidBrushes(void) const |
---|
186 | { |
---|
187 | return mSolidBrushes; |
---|
188 | } |
---|
189 | //----------------------------------------------------------------------- |
---|
190 | std::ostream& operator<< (std::ostream& o, BspNode& n) |
---|
191 | { |
---|
192 | o << "BspNode("; |
---|
193 | if (n.mIsLeaf) |
---|
194 | { |
---|
195 | o << "leaf, bbox=" << n.mBounds << ", cluster=" << n.mVisCluster; |
---|
196 | o << ", faceGrps=" << n.mNumFaceGroups << ", faceStart=" << n.mFaceGroupStart << ")"; |
---|
197 | } |
---|
198 | else |
---|
199 | { |
---|
200 | o << "splitter, plane=" << n.mSplitPlane << ")"; |
---|
201 | } |
---|
202 | return o; |
---|
203 | |
---|
204 | } |
---|
205 | |
---|
206 | } |
---|