Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreOctreeNode.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 octreenode.cpp  -  description
00003 -------------------
00004 begin                : Fri Sep 27 2002
00005 copyright            : (C) 2002 by Jon Anderson
00006 email                : janders@users.sf.net
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010 *                                                                         *
00011 *   This program is free software; you can redistribute it and/or modify  *
00012 *   it under the terms of the GNU Lesser General Public License as        *
00013 *   published by the Free Software Foundation; either version 2 of the    * 
00014 *   License, or (at your option) any later version.                       *
00015 *                                                                         *
00016 ***************************************************************************/
00017 
00018 #include <OgreRoot.h>
00019 
00020 #include <OgreOctreeNode.h>
00021 #include <OgreOctreeSceneManager.h>
00022 
00023 namespace Ogre
00024 {
00025 unsigned long green = 0xFFFFFFFF;
00026 
00027 unsigned short OctreeNode::mIndexes[ 24 ] = {0, 1, 1, 2, 2, 3, 3, 0,       //back
00028         0, 6, 6, 5, 5, 1,             //left
00029         3, 7, 7, 4, 4, 2,             //right
00030         6, 7, 5, 4 };          //front
00031 unsigned long OctreeNode::mColors[ 8 ] = {green, green, green, green, green, green, green, green };
00032 
00033 OctreeNode::OctreeNode( SceneManager* creator ) : SceneNode( creator )
00034 {
00035     mOctant = 0;
00036 }
00037 
00038 OctreeNode::OctreeNode( SceneManager* creator, const String& name ) : SceneNode( creator, name )
00039 {
00040     mOctant = 0;
00041 }
00042 
00043 OctreeNode::~OctreeNode()
00044 {}
00045 void OctreeNode::_removeNodeAndChildren( )
00046 {
00047     static_cast< OctreeSceneManager * > ( mCreator ) -> _removeOctreeNode( this ); 
00048     //remove all the children nodes as well from the octree.
00049     ChildNodeMap::iterator it = mChildren.begin();
00050     while( it != mChildren.end() )
00051     {
00052         static_cast<OctreeNode *>( it->second ) -> _removeNodeAndChildren();
00053         ++it;
00054     }
00055 }
00056 Node * OctreeNode::removeChild( unsigned short index )
00057 {
00058     OctreeNode *on = static_cast<OctreeNode* >( SceneNode::removeChild( index ) );
00059     on -> _removeNodeAndChildren(); 
00060     return on; 
00061 }
00062     
00063 Node * OctreeNode::removeChild( const String & name )
00064 {
00065     OctreeNode *on = static_cast< OctreeNode * >( SceneNode::removeChild(  name ) );
00066     on -> _removeNodeAndChildren( ); 
00067     return on; 
00068 }
00069 
00070 
00071 //same as SceneNode, only it doesn't care about children...
00072 void OctreeNode::_updateBounds( void )
00073 {
00074     mWorldAABB.setNull();
00075     mLocalAABB.setNull();
00076 
00077     // Update bounds from own attached objects
00078     ObjectMap::iterator i = mObjectsByName.begin();
00079     AxisAlignedBox bx;
00080 
00081     while ( i != mObjectsByName.end() )
00082     {
00083 
00084         // Get local bounds of object
00085         bx = i->second ->getBoundingBox();
00086 
00087         mLocalAABB.merge( bx );
00088 
00089         mWorldAABB.merge( i->second ->getWorldBoundingBox(true) );
00090         ++i;
00091     }
00092 
00093 
00094     //update the OctreeSceneManager that things might have moved.
00095     // if it hasn't been added to the octree, add it, and if has moved
00096     // enough to leave it's current node, we'll update it.
00097     if ( ! mWorldAABB.isNull() )
00098     {
00099         static_cast < OctreeSceneManager * > ( mCreator ) -> _updateOctreeNode( this );
00100     }
00101 
00102 }
00103 
00106 bool OctreeNode::_isIn( AxisAlignedBox &box )
00107 {
00108 
00109     Vector3 center = mWorldAABB.getMaximum().midPoint( mWorldAABB.getMinimum() );
00110 
00111     Vector3 bmin = box.getMinimum();
00112     Vector3 bmax = box.getMaximum();
00113 
00114     return ( bmax > center && bmin < center );
00115 
00116 }
00117 
00119 void OctreeNode::_addToRenderQueue( Camera* cam, RenderQueue *queue )
00120 {
00121     ObjectMap::iterator mit = mObjectsByName.begin();
00122 
00123     while ( mit != mObjectsByName.end() )
00124     {
00125         MovableObject * mo = mit->second;
00126 
00127         mo->_notifyCurrentCamera(cam);
00128         if ( mo->isVisible() )
00129         {
00130             mo -> _updateRenderQueue( queue );
00131         }
00132 
00133         ++mit;
00134     }
00135 
00136 }
00137 
00138 
00139 void OctreeNode::getRenderOperation( RenderOperation& rend )
00140 {
00141 
00142     /* TODO
00143     rend.useIndexes = true;
00144     rend.numTextureCoordSets = 0; // no textures
00145     rend.vertexOptions = LegacyRenderOperation::VO_DIFFUSE_COLOURS;
00146     rend.operationType = LegacyRenderOperation::OT_LINE_LIST;
00147     rend.numVertices = 8;
00148     rend.numIndexes = 24;
00149 
00150     rend.pVertices = mCorners;
00151     rend.pIndexes = mIndexes;
00152     rend.pDiffuseColour = mColors;
00153 
00154     const Vector3 * corners = _getLocalAABB().getAllCorners();
00155 
00156     int index = 0;
00157 
00158     for ( int i = 0; i < 8; i++ )
00159     {
00160         rend.pVertices[ index ] = corners[ i ].x;
00161         index++;
00162         rend.pVertices[ index ] = corners[ i ].y;
00163         index++;
00164         rend.pVertices[ index ] = corners[ i ].z;
00165         index++;
00166     }
00167     */
00168 
00169 
00170 }
00171 }

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:19 2004