source: OGRE/trunk/ogrenew/PlugIns/BSPSceneManager/src/OgreBspNode.cpp @ 692

Revision 692, 6.6 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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