From f0622f425dec0b3e34944ad685e84a4f151bdc87 Mon Sep 17 00:00:00 2001 From: Sachith Hasaranga Seneviratne Date: Mon, 16 Jun 2014 20:42:48 +0530 Subject: [PATCH] Added pausing capabilities to curve based (IPO) animations, bound ThreeDanimation class to scripts as type Animator --- data/scripts/haybail.as | 2 ++ src/animations/three_d_animation.cpp | 4 ++++ src/animations/three_d_animation.hpp | 3 +++ src/scriptengine/script_track.cpp | 12 +++++++++++- src/tracks/track_object.hpp | 5 +++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/data/scripts/haybail.as b/data/scripts/haybail.as index 341ebe435..457498e8f 100644 --- a/data/scripts/haybail.as +++ b/data/scripts/haybail.as @@ -12,5 +12,7 @@ void onTrigger() PhysicalObject @haybail = t_obj.getPhysicalObject(); haybail.disable(); Mesh @haybailMesh = t_obj.getMesh(); + Animator @haybailAnimator = t_obj.getAnimator(); + haybailAnimator.setPaused(true); //if (haybail.isFlattener())squashKart(0,35.0); } diff --git a/src/animations/three_d_animation.cpp b/src/animations/three_d_animation.cpp index 38853540f..26f490425 100644 --- a/src/animations/three_d_animation.cpp +++ b/src/animations/three_d_animation.cpp @@ -40,6 +40,7 @@ ThreeDAnimation::ThreeDAnimation(const XMLNode &node, TrackObject* object) : Ani { m_object = object; + m_is_paused = false; m_crash_reset = false; m_explode_kart = false; m_flatten_kart = false; @@ -77,6 +78,9 @@ void ThreeDAnimation::update(float dt) Vec3 xyz = m_object->getPosition(); Vec3 scale = m_object->getScale(); + //make the object think no time has passed to pause it's animation + if (m_is_paused)dt = 0; + AnimationBase::update(dt, &xyz, &m_hpr, &scale); //updates all IPOs //m_node->setPosition(xyz.toIrrVector()); //m_node->setScale(scale.toIrrVector()); diff --git a/src/animations/three_d_animation.hpp b/src/animations/three_d_animation.hpp index 451ed2a82..8d8bfe5e1 100644 --- a/src/animations/three_d_animation.hpp +++ b/src/animations/three_d_animation.hpp @@ -56,6 +56,8 @@ private: bool m_flatten_kart; + /** True if animation is currently paused by scripts */ + bool m_is_paused; /** We have to store the rotation value as computed in blender, since * irrlicht uses a different order, so for rotation animations we * can not use the value returned by getRotation from a scene node. */ @@ -78,6 +80,7 @@ public: bool isCrashReset() const { return m_crash_reset; } bool isExplodeKartObject() const { return m_explode_kart; } bool isFlattenKartObject() const { return m_flatten_kart; } + void setPaused(bool mode){ m_is_paused = mode; } }; // ThreeDAnimation #endif diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index 35cb6f4ed..58ce65a2b 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -24,7 +24,8 @@ #include "tracks/track_object_manager.hpp" #include "tracks/track_object.hpp" #include "tracks/track.hpp" -#include //debug +#include "animations/three_d_animation.hpp" + namespace Scripting { @@ -48,6 +49,10 @@ namespace Scripting { ((PhysicalObject*)(memory))->removeBody(); } + void setPaused(bool mode, void *memory) + { + ((ThreeDAnimation*)(memory))->setPaused(mode); + } void getTrackObject(asIScriptGeneric *gen) { std::string *str = (std::string*)gen->GetArgAddress(0); @@ -92,6 +97,11 @@ namespace Scripting r = engine->RegisterObjectMethod("PhysicalObject", "void disable()", asFUNCTION(disable), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectType("Mesh", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); r = engine->RegisterObjectMethod("TrackObject", "Mesh @getMesh()", asMETHOD(TrackObject, getMesh), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectType("Animator", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "Animator @getAnimator()", asMETHOD(TrackObject, getAnimatorForScript), asCALL_THISCALL); assert(r >= 0); + //fails due to insufficient visibility to scripts TODO : Decide whether to fix visibility or introduce wrappers + //r = engine->RegisterObjectMethod("Animator", "void setPaused(bool mode)", asMETHOD(ThreeDAnimation, setPaused), asCALL_THISCALL); assert(r >= 0); + r = engine->RegisterObjectMethod("Animator", "void setPaused(bool mode)", asFUNCTION( setPaused ), asCALL_CDECL_OBJLAST); assert(r >= 0); } diff --git a/src/tracks/track_object.hpp b/src/tracks/track_object.hpp index b73e0a5e3..e469e0eff 100644 --- a/src/tracks/track_object.hpp +++ b/src/tracks/track_object.hpp @@ -28,6 +28,7 @@ #include "utils/no_copy.hpp" #include "utils/vec3.hpp" #include +#include "animations/three_d_animation.hpp" class XMLNode; class ThreeDAnimation; @@ -146,6 +147,10 @@ public: ThreeDAnimation* getAnimator() { return m_animator; } const ThreeDAnimation* getAnimator() const { return m_animator; } + //Due to above overload AngelScript cannot decide which function to bind + ThreeDAnimation* getAnimatorForScript() { return m_animator; } + + void setPaused(bool mode){ m_animator->setPaused(mode); } const core::vector3df& getPosition() const; const core::vector3df getAbsolutePosition() const;