# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/ActorTreeAbstract.cpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.org                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #include <vlGraphics/ActorTreeAbstract.hpp>
    00033 #include <vlGraphics/Camera.hpp>
    00034
    00035 using namespace vl;
    00036
    00037 //-----------------------------------------------------------------------------
    00038 ActorTreeAbstract::ActorTreeAbstract()
    00039 {
    00040   VL_DEBUG_SET_OBJECT_NAME()
    00041   mActors.setAutomaticDelete(false);
    00042   mParent = NULL;
    00043 }
    00044 //-----------------------------------------------------------------------------
    00045 void ActorTreeAbstract::computeAABB()
    00046 {
    00047   AABB aabb;
    00048   for(int i=0; i<actors()->size(); ++i)
    00049   {
    00050     actors()->at(i)->computeBounds();
    00051     aabb += actors()->at(i)->boundingBox();
    00052   }
    00053   for(int i=0; i<childrenCount(); ++i)
    00054   {
    00055     if (child(i))
    00056     {
    00057       child(i)->computeAABB();
    00058       aabb += child(i)->aabb();
    00059     }
    00060   }
    00061   mAABB = aabb;
    00062 }
    00063 //-----------------------------------------------------------------------------
    00064 void ActorTreeAbstract::extractActors(ActorCollection& list)
    00065 {
    00066   for(int i=0; i<actors()->size(); ++i)
    00067     list.push_back(actors()->at(i));
    00068   for(int i=0; i<childrenCount(); ++i)
    00069     if (child(i))
    00070       child(i)->extractActors(list);
    00071 }
    00072 //-----------------------------------------------------------------------------
    00073 void ActorTreeAbstract::extractVisibleActors(ActorCollection& list, const Camera* camera, unsigned enable_mask)
    00074 {
    00075   // try to cull the whole node
    00076   if ( !camera->frustum().cull(aabb()) )
    00077   {
    00078     // cull Actor by Actor
    00079     for(int i=0; i<actors()->size(); ++i)
    00080     {
    00081       if (enable_mask & actors()->at(i)->enableMask())
    00082       {
    00083         VL_CHECK(actors()->at(i)->lod(0))
    00084         actors()->at(i)->computeBounds();
    00085         if ( !camera->frustum().cull( actors()->at(i)->boundingSphere() ) )
    00086           list.push_back(actors()->at(i));
    00087       }
    00088     }
    00089     for(int i=0; i<childrenCount(); ++i)
    00090       if (child(i))
    00091         child(i)->extractVisibleActors(list, camera);
    00092   }
    00093 }
    00094 //-----------------------------------------------------------------------------
    00095 ActorTreeAbstract* ActorTreeAbstract::eraseActor(Actor* actor)
    00096 {
    00097   int pos = actors()->find(actor);
    00098   if (pos != -1)
    00099   {
    00100     actors()->eraseAt(pos);
    00101     return this;
    00102   }
    00103   else
    00104   {
    00105     ActorTreeAbstract* node = NULL;
    00106     for(int i=0; !node && i<childrenCount(); ++i)
    00107       if (child(i))
    00108         node = child(i)->eraseActor(actor);
    00109     return node;
    00110   }
    00111 }
    00112 //-----------------------------------------------------------------------------
    00113 Actor* ActorTreeAbstract::addActor(Renderable* renderable, Effect* eff, Transform* tr)
    00114 {
    00115   ref<Actor> act = new Actor(renderable,eff,tr);
    00116   actors()->push_back( act.get() );
    00117   return act.get();
    00118 }
    00119 //-----------------------------------------------------------------------------
    00120 Actor* ActorTreeAbstract::addActor(Actor* actor)
    00121 {
    00122   actors()->push_back(actor);
    00123   return actor;
    00124 }
    00125 //-----------------------------------------------------------------------------
    00126 void ActorTreeAbstract::prepareActors(ActorCollection& actors)
    00127 {
    00128   // finds the root transforms
    00129
    00130   std::set< Transform* > root_transforms;
    00131   for(int i=0; i<(int)actors.size(); ++i)
    00132   {
    00133     for( Transform* root = actors[i]->transform(); root; root = root->parent() )
    00134       if ( !root->parent() )
    00135         root_transforms.insert(root);
    00136   }
    00137
    00138   // setup the matrices
    00139
    00140   std::set< Transform* >::iterator tra = root_transforms.begin();
    00141   while( tra != root_transforms.end() )
    00142   {
    00143     (*tra)->computeWorldMatrixRecursive();
    00144     ++tra;
    00145   }
    00146
    00147   // setup the Actor[s] bounding box and bounding sphere
    00148
    00149   for(int i=0; i<(int)actors.size(); ++i)
    00150     actors[i]->computeBounds();
    00151 }
    00152 //-----------------------------------------------------------------------------

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:35.
Permission is granted to use this page to write and publish articles regarding Visualization Library.