8 animation::animation(
double _start_time,
double _end_time, AnimationParameterMapping _parameter_mapping)
10 start_time = _start_time;
12 parameter_mapping = _parameter_mapping;
18 void animation::configure(AnimationParameterMapping _parameter_mapping,
cgv::base::base_ptr _bp)
20 parameter_mapping = _parameter_mapping;
24 void animation::set_parameter_mapping(AnimationParameterMapping _parameter_mapping)
26 parameter_mapping = _parameter_mapping;
28 bool animation::has_started(
double time)
const
30 return time >= start_time;
32 double animation::get_start_time()
const
37 bool animation::is_over(
double time)
const
39 return time >= end_time;
41 double animation::get_parameter(
double time)
const
43 double lambda = std::min(1.0, std::max(0.0, (time - start_time) / (end_time - start_time)));
44 switch (parameter_mapping) {
45 case APM_LINEAR:
return lambda;
46 case APM_SIN_SQUARED:
return pow(sin(1.570796327*lambda), 2.0);
47 case APM_CUBIC:
return lambda*lambda*(3 - 2 * lambda);
50 unsigned nr = (
int&)parameter_mapping;
51 return floor(lambda*nr + 0.5) / nr;
55 bool animation::animates(
const void* ptr)
const
57 const char* char_ptr =
reinterpret_cast<const char*
>(ptr);
58 return char_ptr >= get_ptr() && char_ptr < get_ptr() + get_value_size();
60 bool animation::overlaps(
const char* value_ptr,
size_t value_size)
const
62 if (value_ptr + value_size <= get_ptr())
64 if (get_ptr() + get_value_size() <= value_ptr)
69 bool animation::set_time(
double time)
73 bp->on_set(get_ptr());
81 return _Left->get_start_time() < _Right->get_start_time();
86 std::multiset<animation_ptr, priority> queue;
101 is_connected =
false;
104 void terminate_animations(
const char* value_ptr,
size_t value_size)
106 for (
auto i = queue.begin(); i != queue.end(); ) {
107 if ((*i)->overlaps(value_ptr, value_size)) {
120 void set_time(
double time)
122 for (
auto i = queue.begin(); i != queue.end(); ) {
123 if (!(*i)->has_started(time))
125 if ((*i)->set_time(time)) {
134 void timer_event(
double time,
double dt)
142 anim_manager.try_to_connect();
145 void add_animation(animation_ptr a_ptr,
bool terminate_other_animations)
147 if (terminate_other_animations)
148 ref_animation_manager().terminate_animations(a_ptr->get_ptr(), a_ptr->get_value_size());
149 ref_animation_manager().add_animation(a_ptr);
trigger_server_ptr get_trigger_server()
returns the currently registered trigger server
trigger & get_animation_trigger()
return the global trigger used for animation, which runs by default with 60 Hz