37#ifndef EASY3D_RENDERER_KEY_FRAME_INTERPOLATOR_H
38#define EASY3D_RENDERER_KEY_FRAME_INTERPOLATOR_H
40#include <easy3d/core/types.h>
41#include <easy3d/core/signal.h>
42#include <easy3d/util/timer.h>
43#include <easy3d/renderer/frame.h>
53 class TrianglesDrawable;
251 enum Method { FITTING, INTERPOLATION };
354 void draw_path(
const Camera* camera,
float thickness = 2.0f,
const vec4& color =
vec4(1.0f, 1.0f, 0.5f, 1.0f));
377 Keyframe(
const Frame& fr,
float t);
378 const vec3& position()
const {
return p_; }
379 const quat& orientation()
const {
return q_; }
380 float time()
const {
return time_; }
381 void set_time(
float t) { time_ = t; }
382 void set_position(
const vec3& p) { p_ = p; }
383 void set_orientation(
const quat& q) { q_ = q; }
384 void flip_if_needed(
const quat& prev);
396 std::vector<Keyframe> keyframes_;
397 std::vector<Frame> interpolated_path_;
402 Method interpolation_method_;
403 float interpolation_speed_;
404 bool interpolation_started_;
405 int last_stopped_index_;
410 LinesDrawable* path_drawable_;
411 TrianglesDrawable* cameras_drawable_;
414 Signal<> frame_interpolated;
415 Signal<> interpolation_stopped;
A perspective or orthographic camera.
Definition: camera.h:116
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition: frame.h:152
A keyframe interpolator for animation generation.
Definition: key_frame_interpolator.h:104
float interpolation_speed() const
Returns the current interpolation speed.
Definition: key_frame_interpolator.h:263
const quat & keyframe_orientation(std::size_t index) const
Returns the orientation of the index-th keyframe.
Definition: key_frame_interpolator.cpp:171
virtual ~KeyFrameInterpolator()
Definition: key_frame_interpolator.cpp:69
void delete_last_keyframe()
Removes the lastly added keyframe from the path.
Definition: key_frame_interpolator.cpp:111
float duration() const
Returns the duration of the KeyFrameInterpolator path, expressed in seconds.
Definition: key_frame_interpolator.cpp:176
bool read_keyframes(const std::string &file_name)
reads camera path from a file
Definition: key_frame_interpolator.cpp:360
std::size_t number_of_keyframes() const
Returns the number of keyframes used by the interpolation.
Definition: key_frame_interpolator.h:194
void set_keyframe_orientation(std::size_t index, const quat &q)
Sets the orientation of the index-th keyframe.
Definition: key_frame_interpolator.cpp:133
const std::vector< Frame > & interpolate()
Computes and returns all the interpolated frames.
Definition: key_frame_interpolator.cpp:387
void draw_path(const Camera *camera, float thickness=2.0f, const vec4 &color=vec4(1.0f, 1.0f, 0.5f, 1.0f))
Draws the interpolated camera path.
Definition: key_frame_interpolator.cpp:302
void set_keyframe_time(std::size_t index, float t)
Sets the time corresponding to the index-th keyframe.
Definition: key_frame_interpolator.cpp:119
void set_interpolation_method(Method m)
Sets the interpolation_method().
Definition: key_frame_interpolator.cpp:197
int interpolation_period() const
Returns the current interpolation period, expressed in milliseconds.
Definition: key_frame_interpolator.h:272
KeyFrameInterpolator(Frame *frame=nullptr)
Creates a KeyFrameInterpolator, with frame as associated frame().
Definition: key_frame_interpolator.cpp:55
void start_interpolation()
Starts the interpolation process.
Definition: key_frame_interpolator.cpp:215
void set_keyframe_position(std::size_t index, const vec3 &pos)
Sets the position of the index-th keyframe.
Definition: key_frame_interpolator.cpp:126
void set_frame(Frame *const frame)
Definition: key_frame_interpolator.h:184
float lastTime() const
Returns the time corresponding to the last keyframe, expressed in seconds.
Definition: key_frame_interpolator.cpp:189
void set_interpolation_speed(float speed)
Sets the interpolation_speed().
Definition: key_frame_interpolator.cpp:203
int frame_rate() const
Returns the desired frame rate. Default value is 30.
Definition: key_frame_interpolator.h:278
Frame keyframe(std::size_t index) const
Returns the Frame associated with the keyframe at index.
Definition: key_frame_interpolator.cpp:155
const vec3 & keyframe_position(std::size_t index) const
Returns the position of the index-th keyframe.
Definition: key_frame_interpolator.cpp:166
float firstTime() const
Returns the time corresponding to the first keyframe, expressed in seconds.
Definition: key_frame_interpolator.cpp:181
void toggle_interpolation()
Calls start_interpolation() or stop_interpolation(), depending on is_interpolation_started().
Definition: key_frame_interpolator.h:326
void set_frame_rate(int fps)
Sets the desired frame rate.
Definition: key_frame_interpolator.cpp:209
void stop_interpolation()
Stops an interpolation started with start_interpolation().
Definition: key_frame_interpolator.cpp:247
bool save_keyframes(const std::string &file_name) const
saves the camera path to a file
Definition: key_frame_interpolator.cpp:340
bool is_interpolation_started() const
Returns whether the interpolation is being performed.
Definition: key_frame_interpolator.h:303
void draw_cameras(const Camera *camera, float camera_width, const vec4 &color=vec4(0.5f, 0.8f, 0.5f, 1.0f))
Draws the virtual 3D cameras for the keyframes.
Definition: key_frame_interpolator.cpp:253
Frame * frame() const
Returns the associated Frame and that is interpolated by the KeyFrameInterpolator.
Definition: key_frame_interpolator.h:180
void delete_path()
Removes all keyframes from the path.
Definition: key_frame_interpolator.cpp:140
Method interpolation_method() const
Returns the interpolation method.
Definition: key_frame_interpolator.h:256
float keyframe_time(std::size_t index) const
Returns the time corresponding to the index-th keyframe.
Definition: key_frame_interpolator.cpp:161
bool add_keyframe(const Frame &frame)
Appends a new keyframe to the path.
Definition: key_frame_interpolator.cpp:74
std::string time(double time, int num_digits)
Converts time (in millisecond) into a string with the most suitable/readable unit....
Definition: string.cpp:223
Definition: collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition: types.h:45
Quat< float > quat
A quaternion of float type.
Definition: types.h:86
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition: types.h:47