1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | /***************************************************************************
|
---|
26 | octreenode.cpp - description
|
---|
27 | -------------------
|
---|
28 | begin : Fri Sep 27 2002
|
---|
29 | copyright : (C) 2002 by Jon Anderson
|
---|
30 | email : janders@users.sf.net
|
---|
31 |
|
---|
32 | Enhancements 2003 - 2004 (C) The OGRE Team
|
---|
33 |
|
---|
34 | ***************************************************************************/
|
---|
35 |
|
---|
36 | #include <OgreRoot.h>
|
---|
37 |
|
---|
38 | #include <OgreOctreeNode.h>
|
---|
39 | #include <OgreOctreeSceneManager.h>
|
---|
40 |
|
---|
41 | namespace Ogre
|
---|
42 | {
|
---|
43 | unsigned long green = 0xFFFFFFFF;
|
---|
44 |
|
---|
45 | unsigned short OctreeNode::mIndexes[ 24 ] = {0, 1, 1, 2, 2, 3, 3, 0, //back
|
---|
46 | 0, 6, 6, 5, 5, 1, //left
|
---|
47 | 3, 7, 7, 4, 4, 2, //right
|
---|
48 | 6, 7, 5, 4 }; //front
|
---|
49 | unsigned long OctreeNode::mColors[ 8 ] = {green, green, green, green, green, green, green, green };
|
---|
50 |
|
---|
51 | OctreeNode::OctreeNode( SceneManager* creator ) : SceneNode( creator )
|
---|
52 | {
|
---|
53 | mOctant = 0;
|
---|
54 | }
|
---|
55 |
|
---|
56 | OctreeNode::OctreeNode( SceneManager* creator, const String& name ) : SceneNode( creator, name )
|
---|
57 | {
|
---|
58 | mOctant = 0;
|
---|
59 | }
|
---|
60 |
|
---|
61 | OctreeNode::~OctreeNode()
|
---|
62 | {}
|
---|
63 | void OctreeNode::_removeNodeAndChildren( )
|
---|
64 | {
|
---|
65 | static_cast< OctreeSceneManager * > ( mCreator ) -> _removeOctreeNode( this );
|
---|
66 | //remove all the children nodes as well from the octree.
|
---|
67 | ChildNodeMap::iterator it = mChildren.begin();
|
---|
68 | while( it != mChildren.end() )
|
---|
69 | {
|
---|
70 | static_cast<OctreeNode *>( it->second ) -> _removeNodeAndChildren();
|
---|
71 | ++it;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | Node * OctreeNode::removeChild( unsigned short index )
|
---|
75 | {
|
---|
76 | OctreeNode *on = static_cast<OctreeNode* >( SceneNode::removeChild( index ) );
|
---|
77 | on -> _removeNodeAndChildren();
|
---|
78 | return on;
|
---|
79 | }
|
---|
80 | Node * OctreeNode::removeChild( Node* child )
|
---|
81 | {
|
---|
82 | OctreeNode *on = static_cast<OctreeNode* >( SceneNode::removeChild( child ) );
|
---|
83 | on -> _removeNodeAndChildren();
|
---|
84 | return on;
|
---|
85 | }
|
---|
86 |
|
---|
87 | Node * OctreeNode::removeChild( const String & name )
|
---|
88 | {
|
---|
89 | OctreeNode *on = static_cast< OctreeNode * >( SceneNode::removeChild( name ) );
|
---|
90 | on -> _removeNodeAndChildren( );
|
---|
91 | return on;
|
---|
92 | }
|
---|
93 |
|
---|
94 | //same as SceneNode, only it doesn't care about children...
|
---|
95 | void OctreeNode::_updateBounds( void )
|
---|
96 | {
|
---|
97 | mWorldAABB.setNull();
|
---|
98 | mLocalAABB.setNull();
|
---|
99 |
|
---|
100 | // Update bounds from own attached objects
|
---|
101 | ObjectMap::iterator i = mObjectsByName.begin();
|
---|
102 | AxisAlignedBox bx;
|
---|
103 |
|
---|
104 | while ( i != mObjectsByName.end() )
|
---|
105 | {
|
---|
106 |
|
---|
107 | // Get local bounds of object
|
---|
108 | bx = i->second ->getBoundingBox();
|
---|
109 |
|
---|
110 | mLocalAABB.merge( bx );
|
---|
111 |
|
---|
112 | mWorldAABB.merge( i->second ->getWorldBoundingBox(true) );
|
---|
113 | ++i;
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | //update the OctreeSceneManager that things might have moved.
|
---|
118 | // if it hasn't been added to the octree, add it, and if has moved
|
---|
119 | // enough to leave it's current node, we'll update it.
|
---|
120 | if ( ! mWorldAABB.isNull() )
|
---|
121 | {
|
---|
122 | static_cast < OctreeSceneManager * > ( mCreator ) -> _updateOctreeNode( this );
|
---|
123 | }
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|
127 | /** Since we are loose, only check the center.
|
---|
128 | */
|
---|
129 | bool OctreeNode::_isIn( AxisAlignedBox &box )
|
---|
130 | {
|
---|
131 | // Always fail if not in the scene graph
|
---|
132 | if (!mIsInSceneGraph) return false;
|
---|
133 |
|
---|
134 | Vector3 center = mWorldAABB.getMaximum().midPoint( mWorldAABB.getMinimum() );
|
---|
135 |
|
---|
136 | Vector3 bmin = box.getMinimum();
|
---|
137 | Vector3 bmax = box.getMaximum();
|
---|
138 |
|
---|
139 | return ( bmax > center && bmin < center );
|
---|
140 |
|
---|
141 | }
|
---|
142 |
|
---|
143 | /** Addes the attached objects of this OctreeScene node into the queue. */
|
---|
144 | void OctreeNode::_addToRenderQueue( Camera* cam, RenderQueue *queue, bool onlyShadowCasters )
|
---|
145 | {
|
---|
146 | ObjectMap::iterator mit = mObjectsByName.begin();
|
---|
147 |
|
---|
148 | while ( mit != mObjectsByName.end() )
|
---|
149 | {
|
---|
150 | MovableObject * mo = mit->second;
|
---|
151 |
|
---|
152 | mo->_notifyCurrentCamera(cam);
|
---|
153 | if ( mo->isVisible() &&
|
---|
154 | (!onlyShadowCasters || mo->getCastShadows()))
|
---|
155 | {
|
---|
156 | mo -> _updateRenderQueue( queue );
|
---|
157 | }
|
---|
158 |
|
---|
159 | ++mit;
|
---|
160 | }
|
---|
161 |
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | void OctreeNode::getRenderOperation( RenderOperation& rend )
|
---|
166 | {
|
---|
167 |
|
---|
168 | /* TODO
|
---|
169 | rend.useIndexes = true;
|
---|
170 | rend.numTextureCoordSets = 0; // no textures
|
---|
171 | rend.vertexOptions = LegacyRenderOperation::VO_DIFFUSE_COLOURS;
|
---|
172 | rend.operationType = LegacyRenderOperation::OT_LINE_LIST;
|
---|
173 | rend.numVertices = 8;
|
---|
174 | rend.numIndexes = 24;
|
---|
175 |
|
---|
176 | rend.pVertices = mCorners;
|
---|
177 | rend.pIndexes = mIndexes;
|
---|
178 | rend.pDiffuseColour = mColors;
|
---|
179 |
|
---|
180 | const Vector3 * corners = _getLocalAABB().getAllCorners();
|
---|
181 |
|
---|
182 | int index = 0;
|
---|
183 |
|
---|
184 | for ( int i = 0; i < 8; i++ )
|
---|
185 | {
|
---|
186 | rend.pVertices[ index ] = corners[ i ].x;
|
---|
187 | index++;
|
---|
188 | rend.pVertices[ index ] = corners[ i ].y;
|
---|
189 | index++;
|
---|
190 | rend.pVertices[ index ] = corners[ i ].z;
|
---|
191 | index++;
|
---|
192 | }
|
---|
193 | */
|
---|
194 |
|
---|
195 |
|
---|
196 | }
|
---|
197 | }
|
---|