/src/ogre/PlugIns/BSPSceneManager/src/OgreBspNode.cpp
Line | Count | Source |
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-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | |
29 | | #include "OgreBspNode.h" |
30 | | #include "OgreBspLevel.h" |
31 | | #include "OgreException.h" |
32 | | #include "OgreLogManager.h" |
33 | | |
34 | | namespace Ogre { |
35 | | |
36 | | //----------------------------------------------------------------------- |
37 | | BspNode::BspNode(BspLevel* owner, bool inIsLeaf) |
38 | 0 | { |
39 | 0 | mOwner = owner; |
40 | 0 | mIsLeaf = inIsLeaf; |
41 | 0 | } |
42 | | |
43 | | //----------------------------------------------------------------------- |
44 | | BspNode::BspNode() |
45 | 0 | { |
46 | 0 | } |
47 | | //----------------------------------------------------------------------- |
48 | | BspNode::~BspNode() |
49 | 0 | { |
50 | 0 | } |
51 | | |
52 | | //----------------------------------------------------------------------- |
53 | | bool BspNode::isLeaf(void) const |
54 | 0 | { |
55 | 0 | return mIsLeaf; |
56 | 0 | } |
57 | | |
58 | | //----------------------------------------------------------------------- |
59 | | BspNode* BspNode::getFront(void) const |
60 | 0 | { |
61 | 0 | if (mIsLeaf) |
62 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
63 | 0 | "This method is not valid on a leaf node.", |
64 | 0 | "BspNode::getFront"); |
65 | 0 | return mFront; |
66 | 0 | } |
67 | | |
68 | | //----------------------------------------------------------------------- |
69 | | BspNode* BspNode::getBack(void) const |
70 | 0 | { |
71 | 0 | if (mIsLeaf) |
72 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
73 | 0 | "This method is not valid on a leaf node.", |
74 | 0 | "BspNode::getBack"); |
75 | 0 | return mBack; |
76 | 0 | } |
77 | | |
78 | | //----------------------------------------------------------------------- |
79 | | const Plane& BspNode::getSplitPlane(void) const |
80 | 0 | { |
81 | 0 | if (mIsLeaf) |
82 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
83 | 0 | "This method is not valid on a leaf node.", |
84 | 0 | "BspNode::getSplitPlane"); |
85 | | |
86 | 0 | return mSplitPlane; |
87 | |
|
88 | 0 | } |
89 | | |
90 | | //----------------------------------------------------------------------- |
91 | | const AxisAlignedBox& BspNode::getBoundingBox(void) const |
92 | 0 | { |
93 | 0 | if (!mIsLeaf) |
94 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
95 | 0 | "This method is only valid on a leaf node.", |
96 | 0 | "BspNode::getBoundingBox"); |
97 | 0 | return mBounds; |
98 | |
|
99 | 0 | } |
100 | | |
101 | | //----------------------------------------------------------------------- |
102 | | int BspNode::getNumFaceGroups(void) const |
103 | 0 | { |
104 | 0 | if (!mIsLeaf) |
105 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
106 | 0 | "This method is only valid on a leaf node.", |
107 | 0 | "BspNode::getNumFaces"); |
108 | 0 | return mNumFaceGroups; |
109 | 0 | } |
110 | | |
111 | | //----------------------------------------------------------------------- |
112 | | int BspNode::getFaceGroupStart(void) const |
113 | 0 | { |
114 | 0 | if (!mIsLeaf) |
115 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
116 | 0 | "This method is only valid on a leaf node.", |
117 | 0 | "BspNode::getFaces"); |
118 | 0 | return mFaceGroupStart; |
119 | 0 | } |
120 | | |
121 | | //----------------------------------------------------------------------- |
122 | | bool BspNode::isLeafVisible(const BspNode* leaf) const |
123 | 0 | { |
124 | 0 | return mOwner->isLeafVisible(this, leaf); |
125 | 0 | } |
126 | | //----------------------------------------------------------------------- |
127 | | Plane::Side BspNode::getSide (const Vector3& point) const |
128 | 0 | { |
129 | 0 | if (mIsLeaf) |
130 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
131 | 0 | "This method is not valid on a leaf node.", |
132 | 0 | "BspNode::getSide"); |
133 | | |
134 | 0 | return mSplitPlane.getSide(point); |
135 | |
|
136 | 0 | } |
137 | | //----------------------------------------------------------------------- |
138 | | BspNode* BspNode::getNextNode(const Vector3& point) const |
139 | 0 | { |
140 | |
|
141 | 0 | if (mIsLeaf) |
142 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
143 | 0 | "This method is not valid on a leaf node.", |
144 | 0 | "BspNode::getNextNode"); |
145 | | |
146 | 0 | Plane::Side sd = getSide(point); |
147 | 0 | if (sd == Plane::NEGATIVE_SIDE) |
148 | 0 | { |
149 | | //LogManager::getSingleton().logMessage("back"); |
150 | 0 | return getBack(); |
151 | 0 | } |
152 | 0 | else |
153 | 0 | { |
154 | | //LogManager::getSingleton().logMessage("front"); |
155 | 0 | return getFront(); |
156 | 0 | } |
157 | | |
158 | | |
159 | |
|
160 | 0 | } |
161 | | //----------------------------------------------------------------------- |
162 | | void BspNode::_addMovable(const MovableObject* mov) |
163 | 0 | { |
164 | 0 | mMovables.insert(mov); |
165 | 0 | } |
166 | | //----------------------------------------------------------------------- |
167 | | void BspNode::_removeMovable(const MovableObject* mov) |
168 | 0 | { |
169 | 0 | mMovables.erase(mov); |
170 | 0 | } |
171 | | //----------------------------------------------------------------------- |
172 | | Real BspNode::getDistance(const Vector3& pos) const |
173 | 0 | { |
174 | 0 | if (mIsLeaf) |
175 | 0 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, |
176 | 0 | "This method is not valid on a leaf node.", |
177 | 0 | "BspNode::getSide"); |
178 | | |
179 | 0 | return mSplitPlane.getDistance(pos); |
180 | |
|
181 | 0 | } |
182 | | //----------------------------------------------------------------------- |
183 | | const BspNode::NodeBrushList& BspNode::getSolidBrushes(void) const |
184 | 0 | { |
185 | 0 | return mSolidBrushes; |
186 | 0 | } |
187 | | //----------------------------------------------------------------------- |
188 | | std::ostream& operator<< (std::ostream& o, BspNode& n) |
189 | 0 | { |
190 | 0 | o << "BspNode("; |
191 | 0 | if (n.mIsLeaf) |
192 | 0 | { |
193 | 0 | o << "leaf, bbox=" << n.mBounds << ", cluster=" << n.mVisCluster; |
194 | 0 | o << ", faceGrps=" << n.mNumFaceGroups << ", faceStart=" << n.mFaceGroupStart << ")"; |
195 | 0 | } |
196 | 0 | else |
197 | 0 | { |
198 | 0 | o << "splitter, plane=" << n.mSplitPlane << ")"; |
199 | 0 | } |
200 | 0 | return o; |
201 | |
|
202 | 0 | } |
203 | | |
204 | | } |