Tucano
0.1
A library for rapid prototyping with modern OpenGL and GLSL
|
Path class, defines control points and a cubic Bezier approximation for defining a smooth path from key frames. More...
#include <path.hpp>
Public Member Functions | |
Path () | |
Default constructor. More... | |
void | reset (void) |
Resets the path. More... | |
void | initOpenGLMatrices (void) |
Initializes the view and projection matrices. They are all initialized as Identity matrices, but view is then translated by the defaultTranslation vector. More... | |
void | initialize (string shader_dir="../effects/shaders/") |
Initializes shaders. More... | |
void | fillVertexData (void) |
Fill the vertices array. More... | |
void | addKeyPosition (const Tucano::Camera &camera, float interval=0.0) |
Add key position The camera will pause at this position for given number of steps, default is zero. More... | |
void | addKeyDirection (const Eigen::Quaternion< float > q) |
Add an optial key direction Key directions are interpolated via SLERP and not SQUAD This is specially useful for interpolating a light direction together with the camera path Key directions should be always allocated together with a key position to work properly. More... | |
void | render (const Tucano::Camera &camera, const Tucano::Camera &light) |
Renders smooth path End points for each Beziér is passed as line_strip and control points as vertex attributes Inside geometry shader each Beziér segment is approximate by linear segments. More... | |
int | curveSegment (float t) |
returns the segment given a time t in [0,1] for the whole path More... | |
float | toLocalParameter (float t) |
converts global parameter t to a local t inside a segment More... | |
Eigen::Vector4f | pointOnSegment (float t, int segment) |
Returns a point at time t on a given Beziér segment. More... | |
Eigen::Vector4f | pointOnPath (float global_t) |
compute point on path given t in [0,1] More... | |
Eigen::Quaternionf | logQuaternion (const Eigen::Quaternionf &qi) |
Returns the log of a quaternion log(q) q in the form [cos(a), sin(a) v], log(q) = [0, a v]. More... | |
Eigen::Quaternionf | expQuaternion (const Eigen::Quaternionf &q) |
Returns the exp of a quaternion exp(q) q in the form [0, a v], exp(q) = [cos(a), sin(a) v] with |v|=1. More... | |
Eigen::Quaternionf | squad (int seg, float t) |
SQUAD - Spherical and Quadrangle quaternion interpolation. More... | |
Eigen::Affine3f | cameraAtTime (float global_t) |
return a view matrix at a given path parameter More... | |
Eigen::Quaternion< float > | directionAtTime (float global_t) |
return a direction at a given path parameter More... | |
Eigen::Affine3f | cameraAtCurrentTime (void) |
Return the view matrix at current animation time. More... | |
Eigen::Quaternion< float > | directionAtCurrentTime (void) |
Return the direction at current animation time. More... | |
float | arcLengthToTime (float s) |
Converts from given arc length to time parameter. More... | |
void | toggleAnimation (void) |
Toggle animation. More... | |
void | setLoopAnimation (bool f) |
Set loop animation flag. More... | |
void | toggleDrawControlPoints (void) |
Toggle render control points. More... | |
void | toggleDrawQuaternions (void) |
Toggle render control quaternions. More... | |
bool | isAnimating (void) |
Returns if Animation is running or not. More... | |
void | stepForward (void) |
Move animation forward one step. More... | |
void | stepBackward (void) |
Move animation backward one step. More... | |
void | startAnimation (void) |
Start animation following camera path. More... | |
void | stopAnimation (void) |
Stop animation. More... | |
void | resetAnimation (void) |
Resets animation to first key position. More... | |
float | animTime (void) |
Return current animation time. More... | |
float | animSpeed (void) |
Return animation speed where 1 covers the whole curve in one step. More... | |
void | setAnimSpeed (float as) |
Sets the animation speed. More... | |
void | computeControlQuaternions (void) |
Compute control points for SQUAD. More... | |
void | computeInnerControlPoints (void) |
Compute inner control points from key positions. More... | |
void | computeArcLength (void) |
Compute an approximation of the arclength. More... | |
void | printDebugInfo (void) |
void | writeToFile (const string filename) |
void | loadFromFile (const string filename) |
Public Member Functions inherited from Tucano::Camera | |
void | resetViewMatrix (void) |
Reset view matrix. More... | |
void | resetProjectionMatrix (void) |
Reset projection matrix. More... | |
void | reset (void) |
Resets trackball to initial position and orientation. More... | |
Eigen::Vector3f | getCenter (void) const |
Returns the center of the camera in world space. More... | |
void | getViewMatrix (GLdouble *matrix) |
Return the modelview matrix as a GLdouble array. More... | |
void | getProjectionMatrix (GLdouble *matrix) |
Return the projection matrix as a GLdouble array. More... | |
Eigen::Vector3f | projectPoint (const Eigen::Vector4f &pt, Eigen::Vector4f &viewport) |
Returns screen space coordinates of a 3D point. More... | |
Eigen::Affine3f | getViewMatrix (void) const |
Returns the view matrix as an Affine 3x3 matrix. More... | |
Eigen::Affine3f * | viewMatrix (void) |
Returns a pointer to the view matrix as an Affine 3x3 matrix. More... | |
Eigen::Matrix4f | getProjectionMatrix (void) const |
Returns the view matrix as an 4x4 matrix. More... | |
Eigen::Matrix4f * | projectionMatrix (void) |
Returns a pointer to the projection matrix as an 4x4 matrix. More... | |
Eigen::Matrix3f | getRotationMatrix (void) const |
Returns a 3x3 matrix containing only the rotation of the view matrix. More... | |
Eigen::Vector3f | getTranslationMatrix (void) const |
Returns the translation part of the view matrix as a vector. More... | |
float | getPerspectiveScale (void) const |
Returns the perspective scale. More... | |
Eigen::Vector4f | getViewport (void) const |
Returns the viewport coordinates. More... | |
Eigen::Vector2i | getViewportSize (void) const |
Returns the dimensions of the viewport. More... | |
float | getViewportAspectRatio (void) const |
Returns the viewport aspect ratio. More... | |
void | setViewport (const Eigen::Vector4f &vp) |
Sets the viewport coordinates. More... | |
void | setViewport (const Eigen::Vector2i &vp) |
void | setViewport (const Eigen::Vector2f &vp) |
Sets the viewport coordinates considering that the minimum coordinates are zero. More... | |
void | setProjectionMatrix (const Eigen::Matrix4f &mat) |
Sets the projection matrix from a given 4x4 matrix. More... | |
void | setViewMatrix (const Eigen::Affine3f &mat) |
Sets the view matrix from a given an affine 3x3 matrix. More... | |
float | getNearPlane (void) const |
Returns near plane value. More... | |
float | getFarPlane (void) const |
Returns far plane value. More... | |
~Camera () | |
Default destructor. More... | |
float | getFovy (void) const |
Returns current field of view angle in y axis. More... | |
Camera (void) | |
Default constructor. More... | |
Eigen::Matrix4f | setPerspectiveMatrix (float fy, float in_aspect_ratio, float in_near_plane, float in_far_plane) |
Sets the projection matrix as a perspective matrix. More... | |
void | changeFovy (float new_fovy) |
Changes the fovy and computes new perspective projection matrix. More... | |
Eigen::Matrix4f | setOrthographicMatrix (float left, float right, float bottom, float top, float near_plane, float far_plane) |
Sets the projection matrix as a orthographic matrix. More... | |
void | incrementFov (float inc) |
Increases the fov of the perspective matrix by a given increment. More... | |
void | translate (const Eigen::Vector3f &translation) |
Translates the view matrix by a given vector. More... | |
void | rotate (const Eigen::Quaternion< float > &rotation) |
Rotate the view matrix by a given quaternion. More... | |
void | scale (const Eigen::Vector3f &scale_factors) |
Scales the view matrix by given factors. More... | |
void | scale (float scale_factor) |
Scales the view matrix by given factor in all axis. More... | |
Private Attributes | |
float | anim_speed = 0.025 |
Movement speed, arc length increment for each animation step. More... | |
float | anim_time = 0.0 |
Animation time. More... | |
bool | animating = false |
Start/stop animation. More... | |
bool | loop_animation = false |
Flag to loop animation. More... | |
bool | draw_control_points = false |
Flag to render control points. More... | |
bool | draw_quaternions = false |
Flag to render quaternions at key positions. More... | |
vector< Eigen::Vector4f > | key_positions |
Camera position at each Key frames. More... | |
vector< float > | key_intervals |
Steps to stay paused at a given key position, usually zero. More... | |
vector< Eigen::Vector4f > | control_points_1 |
First control point between two key positions. More... | |
vector< Eigen::Vector4f > | control_points_2 |
Second control point between two key positions. More... | |
vector< vector< float > > | arc_lengths |
Arc-length approximation splitting each Beziér segment into linear segments. More... | |
float | path_length |
Total path length. More... | |
vector< Eigen::Quaternion< float > > | key_quaternions |
Rotation state at each key frame. More... | |
vector< Eigen::Quaternion< float > > | control_quaternions |
Control quaternions for SQUAD. More... | |
vector< Eigen::Quaternion< float > > | key_directions |
Rotation only interpolation (via Slerp) useful for accompaning light direction for example. More... | |
Mesh | curve |
Mesh | control_segments |
Shapes::Sphere | sphere |
A sphere to visually represent the path's key positions. More... | |
Shapes::CoordinateAxes | axes |
Coordinate axes for visualizing quaternions at key positions. More... | |
Shader | camerapath_shader |
Path shader, used for rendering the curve. More... | |
Shader | phong_shader |
To render simple lines. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from Tucano::Camera | |
static Eigen::Matrix4f | createPerspectiveMatrix (float fy, float in_aspect_ratio, float in_near_plane, float in_far_plane) |
Returns a perspective projection matrix with the given parameters. More... | |
static Eigen::Matrix4f | createOrthographicMatrix (float left, float right, float bottom, float top, float near_plane, float far_plane) |
Returns an orthographic projection matrix with the given parameters. More... | |
Protected Attributes inherited from Tucano::Camera | |
Eigen::Matrix4f | projection_matrix |
Projection, or intrinsic, matrix. More... | |
Eigen::Affine3f | view_matrix |
View, or extrinsic, matrix. More... | |
Eigen::Vector4f | viewport |
Viewport dimensions [minX, minY, width, height]. More... | |
Eigen::Affine3f | default_view |
float | near_plane |
Near plane used for projection matrix. More... | |
float | far_plane |
Far plane used for projection matrix. More... | |
float | frustum_left |
Frustum left dimension. More... | |
float | frustum_right |
Frustum right dimension. More... | |
float | frustum_top |
Frustum top dimension. More... | |
float | frustum_bottom |
Frustum bottom dimension. More... | |
float | aspect_ratio |
Aspect ratio for projection matrix. More... | |
float | focal_length |
Camera's Focal Length. More... | |
float | fovy |
Field of view angle in y axis. More... | |
bool | use_perspective |
Flag to indicate if using a perspective or othograpic projection. More... | |
Path class, defines control points and a cubic Bezier approximation for defining a smooth path from key frames.
Very useful for creating camera paths for example, but it is generic enough to be used for other purposes. Each key frame stores a position and an orientation.
Reference: https://www.particleincell.com/2012/bezier-splines/
Notation: We refer to time as the curve parameter (analogy to particle moving along path) We refer to curve as the whole path, and a segment as one Cubic Bezíér that composes path
|
inline |
Default constructor.
|
inline |
Add an optial key direction Key directions are interpolated via SLERP and not SQUAD This is specially useful for interpolating a light direction together with the camera path Key directions should be always allocated together with a key position to work properly.
camera | Camera with directional information |
|
inline |
Add key position The camera will pause at this position for given number of steps, default is zero.
camera | Camera containing position and orientation in view matrix |
interval | Number of steps to stay at this position |
|
inline |
Return animation speed where 1 covers the whole curve in one step.
|
inline |
Return current animation time.
|
inline |
Converts from given arc length to time parameter.
s | Arc length parameter in [0,1] |
|
inline |
Return the view matrix at current animation time.
|
inline |
return a view matrix at a given path parameter
|
inline |
Compute an approximation of the arclength.
approximates the curve by linear segments divide the curve between two key positions and compute the total length of the linear segments
|
inline |
Compute control points for SQUAD.
Quaternions, Interpolation and Animation, Erik B. Dam, Martin Koch, Martin Lillholm
|
inline |
Compute inner control points from key positions.
For each pair of subsequent key positions, compute two control points to define a Beziér Spline. Since we are restricting the splines to join with same position, and first two derivatives, the result is a smooth curve passing through all control points See reference at class info for more details.
To solve the tridiagonal system we use Thomas Algorithm (see Wikipedia)
|
inline |
returns the segment given a time t in [0,1] for the whole path
|
inline |
Return the direction at current animation time.
|
inline |
return a direction at a given path parameter
|
inline |
Returns the exp of a quaternion exp(q) q in the form [0, a v], exp(q) = [cos(a), sin(a) v] with |v|=1.
q | Given quaternion |
|
inline |
Fill the vertices array.
|
inline |
Initializes shaders.
shader_dir | Location of shader files |
|
inline |
Initializes the view and projection matrices. They are all initialized as Identity matrices, but view is then translated by the defaultTranslation vector.
|
inline |
Returns if Animation is running or not.
|
inline |
|
inline |
Returns the log of a quaternion log(q) q in the form [cos(a), sin(a) v], log(q) = [0, a v].
qi | Given quaternion |
|
inline |
compute point on path given t in [0,1]
Note that t refers to the whole path, so t=0 is the first key position and t=1 is the last key position
global_t | Global parameter on path in [0,1] |
|
inline |
Returns a point at time t on a given Beziér segment.
t | Beziér segment parameter |
segment | Beziér segment on path |
|
inline |
|
inline |
Renders smooth path End points for each Beziér is passed as line_strip and control points as vertex attributes Inside geometry shader each Beziér segment is approximate by linear segments.
camera | Current camera for viewing scene |
light | Camera representing light (position and orientation) |
|
inline |
Resets the path.
|
inline |
Resets animation to first key position.
|
inline |
Sets the animation speed.
as | Given animation speed |
|
inline |
Set loop animation flag.
f | True for loop animation, false otherwise |
|
inline |
SQUAD - Spherical and Quadrangle quaternion interpolation.
seg | The current Bezièr segment |
t | Interpolatio time |
|
inline |
Start animation following camera path.
|
inline |
Move animation backward one step.
|
inline |
Move animation forward one step.
|
inline |
Stop animation.
|
inline |
Toggle animation.
|
inline |
Toggle render control points.
|
inline |
Toggle render control quaternions.
|
inline |
converts global parameter t to a local t inside a segment
|
inline |
|
private |
Movement speed, arc length increment for each animation step.
|
private |
Animation time.
|
private |
Start/stop animation.
|
private |
Arc-length approximation splitting each Beziér segment into linear segments.
|
private |
Coordinate axes for visualizing quaternions at key positions.
|
private |
First control point between two key positions.
|
private |
Second control point between two key positions.
|
private |
Control quaternions for SQUAD.
|
private |
|
private |
Mesh with path's key positions and computed control points for drawing smooth curve between key positions
|
private |
Flag to render control points.
|
private |
Flag to render quaternions at key positions.
|
private |
Rotation only interpolation (via Slerp) useful for accompaning light direction for example.
|
private |
Steps to stay paused at a given key position, usually zero.
|
private |
Camera position at each Key frames.
|
private |
Rotation state at each key frame.
|
private |
Flag to loop animation.
|
private |
Total path length.
|
private |
To render simple lines.
|
private |
A sphere to visually represent the path's key positions.