#include "GameObject.h"
GameObject::GameObject(): m_sceneMgr(0),
m_entity(0),
m_node(0),
m_name(),
m_isInitialized(false),
m_isSelected(false),
m_direction(0, 0, 0),
m_oldPosition(0, 0, 0)
{
}
void GameObject::init(Ogre::SceneManager *sceneMgr,
Ogre::String name,
Ogre::Vector3 position,
Ogre::String mesh,
Ogre::String material)
{
if(m_isInitialized)
return;
m_sceneMgr = sceneMgr;
m_isInitialized = true;
m_name = name;
m_entity = m_sceneMgr->createEntity(name, mesh);
m_node = m_sceneMgr->getRootSceneNode()->createChildSceneNode(name + "Node");
m_node->attachObject(m_entity);
m_node->setPosition(position);
m_oldPosition = position;
Ogre::AxisAlignedBox box = m_entity->getBoundingBox();
Ogre::Vector3 boxSize = box.getSize();
Ogre::Real scaleAmt = HEIGHT/boxSize.y;
m_node->scale(scaleAmt, scaleAmt, scaleAmt);
if(material != ""){
m_entity->setMaterialName(material);
}
}
GameObject::~GameObject() {
}
void GameObject::update(const Ogre::FrameEvent & evt)
{
if(!m_isInitialized){
return;
}
m_oldPosition = m_node->getPosition();
Ogre::Vector3 location = m_oldPosition + (m_direction * evt.timeSinceLastFrame);
m_node->setPosition(location);
}
void GameObject::setDirection(Ogre::Vector3 direction)
{
m_direction = direction;
}
Ogre::Vector3 & GameObject::getDirection()
{
return m_direction;
}
bool GameObject::isSelected()
{
return m_isSelected;
}
bool GameObject::isInitialized()
{
return m_isInitialized;
}
void GameObject::setSelected(bool select)
{
m_isSelected = select;
m_node->showBoundingBox(select);
}
Ogre::String GameObject::getName()
{
if(!m_isInitialized)
return "";
return m_name;
}
Ogre::String GameObject::getEntityName()
{
if(!m_isInitialized)
return "";
return m_entity->getName();
}
Ogre::String GameObject::getNodeName()
{
if(!m_isInitialized)
return "";
return m_node->getName();
}
Ogre::AxisAlignedBox GameObject::getTransformedBoundingBox()
{
if(!m_isInitialized)
return Ogre::AxisAlignedBox();
return m_node->_getWorldAABB();
}
void GameObject::stepBack(){
if(m_isInitialized)
m_node->setPosition(m_oldPosition);
}