00001 #include "Building.h"
00002 #include "Game.h"
00003
00004 #include "Level.h"
00005
00006 #include "OgreSceneManager.h"
00007 #include "OgreAxisAlignedBox.h"
00008 #include "OgreStringConverter.h"
00009
00010 using Ogre::SceneManager;
00011 using Ogre::StringConverter;
00012 using Ogre::AxisAlignedBox;
00013
00014
00015 namespace ASR
00016 {
00017 int Building::mNumBuildings = 0;
00018 const int BuildingPadding = 0;
00019
00020
00021 Building::Building( SceneNode* parentNode, String meshName, Vector3 position )
00022 {
00023 mNumBuildings++;
00024 mName = "building_" + StringConverter::toString ( mNumBuildings );
00025
00026 SceneManager* sceneMgr = Game::getSingletonPtr ()->getSceneManager ();
00027
00028 mNode = parentNode->createChildSceneNode( mName + "_node" );
00029 mEntity = sceneMgr->createEntity ( mName, meshName );
00030 mNode->attachObject( mEntity );
00031
00032 mNode->translate ( position );
00033
00034 mNode->_updateBounds ();
00035 AxisAlignedBox boundingBox = mNode->_getWorldAABB ();
00036 Level::getSingleton ().occupyRegion ( boundingBox );
00037 }
00038
00039
00040
00041 Building::~Building(void)
00042 {
00043 }
00044
00045
00046
00047 void Building::scale ( Real x, Real y, Real z )
00048 {
00049 mNode->scale ( x, y, z );
00050 }
00051
00052
00053
00054 void Building::translate ( const Vector3& vec )
00055 {
00056 Vector3 pad = Vector3(BuildingPadding, BuildingPadding, BuildingPadding );
00057
00058
00059 mNode->_updateBounds ();
00060 AxisAlignedBox boundingBox = mNode->_getWorldAABB ();
00061 boundingBox.merge ( boundingBox.getMaximum () + pad );
00062 boundingBox.merge ( boundingBox.getMinimum () - pad );
00063
00064 Level::getSingleton ().unoccupyRegion ( boundingBox );
00065
00066 mNode->translate ( vec );
00067
00068
00069 mNode->_updateBounds ();
00070 boundingBox = mNode->_getWorldAABB ();
00071 boundingBox.merge ( boundingBox.getMaximum () + pad );
00072 boundingBox.merge ( boundingBox.getMinimum () - pad );
00073 Level::getSingleton ().occupyRegion ( boundingBox );
00074 }
00075
00076
00077
00078 Vector3 Building::getPosition ()
00079 {
00080 return mNode->getPosition ();
00081 }
00082
00083
00084
00085 void Building::setPosition ( const Vector3& pos )
00086 {
00087 mNode->setPosition ( pos );
00088 }
00089
00090
00091
00092 void Building::setDirection ( const Vector3& dir )
00093 {
00094 mNode->setDirection ( dir );
00095 }
00096
00097
00098
00099 void Building::setDirection ( float x, float y, float z )
00100 {
00101 mNode->setDirection( x, y, z );
00102 }
00103 }