Sophie

Sophie

distrib > Mandriva > 10.0 > i586 > media > contrib > by-pkgid > 06719cf03808e17ae6f0852ca1052dc2 > files > 929

libogre1-devel-0.13.0-1mdk.i586.rpm

<html>
<head>
<title>OgreOctreeNode.cpp Source File - OGRE Documentation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<link type="text/css" rel="stylesheet" href="style.css">
</head>

<body>
<!-- Generated by Doxygen 1.2.16 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>OgreOctreeNode.cpp</h1><a href="OgreOctreeNode_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/***************************************************************************</font>
00002 <font class="comment">octreenode.cpp  -  description</font>
00003 <font class="comment">-------------------</font>
00004 <font class="comment">begin                : Fri Sep 27 2002</font>
00005 <font class="comment">copyright            : (C) 2002 by Jon Anderson</font>
00006 <font class="comment">email                : janders@users.sf.net</font>
00007 <font class="comment">***************************************************************************/</font>
00008 
00009 <font class="comment">/***************************************************************************</font>
00010 <font class="comment">*                                                                         *</font>
00011 <font class="comment">*   This program is free software; you can redistribute it and/or modify  *</font>
00012 <font class="comment">*   it under the terms of the GNU Lesser General Public License as        *</font>
00013 <font class="comment">*   published by the Free Software Foundation; either version 2 of the    * </font>
00014 <font class="comment">*   License, or (at your option) any later version.                       *</font>
00015 <font class="comment">*                                                                         *</font>
00016 <font class="comment">***************************************************************************/</font>
00017 
00018 <font class="preprocessor">#include &lt;<a class="code" href="OgreRoot_8h.html">OgreRoot.h</a>&gt;</font>
00019 
00020 <font class="preprocessor">#include &lt;<a class="code" href="OgreOctreeNode_8h.html">OgreOctreeNode.h</a>&gt;</font>
00021 <font class="preprocessor">#include &lt;<a class="code" href="OgreOctreeSceneManager_8h.html">OgreOctreeSceneManager.h</a>&gt;</font>
00022 
00023 <font class="keyword">namespace </font>Ogre
00024 {
<a name="l00025"></a><a class="code" href="namespaceOgre.html#a477">00025</a> <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> <a class="code" href="namespaceOgre.html#a477">green</a> = 0xFFFFFFFF;
00026 
<a name="l00027"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodeq1">00027</a> <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> OctreeNode::mIndexes[ 24 ] = {0, 1, 1, 2, 2, 3, 3, 0,       <font class="comment">//back</font>
00028         0, 6, 6, 5, 5, 1,             <font class="comment">//left</font>
00029         3, 7, 7, 4, 4, 2,             <font class="comment">//right</font>
00030         6, 7, 5, 4 };          <font class="comment">//front</font>
<a name="l00031"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodeq0">00031</a> <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> OctreeNode::mColors[ 8 ] = {<a class="code" href="namespaceOgre.html#a477">green</a>, <a class="code" href="namespaceOgre.html#a477">green</a>, <a class="code" href="namespaceOgre.html#a477">green</a>, <a class="code" href="namespaceOgre.html#a477">green</a>, <a class="code" href="namespaceOgre.html#a477">green</a>, <a class="code" href="namespaceOgre.html#a477">green</a>, <a class="code" href="namespaceOgre.html#a477">green</a>, <a class="code" href="namespaceOgre.html#a477">green</a> };
00032 
<a name="l00033"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodea0">00033</a> OctreeNode::OctreeNode( <a class="code" href="classOgre_1_1SceneManager.html">SceneManager</a>* creator ) : <a class="code" href="classOgre_1_1SceneNode.html">SceneNode</a>( creator )
00034 {
00035     <a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNoden1">mOctant</a> = 0;
00036 }
00037 
<a name="l00038"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodea1">00038</a> OctreeNode::OctreeNode( <a class="code" href="classOgre_1_1SceneManager.html">SceneManager</a>* creator, <font class="keyword">const</font> <a class="code" href="classOgre_1_1String.html">String</a>&amp; name ) : <a class="code" href="classOgre_1_1SceneNode.html">SceneNode</a>( creator, name )
00039 {
00040     <a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNoden1">mOctant</a> = 0;
00041 }
00042 
<a name="l00043"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodea2">00043</a> OctreeNode::~OctreeNode()
00044 {}
<a name="l00045"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodeb1">00045</a> <font class="keywordtype">void</font> OctreeNode::_removeNodeAndChildren( )
00046 {
00047     static_cast&lt; OctreeSceneManager * &gt; ( mCreator ) -&gt; _removeOctreeNode( <font class="keyword">this</font> ); 
00048     <font class="comment">//remove all the children nodes as well from the octree.</font>
00049     ChildNodeMap::iterator it = <a class="code" href="classOgre_1_1Node.html#Ogre_1_1TagPointn5">mChildren</a>.begin();
00050     <font class="keywordflow">while</font>( it != <a class="code" href="classOgre_1_1Node.html#Ogre_1_1TagPointn5">mChildren</a>.end() )
00051     {
00052         static_cast&lt;OctreeNode *&gt;( it-&gt;second ) -&gt; <a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodeb1">_removeNodeAndChildren</a>();
00053         ++it;
00054     }
00055 }
<a name="l00056"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodea3">00056</a> <a class="code" href="classOgre_1_1Node.html">Node</a> * OctreeNode::removeChild( <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> index )
00057 {
00058     <a class="code" href="classOgre_1_1OctreeNode.html">OctreeNode</a> *on = static_cast&lt;OctreeNode* &gt;( SceneNode::removeChild( index ) );
00059     on -&gt; <a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodeb1">_removeNodeAndChildren</a>(); 
00060     <font class="keywordflow">return</font> on; 
00061 }
00062     
<a name="l00063"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodea4">00063</a> <a class="code" href="classOgre_1_1Node.html">Node</a> * OctreeNode::removeChild( <font class="keyword">const</font> <a class="code" href="classOgre_1_1String.html">String</a> &amp; name )
00064 {
00065     <a class="code" href="classOgre_1_1OctreeNode.html">OctreeNode</a> *on = static_cast&lt; OctreeNode * &gt;( SceneNode::removeChild(  name ) );
00066     on -&gt; <a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodeb1">_removeNodeAndChildren</a>( ); 
00067     <font class="keywordflow">return</font> on; 
00068 }
00069 
00070 
00071 <font class="comment">//same as SceneNode, only it doesn't care about children...</font>
<a name="l00072"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodeb0">00072</a> <font class="keywordtype">void</font> OctreeNode::_updateBounds( <font class="keywordtype">void</font> )
00073 {
00074     <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden6">mWorldAABB</a>.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa15">setNull</a>();
00075     <a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNoden0">mLocalAABB</a>.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa15">setNull</a>();
00076 
00077     <font class="comment">// Update bounds from own attached objects</font>
00078     ObjectMap::iterator i = <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden0">mObjectsByName</a>.begin();
00079     <a class="code" href="classOgre_1_1AxisAlignedBox.html">AxisAlignedBox</a> bx;
00080 
00081     <font class="keywordflow">while</font> ( i != <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden0">mObjectsByName</a>.end() )
00082     {
00083 
00084         <font class="comment">// Get local bounds of object</font>
00085         bx = i-&gt;second -&gt;getBoundingBox();
00086 
00087         <a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNoden0">mLocalAABB</a>.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa12">merge</a>( bx );
00088 
00089         <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden6">mWorldAABB</a>.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa12">merge</a>( i-&gt;second -&gt;getWorldBoundingBox(<font class="keyword">true</font>) );
00090         ++i;
00091     }
00092 
00093 
00094     <font class="comment">//update the OctreeSceneManager that things might have moved.</font>
00095     <font class="comment">// if it hasn't been added to the octree, add it, and if has moved</font>
00096     <font class="comment">// enough to leave it's current node, we'll update it.</font>
00097     <font class="keywordflow">if</font> ( ! <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden6">mWorldAABB</a>.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa16">isNull</a>() )
00098     {
00099         static_cast &lt; OctreeSceneManager * &gt; ( mCreator ) -&gt; _updateOctreeNode( <font class="keyword">this</font> );
00100     }
00101 
00102 }
00103 
<a name="l00106"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodea7">00106</a> <font class="keywordtype">bool</font> OctreeNode::_isIn( <a class="code" href="classOgre_1_1AxisAlignedBox.html">AxisAlignedBox</a> &amp;box )
00107 {
00108 
00109     <a class="code" href="classOgre_1_1Vector3.html">Vector3</a> center = <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden6">mWorldAABB</a>.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa4">getMaximum</a>().<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3a26">midPoint</a>( <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden6">mWorldAABB</a>.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa3">getMinimum</a>() );
00110 
00111     <a class="code" href="classOgre_1_1Vector3.html">Vector3</a> bmin = box.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa3">getMinimum</a>();
00112     <a class="code" href="classOgre_1_1Vector3.html">Vector3</a> bmax = box.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa4">getMaximum</a>();
00113 
00114     <font class="keywordflow">return</font> ( bmax &gt; center &amp;&amp; bmin &lt; center );
00115 
00116 }
00117 
<a name="l00119"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodea8">00119</a> <font class="keywordtype">void</font> OctreeNode::_addToRenderQueue( <a class="code" href="classOgre_1_1Camera.html">Camera</a>* cam, <a class="code" href="classOgre_1_1RenderQueue.html">RenderQueue</a> *queue )
00120 {
00121     ObjectMap::iterator mit = <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden0">mObjectsByName</a>.begin();
00122 
00123     <font class="keywordflow">while</font> ( mit != <a class="code" href="classOgre_1_1SceneNode.html#Ogre_1_1SceneNoden0">mObjectsByName</a>.end() )
00124     {
00125         <a class="code" href="classOgre_1_1MovableObject.html">MovableObject</a> * mo = mit-&gt;second;
00126 
00127         mo-&gt;<a class="code" href="classOgre_1_1MovableObject.html#Ogre_1_1MovableObjecta7">_notifyCurrentCamera</a>(cam);
00128         <font class="keywordflow">if</font> ( mo-&gt;<a class="code" href="classOgre_1_1MovableObject.html#Ogre_1_1WireBoundingBoxa23">isVisible</a>() )
00129         {
00130             mo -&gt; _updateRenderQueue( queue );
00131         }
00132 
00133         ++mit;
00134     }
00135 
00136 }
00137 
00138 
<a name="l00139"></a><a class="code" href="classOgre_1_1OctreeNode.html#Ogre_1_1OctreeNodea9">00139</a> <font class="keywordtype">void</font> OctreeNode::getRenderOperation( <a class="code" href="classOgre_1_1RenderOperation.html">RenderOperation</a>&amp; rend )
00140 {
00141 
00142     <font class="comment">/* TODO</font>
00143 <font class="comment">    rend.useIndexes = true;</font>
00144 <font class="comment">    rend.numTextureCoordSets = 0; // no textures</font>
00145 <font class="comment">    rend.vertexOptions = LegacyRenderOperation::VO_DIFFUSE_COLOURS;</font>
00146 <font class="comment">    rend.operationType = LegacyRenderOperation::OT_LINE_LIST;</font>
00147 <font class="comment">    rend.numVertices = 8;</font>
00148 <font class="comment">    rend.numIndexes = 24;</font>
00149 <font class="comment"></font>
00150 <font class="comment">    rend.pVertices = mCorners;</font>
00151 <font class="comment">    rend.pIndexes = mIndexes;</font>
00152 <font class="comment">    rend.pDiffuseColour = mColors;</font>
00153 <font class="comment"></font>
00154 <font class="comment">    const Vector3 * corners = _getLocalAABB().getAllCorners();</font>
00155 <font class="comment"></font>
00156 <font class="comment">    int index = 0;</font>
00157 <font class="comment"></font>
00158 <font class="comment">    for ( int i = 0; i &lt; 8; i++ )</font>
00159 <font class="comment">    {</font>
00160 <font class="comment">        rend.pVertices[ index ] = corners[ i ].x;</font>
00161 <font class="comment">        index++;</font>
00162 <font class="comment">        rend.pVertices[ index ] = corners[ i ].y;</font>
00163 <font class="comment">        index++;</font>
00164 <font class="comment">        rend.pVertices[ index ] = corners[ i ].z;</font>
00165 <font class="comment">        index++;</font>
00166 <font class="comment">    }</font>
00167 <font class="comment">    */</font>
00168 
00169 
00170 }
00171 }
</pre></div><p>
Copyright &copy; 2002-2003 by The OGRE Team<br />
Last modified Wed Jan 21 00:10:19 2004
</p>
</body>
</html>