diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index 213b4bc12..36821c080 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -228,6 +228,11 @@ namespace Scripting ((TrackObjectPresentationLight*)memory)->setEnergy(energy); } + void animateEnergy(float energy, float duration, /** \cond DOXYGEN_IGNORE */void *memory /** \endcond */) + { + ((TrackObjectPresentationLight*)memory)->setEnergy(energy, duration); + } + /** @} */ } @@ -358,6 +363,7 @@ namespace Scripting // Light r = engine->RegisterObjectMethod("Light", "void setEnergy(float)", asFUNCTION(Light::setEnergy), asCALL_CDECL_OBJLAST); assert(r >= 0); + r = engine->RegisterObjectMethod("Light", "void animateEnergy(float, float)", asFUNCTION(Light::animateEnergy), asCALL_CDECL_OBJLAST); assert(r >= 0); // Curve based Animation //fails due to insufficient visibility to scripts TODO : Decide whether to fix visibility or introduce wrappers diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 409deaff9..6161f4e47 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -967,6 +967,11 @@ TrackObjectPresentationLight::TrackObjectPresentationLight( { m_node = NULL; // lights require shaders to work } + + m_energy_animation_from = 0.0f; + m_energy_animation_to = 0.0f; + m_energy_animation_total_duration = 0.0f; + m_energy_animation_remaining_duration = 0.0f; } // TrackObjectPresentationLight // ---------------------------------------------------------------------------- @@ -984,6 +989,29 @@ void TrackObjectPresentationLight::setEnergy(float energy) } } // ---------------------------------------------------------------------------- +void TrackObjectPresentationLight::setEnergy(float energy, float duration) +{ + m_energy_animation_from = m_energy; + m_energy_animation_to = energy; + m_energy_animation_total_duration = duration; + m_energy_animation_remaining_duration = duration; +} +// ---------------------------------------------------------------------------- +void TrackObjectPresentationLight::update(float dt) +{ + if (m_energy_animation_remaining_duration > 0.0f) + { + m_energy_animation_remaining_duration -= dt; + if (m_energy_animation_remaining_duration < 0.0f) + m_energy_animation_remaining_duration = 0.0f; + + float ratio = m_energy_animation_remaining_duration / m_energy_animation_total_duration; + + setEnergy(m_energy_animation_from + + (m_energy_animation_to - m_energy_animation_from)*(1.0f - ratio)); + } +} +// ---------------------------------------------------------------------------- TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger( const XMLNode& xml_node) : TrackObjectPresentation(xml_node) diff --git a/src/tracks/track_object_presentation.hpp b/src/tracks/track_object_presentation.hpp index a6f7fbbca..ca4ba2b0b 100644 --- a/src/tracks/track_object_presentation.hpp +++ b/src/tracks/track_object_presentation.hpp @@ -355,11 +355,18 @@ private: float m_distance; float m_energy; + float m_energy_animation_from; + float m_energy_animation_to; + float m_energy_animation_total_duration; + float m_energy_animation_remaining_duration; + public: TrackObjectPresentationLight(const XMLNode& xml_node, scene::ISceneNode* parent); virtual ~TrackObjectPresentationLight(); void setEnergy(float energy); + void setEnergy(float energy, float duration); + virtual void update(float dt) OVERRIDE; }; // TrackObjectPresentationLight // ============================================================================