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

OgreSubEntity.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 #include "OgreSubEntity.h"
00027 
00028 #include "OgreEntity.h"
00029 #include "OgreSceneManager.h"
00030 #include "OgreMaterialManager.h"
00031 #include "OgreSubMesh.h"
00032 #include "OgreTagPoint.h"
00033 #include "OgreLogManager.h"
00034 
00035 namespace Ogre {
00036     //-----------------------------------------------------------------------
00037     SubEntity::SubEntity ()
00038     {
00039         mpMaterial = static_cast<Material*>(MaterialManager::getSingleton().getByName("BaseWhite"));
00040         mMaterialLodIndex = 0;
00041         mRenderDetail = SDL_SOLID;
00042     }
00043     //-----------------------------------------------------------------------
00044     SubMesh* SubEntity::getSubMesh(void)
00045     {
00046         return mSubMesh;
00047     }
00048     //-----------------------------------------------------------------------
00049     const String& SubEntity::getMaterialName(void) const
00050     {
00051         return mMaterialName;
00052     }
00053     //-----------------------------------------------------------------------
00054     void SubEntity::setMaterialName( const String& name)
00055     {
00056 
00057         //String oldName = mMaterialName;
00058         mMaterialName = name;
00059         // Update SceneManager re material change
00060         //mParentEntity->mCreatorSceneManager->_notifyMaterialUsage(oldName, mMaterialName, this);
00061         mpMaterial = (Material*)MaterialManager::getSingleton().getByName(mMaterialName);
00062 
00063         if (!mpMaterial)
00064         {
00065             LogManager::getSingleton().logMessage("Can't assign material " + name + 
00066                 " to SubEntity of " + mParentEntity->getName() + " because this "
00067                 "Material does not exist. Have you forgotten to define it in a "
00068                 ".material script?");
00069             mpMaterial = (Material*)MaterialManager::getSingleton().getByName("BaseWhite");
00070         }
00071         // Ensure new material loaded (will not load again if already loaded)
00072         mpMaterial->load();
00073 
00074 
00075     }
00076     //-----------------------------------------------------------------------
00077     Material* SubEntity::getMaterial(void) const
00078     {
00079         return mpMaterial;
00080     }
00081     //-----------------------------------------------------------------------
00082     Technique* SubEntity::getTechnique(void) const
00083     {
00084         return mpMaterial->getBestTechnique(mMaterialLodIndex);
00085     }
00086     //-----------------------------------------------------------------------
00087     void SubEntity::getRenderOperation(RenderOperation& op)
00088     {
00089         // Use LOD
00090         mSubMesh->_getRenderOperation(op, mParentEntity->mMeshLodIndex);
00091     }
00092     //-----------------------------------------------------------------------
00093     void SubEntity::getWorldTransforms(Matrix4* xform) const
00094     {
00095         if (!mParentEntity->mNumBoneMatrices)
00096         {
00097             *xform = mParentEntity->_getParentNodeFullTransform();
00098         }
00099         else
00100         {
00101             // Bones, use cached matrices built when Entity::_updateRenderQueue was called
00102             int i;
00103             for (i = 0; i < mParentEntity->mNumBoneMatrices; ++i)
00104             {
00105                 *xform = mParentEntity->mBoneMatrices[i];
00106                 ++xform;
00107             }
00108         }
00109     }
00110     //-----------------------------------------------------------------------
00111     const Quaternion& SubEntity::getWorldOrientation(void) const
00112     {
00113         return mParentEntity->mParentNode->_getDerivedOrientation();
00114     }
00115     //-----------------------------------------------------------------------
00116     const Vector3& SubEntity::getWorldPosition(void) const
00117     {
00118         return mParentEntity->mParentNode->_getDerivedPosition();
00119     }
00120 
00121     //-----------------------------------------------------------------------
00122     unsigned short SubEntity::getNumWorldTransforms(void) const
00123     {
00124         if (!mParentEntity->mNumBoneMatrices)
00125             return 1;
00126         else
00127             return mParentEntity->mNumBoneMatrices;
00128     }
00129     //-----------------------------------------------------------------------
00130     Real SubEntity::getSquaredViewDepth(const Camera* cam) const
00131     {
00132         Node* n = mParentEntity->getParentNode();
00133         assert(n);
00134         return n->getSquaredViewDepth(cam);
00135     }
00136     //-----------------------------------------------------------------------
00137     bool SubEntity::getNormaliseNormals(void) const
00138     {
00139         return mParentEntity->mNormaliseNormals;
00140     }
00141     //-----------------------------------------------------------------------
00142     const LightList& SubEntity::getLights(void) const
00143     {
00144         Node* n = mParentEntity->getParentNode();
00145         assert(n);
00146         return n->getLights();
00147     }
00148 
00149 }

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:29 2004