C:/Users/Mike/Documents/Visual Studio Projects/GameEngine/src/GraphicalComponent.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 Copyright (C) 2006 Michael Harnetty
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 -----------------------------------------------------------------------------
00019 */
00020 
00021 #include "GraphicalComponent.h"
00022 #include "PhysicsManager.h"
00023 
00024 namespace GameEngine {
00025 
00026 
00027         GraphicalComponent::GraphicalComponent( Ogre::SceneNode* rootNode )     
00028                                                                                                 :       mParentNode( rootNode ),
00029                                                                                                         mSceneManager( rootNode->getCreator() )
00030         {
00031                 
00032         }
00033 
00034         GraphicalComponent::GraphicalComponent( Ogre::SceneNode* const rootNode, Vector3& initialPos,  Quaternion& initialOri ) 
00035                                                                                                 :       mParentNode( rootNode ),
00036                                                                                                         mSceneManager( rootNode->getCreator() ),
00037                                                                                                         mInitialPos(initialPos),
00038                                                                                                         mInitialOri(initialOri)
00039         {
00040                 
00041         }
00042 
00043 
00044         GraphicalComponent::~GraphicalComponent()
00045         {
00046         }
00047 
00048 
00049         bool GraphicalComponent::init()
00050         {
00051                 assert(mParent && !isInitialised());    // Must have a parent to init, can't have already destroyed object
00052                 
00053                 GameObjectComponent::init();
00054 
00055                 EventManager::getSingletonPtr()->addListener(this->shared_from_this(), EventType("ObjectMoved"));
00056 
00057                 mSceneNode = mSceneManager->createSceneNode( mParent->getID() );
00058                 mSceneNode->setPosition(mInitialPos);
00059                 mSceneNode->setOrientation(mInitialOri);
00060 
00061                 mParentNode->addChild(mSceneNode);
00062                 return true;
00063         }
00064 
00065 
00066         void GraphicalComponent::destroy()
00067         {
00068                 //assert(isInitialised() && ! isDead());
00069 
00070                 if(mSceneNode){
00071                         mParentNode->removeAndDestroyChild( mParent->getID() );
00072                         mSceneNode = NULL;
00073                 }
00074 
00075                 EventManager::getSingletonPtr()->delListener(this->shared_from_this(), EventType("ObjectMoved"));
00076                 GameObjectComponent::destroy();
00077         }
00078 
00079 
00080         bool GraphicalComponent::handleEvent(const Event& event)
00081         {
00082                 if(!isInitialised() || isDead()) return false;
00083 
00084                 if(event.getEventType() == EventType("ObjectMoved") ){ // And object moved
00085                         PhysicsMovementEventData* e = event.getDataPtr<PhysicsMovementEventData>();
00086 
00087                         if(e->mObject == this->getParent()){ // Was it this object that moved ?
00088                                 mSceneNode->setPosition(e->mPosistion);
00089                                 mSceneNode->setOrientation(e->mOrientation.normalise());
00090                         }
00091                 }
00092 
00093                 return false; // Dont consume event
00094         }
00095 
00096 
00097         void GraphicalComponent::update(const double& dt)
00098         {
00099                 assert(isInitialised() && !isDead());
00100 
00101         }
00102 
00103 }

Generated on Thu Apr 19 09:47:02 2007 for GameEngine by  doxygen 1.5.2