source: OGRE/trunk/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeNode.cpp @ 193

Revision 193, 6.8 KB checked in by mattausch, 19 years ago (diff)

changed to ogre 103
added readme

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/***************************************************************************
26octreenode.cpp  -  description
27-------------------
28begin                : Fri Sep 27 2002
29copyright            : (C) 2002 by Jon Anderson
30email                : janders@users.sf.net
31
32Enhancements 2003 - 2004 (C) The OGRE Team
33
34***************************************************************************/
35
36#include <OgreRoot.h>
37
38#include <OgreOctreeNode.h>
39#include <OgreOctreeSceneManager.h>
40#include <OgreMeshManager.h>
41#include <OgreSubMesh.h>
42
43namespace Ogre
44{
45unsigned long green = 0xFFFFFFFF;
46
47#ifdef GTP_VISIBILITY_MODIFIED_OGRE
48Real OctreeNode::msVizScale = 1;
49#endif // GTP_VISIBILITY_MODIFIED_OGRE
50
51unsigned short OctreeNode::mIndexes[ 24 ] = {0, 1, 1, 2, 2, 3, 3, 0,       //back
52        0, 6, 6, 5, 5, 1,             //left
53        3, 7, 7, 4, 4, 2,             //right
54        6, 7, 5, 4 };          //front
55unsigned long OctreeNode::mColors[ 8 ] = {green, green, green, green, green, green, green, green };
56
57OctreeNode::OctreeNode( SceneManager* creator ) : SceneNode( creator )
58{
59    mOctant = 0;
60}
61
62OctreeNode::OctreeNode( SceneManager* creator, const String& name ) : SceneNode( creator, name )
63{
64    mOctant = 0;
65}
66
67OctreeNode::~OctreeNode()
68{}
69void OctreeNode::_removeNodeAndChildren( )
70{
71    static_cast< OctreeSceneManager * > ( mCreator ) -> _removeOctreeNode( this );
72    //remove all the children nodes as well from the octree.
73    ChildNodeMap::iterator it = mChildren.begin();
74    while( it != mChildren.end() )
75    {
76        static_cast<OctreeNode *>( it->second ) -> _removeNodeAndChildren();
77        ++it;
78    }
79}
80Node * OctreeNode::removeChild( unsigned short index )
81{
82    OctreeNode *on = static_cast<OctreeNode* >( SceneNode::removeChild( index ) );
83    on -> _removeNodeAndChildren();
84    return on;
85}
86Node * OctreeNode::removeChild( Node* child )
87{
88    OctreeNode *on = static_cast<OctreeNode* >( SceneNode::removeChild( child ) );
89    on -> _removeNodeAndChildren();
90    return on;
91}
92   
93Node * OctreeNode::removeChild( const String & name )
94{
95    OctreeNode *on = static_cast< OctreeNode * >( SceneNode::removeChild(  name ) );
96    on -> _removeNodeAndChildren( );
97    return on;
98}
99
100//same as SceneNode, only it doesn't care about children...
101void OctreeNode::_updateBounds( void )
102{
103    mWorldAABB.setNull();
104    mLocalAABB.setNull();
105
106    // Update bounds from own attached objects
107    ObjectMap::iterator i = mObjectsByName.begin();
108    AxisAlignedBox bx;
109
110    while ( i != mObjectsByName.end() )
111    {
112
113        // Get local bounds of object
114        bx = i->second ->getBoundingBox();
115
116        mLocalAABB.merge( bx );
117
118        mWorldAABB.merge( i->second ->getWorldBoundingBox(true) );
119        ++i;
120    }
121
122
123    //update the OctreeSceneManager that things might have moved.
124    // if it hasn't been added to the octree, add it, and if has moved
125    // enough to leave it's current node, we'll update it.
126    if ( ! mWorldAABB.isNull() )
127    {
128        static_cast < OctreeSceneManager * > ( mCreator ) -> _updateOctreeNode( this );
129    }
130
131}
132
133/** Since we are loose, only check the center.
134*/
135bool OctreeNode::_isIn( AxisAlignedBox &box )
136{
137        // Always fail if not in the scene graph
138        if (!mIsInSceneGraph) return false;
139
140    Vector3 center = mWorldAABB.getMaximum().midPoint( mWorldAABB.getMinimum() );
141
142    Vector3 bmin = box.getMinimum();
143    Vector3 bmax = box.getMaximum();
144
145    return ( bmax > center && bmin < center );
146
147}
148
149/** Addes the attached objects of this OctreeScene node into the queue. */
150void OctreeNode::_addToRenderQueue( Camera* cam, RenderQueue *queue, bool onlyShadowCasters )
151{
152    ObjectMap::iterator mit = mObjectsByName.begin();
153
154    while ( mit != mObjectsByName.end() )
155    {
156        MovableObject * mo = mit->second;
157
158        mo->_notifyCurrentCamera(cam);
159        if ( mo->isVisible() &&
160            (!onlyShadowCasters || mo->getCastShadows()))
161        {
162            mo -> _updateRenderQueue( queue );
163        }
164
165        ++mit;
166    }
167
168}
169
170
171void OctreeNode::getRenderOperation( RenderOperation& rend )
172{
173#ifdef GTP_VISIBILITY_MODIFIED_OGRE
174        /*static SubMesh* pSubMesh = 0;
175
176        if (!pSubMesh)
177        {
178                MeshPtr pMesh = MeshManager::getSingleton().load("axis.mesh",
179                        ResourceGroupManager::BOOTSTRAP_RESOURCE_GROUP_NAME);
180                pSubMesh = pMesh->getSubMesh(0);
181        }
182        pSubMesh->_getRenderOperation(rend);*/
183
184        // HACK. render scaled box
185        if (mWireBoundingBox == NULL)
186        {
187                mWireBoundingBox = new WireBoundingBox();
188        }
189
190        //LogManager::getSingleton().logMessage("hagaaggaagag");
191        AxisAlignedBox box = mLocalAABB;
192       
193        // HACK: scale should not be done here
194        box.scale(Vector3(msVizScale, msVizScale, msVizScale));
195
196        mWireBoundingBox->setupBoundingBox(box);
197        mWireBoundingBox->getRenderOperation(rend);
198
199#endif // GTP_VISIBILITY_MODIFIED_OGRE
200
201    /* TODO
202    rend.useIndexes = true;
203    rend.numTextureCoordSets = 0; // no textures
204    rend.vertexOptions = LegacyRenderOperation::VO_DIFFUSE_COLOURS;
205    rend.operationType = LegacyRenderOperation::OT_LINE_LIST;
206    rend.numVertices = 8;
207    rend.numIndexes = 24;
208
209    rend.pVertices = mCorners;
210    rend.pIndexes = mIndexes;
211    rend.pDiffuseColour = mColors;
212
213    const Vector3 * corners = _getLocalAABB().getAllCorners();
214
215    int index = 0;
216
217    for ( int i = 0; i < 8; i++ )
218    {
219        rend.pVertices[ index ] = corners[ i ].x;
220        index++;
221        rend.pVertices[ index ] = corners[ i ].y;
222        index++;
223        rend.pVertices[ index ] = corners[ i ].z;
224        index++;
225    }
226    */
227
228
229}
230
231#ifdef GTP_VISIBILITY_MODIFIED_OGRE
232void OctreeNode::setVizScale(Real scale)
233{
234        msVizScale = scale;
235}
236#endif // GTP_VISIBILITY_MODIFIED_OGRE
237}
Note: See TracBrowser for help on using the repository browser.