00001 #include "TrackControlObject.h" 00002 #include "Application.h" 00003 00004 int TrackControlObject::s_nextID = 0; 00005 00006 void TrackControlObject::setID() 00007 { 00008 m_ID = s_nextID; 00009 ++s_nextID; 00010 } 00011 00012 TrackControlObject::TrackControlObject(int _val, Ogre::Vector3 _pos, Track* _track) : SelectableObject() 00013 { 00014 setID(); 00015 setName("TrackControlObject" + Ogre::StringConverter::toString(getID())); 00016 00017 setPointID(_val); 00018 setTrack(_track); 00019 setLink(0); 00020 00021 m_controlRadius = 2.0f; 00022 00023 Ogre::SceneNode* sceneNode = _track->getSceneNode()->createChildSceneNode(m_name + "SceneNode"); 00024 setSceneNode(sceneNode); 00025 00026 // Entity call will be replaced with manual object. For now, though... 00027 Ogre::Entity* ent = _track->getSceneManager()->createEntity(m_name, _track->getSceneManager()->PT_SPHERE); 00028 sceneNode->setScale(0.005f,0.005f,0.005f); 00029 setEntity(ent); 00030 00031 sceneNode->setPosition(_pos); 00032 setInitialPosition(_pos); 00033 Application::getSingleton()->getObjectManager()->addObject(this); 00034 } 00035 00036 00037 int TrackControlObject::getPointID() const 00038 { 00039 return m_pointID; 00040 } 00041 00042 void TrackControlObject::setPointID(const int &_val) 00043 { 00044 m_pointID = _val; 00045 } 00046 00047 TrackControlObject* TrackControlObject::getLink() const 00048 { 00049 return m_link; 00050 } 00051 00052 void TrackControlObject::setLink(TrackControlObject* _val) 00053 { 00054 m_link = _val; 00055 } 00056 00057 bool TrackControlObject::move(Ogre::Real _time) 00058 { 00059 // Of course we still want to move! 00060 00061 bool ret = GameObject::move(_time); 00062 if (ret) 00063 { 00064 Ogre::Vector3 currentPos = getSceneNode()->getPosition(); 00065 // Use a squared control radius to avoid the square root operation. 00066 if (currentPos.squaredDistance(getInitialPosition()) > getControlRadiusSquared()) 00067 { 00068 Ogre::Vector3 moveVector = currentPos - getInitialPosition(); 00069 moveVector = moveVector.normalisedCopy() * getControlRadius(); 00070 getSceneNode()->setPosition(getInitialPosition() + moveVector); 00071 } 00072 00073 getTrack()->getSpline()->updatePoint(getPointID(),getSceneNode()->getPosition()); 00074 if (getLink() != 0) 00075 { 00076 getLink()->getSceneNode()->setPosition(getSceneNode()->getPosition()); 00077 getTrack()->getSpline()->updatePoint(getLink()->getPointID(),getLink()->getSceneNode()->getPosition()); 00078 } 00079 m_track->controlObjectMoved(); 00080 } 00081 return ret; 00082 } 00083 00084 Track* TrackControlObject::getTrack() const 00085 { 00086 return m_track; 00087 } 00088 00089 void TrackControlObject::setTrack(Track* _val) 00090 { 00091 m_track = _val; 00092 } 00093 00094 Ogre::Vector3 TrackControlObject::getInitialPosition() const 00095 { 00096 return m_initialPosition; 00097 } 00098 00099 void TrackControlObject::setInitialPosition(Ogre::Vector3& _val) 00100 { 00101 m_initialPosition = _val; 00102 } 00103 00104 Ogre::Real TrackControlObject::getControlRadius() const 00105 { 00106 return m_controlRadius; 00107 } 00108 00109 Ogre::Real TrackControlObject::getControlRadiusSquared() const 00110 { 00111 return (m_controlRadius * m_controlRadius); 00112 } 00113 00114 void TrackControlObject::setControlRadius(Ogre::Real& _val) 00115 { 00116 m_controlRadius = _val; 00117 } 00118