///////////////////////////////////////////////////////////////////////////////////////////////////////// // SimpleGamePlugin // MyBehavior.cpp // // Code : Anael Seghezzi ///////////////////////////////////////////////////////////////////////////////////////////////////////// #include "MyBehavior.h" ///////////////////////////////////////////////////////////////////////////////////////////////////////// // Init, this part is always similar, constructor, copy constructor etc ///////////////////////////////////////////////////////////////////////////////////////////////////////// // constructor MyBehavior::MyBehavior(MObject3d * parentObject): MBehavior(parentObject), m_rotationSpeed(1) {} // copy constructor MyBehavior::MyBehavior(MyBehavior & behavior, MObject3d * parentObject): MBehavior(parentObject), m_rotationSpeed(behavior.m_rotationSpeed) {} // destructor MyBehavior::~MyBehavior(void) {} // destroy function : always similar void MyBehavior::destroy(void) { delete this; } // getNew function : always similar MBehavior * MyBehavior::getNew(MObject3d * parentObject) { return new MyBehavior(parentObject); } // getCopy function : always similar MBehavior * MyBehavior::getCopy(MObject3d * parentObject) { return new MyBehavior(*this, parentObject); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// // Variables, allow to access custom variable from script and from Maratis Editor ///////////////////////////////////////////////////////////////////////////////////////////////////////// unsigned int MyBehavior::getVariablesNumber(void){ return 1; } MVariable MyBehavior::getVariable(unsigned int id) { switch(id) { default: return MVariable("NULL", NULL, M_VARIABLE_NULL); case 0: return MVariable("rotationSpeed", &m_rotationSpeed, M_VARIABLE_FLOAT); } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// // Events ///////////////////////////////////////////////////////////////////////////////////////////////////////// // update function (called by MGame class by default) void MyBehavior::update(void) { MEngine * engine = MEngine::getInstance(); MGame * game = engine->getGame(); // check if the game is running, removing thif test will enable In-Editor update (like for the lookAt behavior) if(! game->isRunning()) return; // get the associated parent object (who is using this behavior) MObject3d * parent = getParentObject(); // lets rotate the parent object around the z axis, using our custom "rotationSpeed" variable parent->addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed); }