[657] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
| 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 | #include "OgreStableHeaders.h"
|
---|
| 26 | #include "OgreSimpleRenderable.h"
|
---|
| 27 | #include "OgreException.h"
|
---|
| 28 | #include "OgreSceneNode.h"
|
---|
| 29 |
|
---|
| 30 | #include "OgreMaterialManager.h"
|
---|
| 31 |
|
---|
| 32 | namespace Ogre {
|
---|
| 33 |
|
---|
| 34 | uint SimpleRenderable::ms_uGenNameCount = 0;
|
---|
| 35 |
|
---|
| 36 | SimpleRenderable::SimpleRenderable()
|
---|
| 37 | {
|
---|
| 38 | m_matWorldTransform = Matrix4::IDENTITY;
|
---|
| 39 |
|
---|
| 40 | m_strMatName = "BaseWhite";
|
---|
| 41 | m_pMaterial = MaterialManager::getSingleton().getByName("BaseWhite");
|
---|
| 42 |
|
---|
| 43 | m_pParentSceneManager = NULL;
|
---|
| 44 |
|
---|
| 45 | mParentNode = NULL;
|
---|
| 46 | m_pCamera = NULL;
|
---|
| 47 |
|
---|
| 48 | // Generate name
|
---|
| 49 | StringUtil::StrStreamType name;
|
---|
| 50 | name << _TO_CHAR("SimpleRenderable") << ms_uGenNameCount++;
|
---|
| 51 | m_strName = name.str();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | void SimpleRenderable::setMaterial( const String& matName )
|
---|
| 55 | {
|
---|
| 56 | m_strMatName = matName;
|
---|
| 57 | m_pMaterial = MaterialManager::getSingleton().getByName(m_strMatName);
|
---|
| 58 | if (m_pMaterial.isNull())
|
---|
| 59 | OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find material " + m_strMatName,
|
---|
| 60 | "SimpleRenderable::setMaterial" );
|
---|
| 61 |
|
---|
| 62 | // Won't load twice anyway
|
---|
| 63 | m_pMaterial->load();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | const MaterialPtr& SimpleRenderable::getMaterial(void) const
|
---|
| 67 | {
|
---|
| 68 | return m_pMaterial;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void SimpleRenderable::getRenderOperation(RenderOperation& op)
|
---|
| 72 | {
|
---|
| 73 | op = mRenderOp;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | void SimpleRenderable::setRenderOperation( const RenderOperation& rend )
|
---|
| 77 | {
|
---|
| 78 | mRenderOp = rend;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | void SimpleRenderable::setWorldTransform( const Matrix4& xform )
|
---|
| 82 | {
|
---|
| 83 | m_matWorldTransform = xform;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | void SimpleRenderable::getWorldTransforms( Matrix4* xform ) const
|
---|
| 87 | {
|
---|
| 88 | *xform = m_matWorldTransform * mParentNode->_getFullTransform();
|
---|
| 89 | }
|
---|
| 90 | //-----------------------------------------------------------------------
|
---|
| 91 | const Quaternion& SimpleRenderable::getWorldOrientation(void) const
|
---|
| 92 | {
|
---|
| 93 | return mParentNode->_getDerivedOrientation();
|
---|
| 94 | }
|
---|
| 95 | //-----------------------------------------------------------------------
|
---|
| 96 | const Vector3& SimpleRenderable::getWorldPosition(void) const
|
---|
| 97 | {
|
---|
| 98 | return mParentNode->_getDerivedPosition();
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | void SimpleRenderable::_notifyCurrentCamera(Camera* cam)
|
---|
| 102 | {
|
---|
| 103 | m_pCamera = cam;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void SimpleRenderable::setBoundingBox( const AxisAlignedBox& box )
|
---|
| 107 | {
|
---|
| 108 | mBox = box;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | const AxisAlignedBox& SimpleRenderable::getBoundingBox(void) const
|
---|
| 112 | {
|
---|
| 113 | return mBox;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | void SimpleRenderable::_updateRenderQueue(RenderQueue* queue)
|
---|
| 117 | {
|
---|
| 118 | queue->addRenderable( this, mRenderQueueID, OGRE_RENDERABLE_DEFAULT_PRIORITY);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | SimpleRenderable::~SimpleRenderable()
|
---|
| 122 | {
|
---|
| 123 | }
|
---|
| 124 | //-----------------------------------------------------------------------
|
---|
| 125 | const String& SimpleRenderable::getName(void) const
|
---|
| 126 | {
|
---|
| 127 | return m_strName;
|
---|
| 128 | }
|
---|
| 129 | //-----------------------------------------------------------------------
|
---|
| 130 | const String& SimpleRenderable::getMovableType(void) const
|
---|
| 131 | {
|
---|
| 132 | static String movType = "SimpleRenderable";
|
---|
| 133 | return movType;
|
---|
| 134 | }
|
---|
| 135 | //-----------------------------------------------------------------------
|
---|
| 136 | const LightList& SimpleRenderable::getLights(void) const
|
---|
| 137 | {
|
---|
| 138 | static LightList dummyLightList;
|
---|
| 139 | // Use parent node
|
---|
| 140 | SceneNode* n = getParentSceneNode();
|
---|
| 141 | if (n)
|
---|
| 142 | return n->findLights(this->getBoundingRadius());
|
---|
| 143 | else
|
---|
| 144 | return dummyLightList;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | }
|
---|