source: OGRE/trunk/ogre_changes/Ogre1.2/PlugIns/OctreeSceneManager/src/OgreOctreeNode.cpp @ 921

Revision 921, 6.7 KB checked in by mattausch, 18 years ago (diff)

added updates for visibility

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