Index: trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp	(revision 131)
+++ trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp	(revision 135)
@@ -779,6 +779,5 @@
 void SceneManager::_renderScene(Camera* camera, Viewport* vp, bool includeOverlays)
 {
-	LogManager::getSingleton().logMessage("***********RENDER SCENE************");
-    Root::getSingleton()._setCurrentSceneManager(this);
+	Root::getSingleton()._setCurrentSceneManager(this);
     // Prep Pass for use in debug shadows
     initShadowVolumeMaterials();
@@ -4200,9 +4199,9 @@
 void SceneManager::_renderSceneNode(Camera *cam, SceneNode *node, bool leaveTransparentsInQueue)
 {
+	// delete previously rendered objects from renderqueue
+	_deleteRenderedQueueGroups(leaveTransparentsInQueue);
+
 	node->_findVisibleObjects(cam, getRenderQueue(), false, mDisplayNodes, false);
 	SceneManager::_renderVisibleObjects();
-
-	// delete all rendered objects from renderqueue
-	_deleteRenderedQueueGroups(leaveTransparentsInQueue);
 }
 //-----------------------------------------------------------------------
@@ -4248,10 +4247,9 @@
 void SceneManager::_renderMovableObject(MovableObject *mov, const bool leaveTransparentsInQueue)
 {
+	// delete previously rendered objects from renderqueue
+	_deleteRenderedQueueGroups(leaveTransparentsInQueue);
+
 	mov->_updateRenderQueue(getRenderQueue());
 	SceneManager::_renderVisibleObjects();
-	
-	// delete rendered objects from renderqueue
-	//TODO: should be first
-	_deleteRenderedQueueGroups(leaveTransparentsInQueue);
 }
 #endif //GTP_VISIBILITY_MODIFIED_OGRE
Index: trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/include/OgreOctree.h
===================================================================
--- trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/include/OgreOctree.h	(revision 104)
+++ trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/include/OgreOctree.h	(revision 135)
@@ -157,40 +157,48 @@
 
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	public:
-		/** Returns last visited frame id. */
-		int lastVisited(void);
-		/** Set to current frame id.
-        @param current frame id.
-        */
-		void setLastVisited(int frameid);
-		/** Makes this octree become visible / invisble.
-        @param visible Whether this node is to be made visible or invisible
-        */
-		void setOctreeVisible(bool visible);
-		/** Returns true if this node is marked visible, false otherwise. 
-		*/
-		bool isOctreeVisible(void);
-		/** Gets this node's parent (NULL if this is the root).
-		*/
-		Octree *getParent();
-		/** Frame id when this octree was last rendered. 
-		@return last rendered frame id
-		*/	
-		int lastRendered(void);
-		/** Sets frame id when this octree was last rendered. 
-		@param last rendered frame id
-		*/
-		void setLastRendered(int frameid);
-		/** Returns current depth of octree 
-		@return current depth
-		*/
-		int getDepth();
-
-	protected:
-
-		int mLastRendered;
-		int mLastVisited;
-		bool mVisible;
-		int mDepth;
+public:
+	/** Returns last visited frame id. */
+	int lastVisited(void);
+	/** Set to current frame id.
+    @param current frame id.
+    */
+	void setLastVisited(int frameid);
+	/** Makes this octree become visible / invisble.
+    @param visible Whether this node is to be made visible or invisible
+    */
+	void setOctreeVisible(bool visible);
+	/** Returns true if this node is marked visible, false otherwise. 
+	*/
+	bool isOctreeVisible(void);
+	/** Gets this node's parent (NULL if this is the root).
+	*/
+	Octree *getParent();
+	/** Frame id when this octree was last rendered. 
+	@return last rendered frame id
+	*/	
+	int lastRendered(void);
+	/** Sets frame id when this octree was last rendered. 
+	@param last rendered frame id
+	*/
+	void setLastRendered(int frameid);
+	/** Returns current depth of octree 
+	@return current depth
+	*/
+	int getDepth();
+	/** Returns real extent of the octree, i.e., the merged extent of the bounding boxes. */
+	AxisAlignedBox _getWorldAABB(void) const;
+
+	/** Updates bounds of real aabb of octree. */
+	void _updateBounds();
+
+protected:
+	
+	/** the real extent of the octree. */
+	AxisAlignedBox mWorldAABB;
+
+	int mLastRendered;
+	int mLastVisited;
+	bool mVisible;
+	int mDepth;
 
 #endif // GTP_VISIBILITY_MODIFIED_OGRE
Index: trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctree.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctree.cpp	(revision 115)
+++ trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctree.cpp	(revision 135)
@@ -142,4 +142,8 @@
     _ref();
 
+#ifdef GTP_VISIBILITY_MODIFIED_OGRE
+	_updateBounds();
+#endif
+
 }
 
@@ -151,4 +155,8 @@
     //update total counts.
     _unref();
+
+#ifdef GTP_VISIBILITY_MODIFIED_OGRE
+	_updateBounds();
+#endif
 }
 
@@ -165,5 +173,6 @@
         mWireBoundingBox = new WireBoundingBox();
 
-	mWireBoundingBox->setupBoundingBox(mBox);
+	//mWireBoundingBox->setupBoundingBox(mBox);
+	mWireBoundingBox->setupBoundingBox(mWorldAABB);
     return mWireBoundingBox;
 }
@@ -171,5 +180,5 @@
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
 //-----------------------------------------------------------------------	
-int Octree::lastVisited(void)
+int Octree::lastVisited()
 {
 	return mLastVisited;
@@ -181,5 +190,5 @@
 }
 //-----------------------------------------------------------------------	
-int Octree::lastRendered(void)
+int Octree::lastRendered()
 {
 	return mLastRendered;
@@ -196,5 +205,5 @@
 }
 //-----------------------------------------------------------------------	
-bool Octree::isOctreeVisible(void)
+bool Octree::isOctreeVisible()
 {
 	return mVisible;
@@ -210,4 +219,45 @@
 	return mDepth;
 }
+//-----------------------------------------------------------------------	
+AxisAlignedBox Octree::_getWorldAABB(void) const
+{
+	return mWorldAABB;
+}
+//-----------------------------------------------------------------------
+void Octree::_updateBounds()
+{
+	// Reset bounds first
+    mWorldAABB.setNull();
+
+    // Update bounds from own attached objects
+	NodeList::iterator it, it_end;
+	it_end = mNodes.end();
+
+    for (it = mNodes.begin(); it != it_end; ++it)
+    {
+        // Merge world bounds of each object
+		mWorldAABB.merge((*it)->_getWorldAABB());
+    }
+
+    // Merge with children
+	for (int i = 0; i < 2; ++i)
+    {
+        for (int j = 0; j < 2; ++j)
+        {
+            for (int k = 0; k < 2; ++k)
+            {
+                if (mChildren[i][j][k] != 0)
+				{
+					mWorldAABB.merge(mChildren[i][j][k]->_getWorldAABB());
+				}
+            }
+        }
+	}
+	// recursively update parent bounds
+	if (mParent)
+	{
+		mParent->_updateBounds();
+	}
+ }
 #endif //GTP_VISIBILITY_MODIFIED_OGRE
 }
Index: trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeSceneManager.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeSceneManager.cpp	(revision 115)
+++ trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeSceneManager.cpp	(revision 135)
@@ -428,4 +428,10 @@
             _addOctreeNode( onode, mOctree );
     }
+#ifdef GTP_VISIBILITY_MODIFIED_OGRE
+	else // still update because bounding box may be different
+	{
+		onode -> getOctant() -> _updateBounds();
+	}
+#endif // GTP_VISIBILITY_MODIFIED_OGRE
 }
 
@@ -1172,4 +1178,7 @@
 									   bool leaveTransparentsInQueue)//, bool useZPassQueue)
 {
+	// delete previously rendered objects from the render queue
+	_deleteRenderedQueueGroups(leaveTransparentsInQueue);
+
 	//Add stuff to be rendered;
     NodeList::iterator it = octant->mNodes.begin();
@@ -1211,6 +1220,4 @@
 	//-- the actual rendering
 	SceneManager::_renderVisibleObjects();
-	// delete all rendered objects from the render queue
-	_deleteRenderedQueueGroups(leaveTransparentsInQueue);
 }
 #endif // GTP_VISIBILITY_MODIFIED_OGRE
