More work on scripting Property animator
This commit is contained in:
parent
840bc3df64
commit
27290b4ffb
@ -3,14 +3,17 @@
|
||||
#include "tracks/track_object_presentation.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
AnimatedProperty::AnimatedProperty(AnimatablePropery property, double from, double to,
|
||||
AnimatedProperty::AnimatedProperty(AnimatablePropery property,
|
||||
int values_count, double* values_from, double* values_to,
|
||||
double duration, void* data)
|
||||
{
|
||||
m_property = property;
|
||||
m_value_from = from;
|
||||
m_value_to = to;
|
||||
m_remaining_time = m_total_time = duration;
|
||||
m_data = data;
|
||||
m_values_count = values_count;
|
||||
m_values_from = values_from;
|
||||
m_values_to = values_to;
|
||||
m_new_values = new double[values_count];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -26,35 +29,41 @@ bool AnimatedProperty::update(double dt)
|
||||
}
|
||||
|
||||
double ratio = 1.0 - m_remaining_time / m_total_time;
|
||||
double new_value = m_value_from + (m_value_to - m_value_from) * ratio;
|
||||
|
||||
for (int i = 0; i < m_values_count; i++)
|
||||
{
|
||||
m_new_values[i] = m_values_from[i] + (m_values_to[i] - m_values_from[i]) * ratio;
|
||||
}
|
||||
|
||||
switch (m_property)
|
||||
{
|
||||
case AnimatablePropery::AP_LIGHT_ENERGY:
|
||||
{
|
||||
TrackObjectPresentationLight* light = (TrackObjectPresentationLight*)m_data;
|
||||
light->setEnergy((float)new_value);
|
||||
light->setEnergy((float)m_new_values[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
case AnimatablePropery::FOG_START:
|
||||
case AnimatablePropery::FOG_RANGE:
|
||||
{
|
||||
Track* track = (Track*)m_data;
|
||||
track->setFogStart((float)new_value);
|
||||
break;
|
||||
}
|
||||
|
||||
case AnimatablePropery::FOG_END:
|
||||
{
|
||||
Track* track = (Track*)m_data;
|
||||
track->setFogEnd((float)new_value);
|
||||
track->setFogStart((float)m_new_values[0]);
|
||||
track->setFogEnd((float)m_new_values[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
case AnimatablePropery::FOG_MAX:
|
||||
{
|
||||
Track* track = (Track*)m_data;
|
||||
track->setFogMax((float)new_value);
|
||||
track->setFogMax((float)m_new_values[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
case AnimatablePropery::FOG_COLOR:
|
||||
{
|
||||
Track* track = (Track*)m_data;
|
||||
video::SColor color(255, (int)m_new_values[0], (int)m_new_values[1], (int)m_new_values[2]);
|
||||
track->setFogColor(color);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -18,27 +18,39 @@
|
||||
#ifndef HEADER_PROPERTY_ANIMATOR_HPP
|
||||
#define HEADER_PROPERTY_ANIMATOR_HPP
|
||||
|
||||
#include "utils/no_copy.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
|
||||
enum AnimatablePropery
|
||||
{
|
||||
AP_LIGHT_ENERGY,
|
||||
FOG_START,
|
||||
FOG_END,
|
||||
FOG_MAX
|
||||
FOG_RANGE,
|
||||
FOG_MAX,
|
||||
FOG_COLOR
|
||||
};
|
||||
|
||||
class AnimatedProperty
|
||||
class AnimatedProperty : NoCopy
|
||||
{
|
||||
AnimatablePropery m_property;
|
||||
double m_value_from;
|
||||
double m_value_to;
|
||||
int m_values_count;
|
||||
double* m_values_from;
|
||||
double* m_values_to;
|
||||
double* m_new_values;
|
||||
double m_total_time;
|
||||
double m_remaining_time;
|
||||
void* m_data;
|
||||
|
||||
public:
|
||||
AnimatedProperty(AnimatablePropery property, double from, double to, double duration, void* data);
|
||||
AnimatedProperty(AnimatablePropery property, int values_count,
|
||||
double* values_from, double* values_to,
|
||||
double duration, void* data);
|
||||
|
||||
~AnimatedProperty()
|
||||
{
|
||||
delete[] m_values_from;
|
||||
delete[] m_values_to;
|
||||
delete[] m_new_values;
|
||||
}
|
||||
|
||||
bool update(double dt);
|
||||
};
|
||||
|
@ -140,16 +140,31 @@ namespace Scripting
|
||||
PropertyAnimator* animator = PropertyAnimator::get();
|
||||
::Track* track = World::getWorld()->getTrack();
|
||||
animator->add(
|
||||
new AnimatedProperty(FOG_MAX, track->getFogMax(), maxDensity, duration, track)
|
||||
new AnimatedProperty(FOG_MAX, 1,
|
||||
new double[1] { track->getFogMax() },
|
||||
new double[1] { maxDensity }, duration, track)
|
||||
);
|
||||
animator->add(
|
||||
new AnimatedProperty(FOG_START, track->getFogStart(), start, duration, track)
|
||||
);
|
||||
animator->add(
|
||||
new AnimatedProperty(FOG_END, track->getFogEnd(), end, duration, track)
|
||||
new AnimatedProperty(FOG_RANGE, 2,
|
||||
new double[2] { track->getFogStart(), track->getFogEnd() },
|
||||
new double[2] { start, end }, duration, track)
|
||||
);
|
||||
|
||||
// TODO: animate fog color
|
||||
video::SColor color = track->getFogColor();
|
||||
animator->add(
|
||||
new AnimatedProperty(FOG_COLOR, 3,
|
||||
new double[3] {
|
||||
(double)color.getRed(),
|
||||
(double)color.getGreen(),
|
||||
(double)color.getBlue()
|
||||
},
|
||||
new double[3] {
|
||||
(double)r,
|
||||
(double)g,
|
||||
(double)b
|
||||
},
|
||||
duration, track)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,9 +265,10 @@ namespace Scripting
|
||||
{
|
||||
TrackObjectPresentationLight* light = ((TrackObjectPresentationLight*)memory);
|
||||
PropertyAnimator::get()->add(
|
||||
new AnimatedProperty(AP_LIGHT_ENERGY, light->getEnergy(), energy, duration, light)
|
||||
new AnimatedProperty(AP_LIGHT_ENERGY, 1,
|
||||
new double[1] { light->getEnergy() },
|
||||
new double[1] { energy }, duration, light)
|
||||
);
|
||||
//((TrackObjectPresentationLight*)memory)->setEnergy(energy, duration);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -566,6 +566,8 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
video::SColor getFogColor() const { return m_fog_color; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setFogColor(video::SColor& color) { m_fog_color = color; }
|
||||
// ------------------------------------------------------------------------
|
||||
video::SColor getSunColor() const { return m_sun_diffuse_color; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Whether this is an "internal" track. If so it won't be offered
|
||||
|
Loading…
Reference in New Issue
Block a user