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 #include <OgreRoot.h>
00018 
00019 #include <OgreOctreeNode.h>
00020 #include <OgreOctreeSceneManager.h>
00021 
00022 namespace Ogre
00023 {
00024 unsigned long green = 0xFFFFFFFF;
00025 
00026 unsigned short OctreeNode::mIndexes[ 24 ] = {0, 1, 1, 2, 2, 3, 3, 0,       //back
00027         0, 6, 6, 5, 5, 1,             //left
00028         3, 7, 7, 4, 4, 2,             //right
00029         6, 7, 5, 4 };          //front
00030 unsigned long OctreeNode::mColors[ 8 ] = {green, green, green, green, green, green, green, green };
00031 
00032 OctreeNode::OctreeNode( SceneManager* creator ) : SceneNode( creator )
00033 {
00034     mOctant = 0;
00035 }
00036 
00037 OctreeNode::OctreeNode( SceneManager* creator, const String& name ) : SceneNode( creator, name )
00038 {
00039     mOctant = 0;
00040 }
00041 
00042 OctreeNode::~OctreeNode()
00043 {}
00044 void OctreeNode::_removeNodeAndChildren( )
00045 {
00046     static_cast< OctreeSceneManager * > ( mCreator ) -> _removeOctreeNode( this ); 
00047     //remove all the children nodes as well from the octree.
00048     ChildNodeMap::iterator it = mChildren.begin();
00049     while( it != mChildren.end() )
00050     {
00051         static_cast<OctreeNode *>( it->second ) -> _removeNodeAndChildren();
00052         ++it;
00053     }
00054 }
00055 Node * OctreeNode::removeChild( unsigned short index )
00056 {
00057     OctreeNode *on = static_cast<OctreeNode* >( SceneNode::removeChild( index ) );
00058     on -> _removeNodeAndChildren(); 
00059     return on; 
00060 }
00061     
00062 Node * OctreeNode::removeChild( const String & name )
00063 {
00064     OctreeNode *on = static_cast< OctreeNode * >( SceneNode::removeChild(  name ) );
00065     on -> _removeNodeAndChildren( ); 
00066     return on; 
00067 }
00068 
00069 
00070 //same as SceneNode, only it doesn't care about children...
00071 void OctreeNode::_updateBounds( void )
00072 {
00073     mWorldAABB.setNull();
00074     mLocalAABB.setNull();
00075 
00076     // Update bounds from own attached objects
00077     ObjectMap::iterator i = mObjectsByName.begin();
00078     AxisAlignedBox bx;
00079 
00080     while ( i != mObjectsByName.end() )
00081     {
00082 
00083         // Get local bounds of object
00084         bx = i->second ->getBoundingBox();
00085 
00086         mLocalAABB.merge( bx );
00087 
00088         mWorldAABB.merge( i->second ->getWorldBoundingBox(true) );
00089         ++i;
00090     }
00091 
00092 
00093     //update the OctreeSceneManager that things might have moved.
00094     // if it hasn't been added to the octree, add it, and if has moved
00095     // enough to leave it's current node, we'll update it.
00096     if ( ! mWorldAABB.isNull() )
00097     {
00098         static_cast < OctreeSceneManager * > ( mCreator ) -> _updateOctreeNode( this );
00099     }
00100 
00101 }
00102 
00105 bool OctreeNode::_isIn( AxisAlignedBox &box )
00106 {
00107 
00108     Vector3 center = mWorldAABB.getMaximum().midPoint( mWorldAABB.getMinimum() );
00109 
00110     Vector3 bmin = box.getMinimum();
00111     Vector3 bmax = box.getMaximum();
00112 
00113     return ( bmax > center && bmin < center );
00114 
00115 }
00116 
00118 void OctreeNode::_addToRenderQueue( Camera* cam, RenderQueue *queue, bool onlyShadowCasters )
00119 {
00120     ObjectMap::iterator mit = mObjectsByName.begin();
00121 
00122     while ( mit != mObjectsByName.end() )
00123     {
00124         MovableObject * mo = mit->second;
00125 
00126         mo->_notifyCurrentCamera(cam);
00127         if ( mo->isVisible() &&
00128             (!onlyShadowCasters || mo->getCastShadows()))
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 Fri May 14 23:22:29 2004