Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreMovableObject.cpp

Go to the documentation of this file.

    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-2002 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 #include "OgreStableHeaders.h"
    00026
    00027 #include "OgreMovableObject.h"
    00028 #include "OgreSceneNode.h"
    00029 #include "OgreTagPoint.h"
    00030 #include "OgreLight.h"
    00031 #include "OgreEntity.h"
    00032
    00033 namespace Ogre {
    00034
    00035     //-----------------------------------------------------------------------
    00036     MovableObject::MovableObject()
    00037     {
    00038         mParentNode = 0;
    00039         mVisible = true;
    00040         mUserObject = 0;
    00041         mRenderQueueID = RENDER_QUEUE_MAIN;
    00042         mRenderQueueIDSet = false;
    00043         mQueryFlags = 0xFFFFFFFF;
    00044         mWorldAABB.setNull();
    00045         mParentIsTagPoint = false;
    00046         mCastShadows = true;
    00047     }
    00048     //-----------------------------------------------------------------------
    00049     MovableObject::~MovableObject()
    00050     {
    00051         if (mParentNode)
    00052         {
    00053             // detach from parent
    00054             if (mParentIsTagPoint)
    00055             {
    00056                 // May be we are a lod entity which not in the parent entity child object list,
    00057                 // call this method could safely ignore this case.
    00058                 static_cast<TagPoint*>(mParentNode)->getParentEntity()->detachObjectFromBone(this);
    00059             }
    00060             else
    00061             {
    00062                 // May be we are a lod entity which not in the parent node child object list,
    00063                 // call this method could safely ignore this case.
    00064                 static_cast<SceneNode*>(mParentNode)->detachObject(this);
    00065             }
    00066         }
    00067     }
    00068     //-----------------------------------------------------------------------
    00069     void MovableObject::_notifyAttached(Node* parent, bool isTagPoint)
    00070     {
    00071         mParentNode = parent;
    00072         mParentIsTagPoint = isTagPoint;
    00073     }
    00074     //-----------------------------------------------------------------------
    00075     Node* MovableObject::getParentNode(void) const
    00076     {
    00077         return mParentNode;
    00078     }
    00079     //-----------------------------------------------------------------------
    00080     SceneNode* MovableObject::getParentSceneNode(void) const
    00081     {
    00082         if (mParentIsTagPoint)
    00083         {
    00084             TagPoint* tp = static_cast<TagPoint*>(mParentNode);
    00085             return tp->getParentEntity()->getParentSceneNode();
    00086         }
    00087         else
    00088         {
    00089             return static_cast<SceneNode*>(mParentNode);
    00090         }
    00091     }
    00092     //-----------------------------------------------------------------------
    00093     bool MovableObject::isAttached(void) const
    00094     {
    00095         return (mParentNode != 0);
    00096
    00097     }
    00098     //-----------------------------------------------------------------------
    00099     void MovableObject::setVisible(bool visible)
    00100     {
    00101         mVisible = visible;
    00102     }
    00103     //-----------------------------------------------------------------------
    00104     bool MovableObject::isVisible(void) const
    00105     {
    00106         return mVisible;
    00107
    00108     }
    00109     //-----------------------------------------------------------------------
    00110     void MovableObject::setRenderQueueGroup(RenderQueueGroupID queueID)
    00111     {
    00112         mRenderQueueID = queueID;
    00113         mRenderQueueIDSet = true;
    00114     }
    00115     //-----------------------------------------------------------------------
    00116     RenderQueueGroupID MovableObject::getRenderQueueGroup(void) const
    00117     {
    00118         return mRenderQueueID;
    00119     }
    00120     //-----------------------------------------------------------------------
    00121     Matrix4 MovableObject::_getParentNodeFullTransform(void) const
    00122     {
    00123
    00124         if(mParentNode)
    00125         {
    00126             // object attached to a sceneNode
    00127             return mParentNode->_getFullTransform();
    00128         }
    00129         // fallback
    00130         return Matrix4::IDENTITY;
    00131     }
    00132     //-----------------------------------------------------------------------
    00133     const AxisAlignedBox& MovableObject::getWorldBoundingBox(bool derive) const
    00134     {
    00135         if (derive)
    00136         {
    00137             mWorldAABB = this->getBoundingBox();
    00138             mWorldAABB.transform(_getParentNodeFullTransform());
    00139         }
    00140
    00141         return mWorldAABB;
    00142
    00143     }
    00144     //-----------------------------------------------------------------------
    00145     const Sphere& MovableObject::getWorldBoundingSphere(bool derive) const
    00146     {
    00147         if (derive)
    00148         {
    00149             mWorldBoundingSphere.setRadius(getBoundingRadius());
    00150             mWorldBoundingSphere.setCenter(mParentNode->_getDerivedPosition());
    00151         }
    00152         return mWorldBoundingSphere;
    00153     }
    00154
    00155     //-----------------------------------------------------------------------
    00156     const AxisAlignedBox& MovableObject::getLightCapBounds(void) const
    00157     {
    00158         // Same as original bounds
    00159         return getWorldBoundingBox();
    00160     }
    00161     //-----------------------------------------------------------------------
    00162     const AxisAlignedBox& MovableObject::getDarkCapBounds(const Light& light, Real extrusionDist) const
    00163     {
    00164         // Extrude own light cap bounds
    00165         mWorldDarkCapBounds = getLightCapBounds();
    00166         this->extrudeBounds(mWorldDarkCapBounds, light.getAs4DVector(),
    00167             extrusionDist);
    00168         return mWorldDarkCapBounds;
    00169
    00170     }
    00171     //-----------------------------------------------------------------------
    00172     Real MovableObject::getPointExtrusionDistance(const Light* l) const
    00173     {
    00174         if (mParentNode)
    00175         {
    00176             return getExtrusionDistance(mParentNode->_getDerivedPosition(), l);
    00177         }
    00178         else
    00179         {
    00180             return 0;
    00181         }
    00182     }
    00183
    00184
    00185 }
    00186

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:35 2004