5#ifndef _USE_MATH_DEFINES
6 #define _USE_MATH_DEFINES 1
10#include <cgv/data/ref_ptr.h>
11#include <cgv/base/base.h>
12#include <cgv/math/geom.h>
13#include <cgv/gui/trigger.h>
20 class CGV_API animation;
24 enum AnimationParameterMapping
34 AnimationParameterMapping parameter_mapping;
38 virtual void set_value(
double time) = 0;
40 animation(
double _start_time,
double _end_time, AnimationParameterMapping _parameter_mapping = APM_LINEAR);
44 void set_parameter_mapping(AnimationParameterMapping _parameter_mapping);
45 double get_start_time()
const;
46 bool has_started(
double time)
const;
47 bool is_over(
double time)
const;
48 double get_parameter(
double time)
const;
49 bool animates(
const void* ptr)
const;
50 bool overlaps(
const char* value_ptr,
size_t value_size)
const;
51 virtual char* get_ptr()
const = 0;
52 virtual size_t get_value_size()
const = 0;
53 bool set_time(
double time);
56 extern CGV_API
void add_animation(
animation_ptr a_ptr,
bool terminate_other_animations =
true);
67 char* get_ptr()
const {
return reinterpret_cast<char*
>(value_ptr); }
68 size_t get_value_size()
const {
return sizeof(T); }
70 value_animation(T& value,
const T& _end_value,
double _start_time,
double _end_time, AnimationParameterMapping _parameter_mapping = APM_SIN_SQUARED) :
71 animation(_start_time, _end_time, _parameter_mapping), value_ptr(&value), start_value(value), end_value(_end_value)
79 void set_value(
double time) {
80 double lambda = this->get_parameter(time);
81 *this->value_ptr = (T)(1.0 - lambda)*this->start_value + (T)lambda*this->end_value;
84 linear_blend_animation(T& value,
const T& _end_value,
double _start_time,
double _end_time, AnimationParameterMapping _parameter_mapping = APM_SIN_SQUARED) :
93 void set_value(
double time) {
94 double lambda = this->get_parameter(time);
95 *this->value_ptr = pow(this->start_value,(1.0 - lambda))*pow(this->end_value, lambda);
98 geometric_blend_animation(T& value,
const T& _end_value,
double _start_time,
double _end_time, AnimationParameterMapping _parameter_mapping = APM_SIN_SQUARED) :
103 template <
typename T>
108 void set_value(
double time) {
109 double lambda = this->get_parameter(time);
110 *this->value_ptr = pow(this->start_value, (1.0 - lambda))*pow(this->end_value, lambda);
113 slerp_animation(T& value,
const T& _end_value,
double _start_time,
double _end_time, AnimationParameterMapping _parameter_mapping = APM_LINEAR) :
116 Omega = acos(dot(this->start_value, this->end_value) / sqrt(dot(this->start_value,this->start_value)*dot(this->end_value,this->end_value)));
121 template <
typename T>
128 void set_value(
double time) {
129 double lambda = this->get_parameter(time);
130 *this->value_ptr = cgv::math::rotate(this->start_value, axis, lambda * angle);
139 compute_rotation_axis_and_angle_from_vector_pair(this->start_value, this->end_value, axis, angle);
144 template <
typename T>
145 animation_ptr animate_with_linear_blend(T& value,
const T& target_value,
double duration_sec,
double delay_sec = 0.0f,
bool terminate_other_animations =
true)
149 add_animation(a_ptr, terminate_other_animations);
153 template <
typename T>
154 animation_ptr animate_with_geometric_blend(T& value,
const T& target_value,
double duration_sec,
double delay_sec = 0.0f,
bool terminate_other_animations =
true)
157 animation_ptr a_ptr(
new geometric_blend_animation<T>(value, target_value, time + delay_sec, time + duration_sec + delay_sec));
158 add_animation(a_ptr, terminate_other_animations);
162 template <
typename T>
163 animation_ptr animate_with_slerp(T& value,
const T& target_value,
double duration_sec,
double delay_sec = 0.0f,
bool terminate_other_animations =
true)
166 animation_ptr a_ptr(
new slerp_animation<T>(value, target_value, time + delay_sec, time + duration_sec + delay_sec));
167 add_animation(a_ptr, terminate_other_animations);
170 template <
typename T>
174 animation_ptr a_ptr(
new rotation_animation<T>(value, target_value, time + delay_sec, time + duration_sec + delay_sec));
175 add_animation(a_ptr, terminate_other_animations);
178 template <
typename T>
182 animation_ptr a_ptr(
new rotation_animation<T>(value, axis, angle, time + delay_sec, time + duration_sec + delay_sec));
183 add_animation(a_ptr, terminate_other_animations);
189#include <cgv/config/lib_end.h>
if you derive your class from this class, a ref_ptr will do reference counting in the inhereted ref_c...
reference counted pointer, which can work together with types that are derived from ref_counted,...
static double get_current_time()
return the current time
A vector with zero based index.