00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2004 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 /*************************************************************************** 00026 octreenode.cpp - description 00027 ------------------- 00028 begin : Fri Sep 27 2002 00029 copyright : (C) 2002 by Jon Anderson 00030 email : janders@users.sf.net 00031 00032 Enhancements 2003 - 2004 (C) The OGRE Team 00033 00034 ***************************************************************************/ 00035 00036 #include <OgreRoot.h> 00037 00038 #include <OgreOctreeNode.h> 00039 #include <OgreOctreeSceneManager.h> 00040 00041 namespace Ogre 00042 { 00043 unsigned long green = 0xFFFFFFFF; 00044 00045 unsigned short OctreeNode::mIndexes[ 24 ] = {0, 1, 1, 2, 2, 3, 3, 0, //back 00046 0, 6, 6, 5, 5, 1, //left 00047 3, 7, 7, 4, 4, 2, //right 00048 6, 7, 5, 4 }; //front 00049 unsigned long OctreeNode::mColors[ 8 ] = {green, green, green, green, green, green, green, green }; 00050 00051 OctreeNode::OctreeNode( SceneManager* creator ) : SceneNode( creator ) 00052 { 00053 mOctant = 0; 00054 } 00055 00056 OctreeNode::OctreeNode( SceneManager* creator, const String& name ) : SceneNode( creator, name ) 00057 { 00058 mOctant = 0; 00059 } 00060 00061 OctreeNode::~OctreeNode() 00062 {} 00063 void OctreeNode::_removeNodeAndChildren( ) 00064 { 00065 static_cast< OctreeSceneManager * > ( mCreator ) -> _removeOctreeNode( this ); 00066 //remove all the children nodes as well from the octree. 00067 ChildNodeMap::iterator it = mChildren.begin(); 00068 while( it != mChildren.end() ) 00069 { 00070 static_cast<OctreeNode *>( it->second ) -> _removeNodeAndChildren(); 00071 ++it; 00072 } 00073 } 00074 Node * OctreeNode::removeChild( unsigned short index ) 00075 { 00076 OctreeNode *on = static_cast<OctreeNode* >( SceneNode::removeChild( index ) ); 00077 on -> _removeNodeAndChildren(); 00078 return on; 00079 } 00080 Node * OctreeNode::removeChild( Node* child ) 00081 { 00082 OctreeNode *on = static_cast<OctreeNode* >( SceneNode::removeChild( child ) ); 00083 on -> _removeNodeAndChildren(); 00084 return on; 00085 } 00086 00087 Node * OctreeNode::removeChild( const String & name ) 00088 { 00089 OctreeNode *on = static_cast< OctreeNode * >( SceneNode::removeChild( name ) ); 00090 on -> _removeNodeAndChildren( ); 00091 return on; 00092 } 00093 00094 //same as SceneNode, only it doesn't care about children... 00095 void OctreeNode::_updateBounds( void ) 00096 { 00097 mWorldAABB.setNull(); 00098 mLocalAABB.setNull(); 00099 00100 // Update bounds from own attached objects 00101 ObjectMap::iterator i = mObjectsByName.begin(); 00102 AxisAlignedBox bx; 00103 00104 while ( i != mObjectsByName.end() ) 00105 { 00106 00107 // Get local bounds of object 00108 bx = i->second ->getBoundingBox(); 00109 00110 mLocalAABB.merge( bx ); 00111 00112 mWorldAABB.merge( i->second ->getWorldBoundingBox(true) ); 00113 ++i; 00114 } 00115 00116 00117 //update the OctreeSceneManager that things might have moved. 00118 // if it hasn't been added to the octree, add it, and if has moved 00119 // enough to leave it's current node, we'll update it. 00120 if ( ! mWorldAABB.isNull() ) 00121 { 00122 static_cast < OctreeSceneManager * > ( mCreator ) -> _updateOctreeNode( this ); 00123 } 00124 00125 } 00126 00129 bool OctreeNode::_isIn( AxisAlignedBox &box ) 00130 { 00131 00132 Vector3 center = mWorldAABB.getMaximum().midPoint( mWorldAABB.getMinimum() ); 00133 00134 Vector3 bmin = box.getMinimum(); 00135 Vector3 bmax = box.getMaximum(); 00136 00137 return ( bmax > center && bmin < center ); 00138 00139 } 00140 00142 void OctreeNode::_addToRenderQueue( Camera* cam, RenderQueue *queue, bool onlyShadowCasters ) 00143 { 00144 ObjectMap::iterator mit = mObjectsByName.begin(); 00145 00146 while ( mit != mObjectsByName.end() ) 00147 { 00148 MovableObject * mo = mit->second; 00149 00150 mo->_notifyCurrentCamera(cam); 00151 if ( mo->isVisible() && 00152 (!onlyShadowCasters || mo->getCastShadows())) 00153 { 00154 mo -> _updateRenderQueue( queue ); 00155 } 00156 00157 ++mit; 00158 } 00159 00160 } 00161 00162 00163 void OctreeNode::getRenderOperation( RenderOperation& rend ) 00164 { 00165 00166 /* TODO 00167 rend.useIndexes = true; 00168 rend.numTextureCoordSets = 0; // no textures 00169 rend.vertexOptions = LegacyRenderOperation::VO_DIFFUSE_COLOURS; 00170 rend.operationType = LegacyRenderOperation::OT_LINE_LIST; 00171 rend.numVertices = 8; 00172 rend.numIndexes = 24; 00173 00174 rend.pVertices = mCorners; 00175 rend.pIndexes = mIndexes; 00176 rend.pDiffuseColour = mColors; 00177 00178 const Vector3 * corners = _getLocalAABB().getAllCorners(); 00179 00180 int index = 0; 00181 00182 for ( int i = 0; i < 8; i++ ) 00183 { 00184 rend.pVertices[ index ] = corners[ i ].x; 00185 index++; 00186 rend.pVertices[ index ] = corners[ i ].y; 00187 index++; 00188 rend.pVertices[ index ] = corners[ i ].z; 00189 index++; 00190 } 00191 */ 00192 00193 00194 } 00195 }
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:36 2004