Scripting : allow smoothly animating lights
This commit is contained in:
parent
953c29089e
commit
66909086fd
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
// ============================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user