2/5
2. Descriptive animation
Cardinal Spline Interpolation
Code explanation
-
The scene associated to the next exercise is described in the directory 01_animation_descriptive/interpolation_position.[ch]pp
-
To activate this scene you need to
-
Open the file current_scene.hpp indicating which exercise file should be compiled
-
Change
#define SCENE_DEFAULT_3D_GRAPHICSinto#define SCENE_INTERPOLATION_POSITION(note that the possible #define are already prepared and you can just comment/uncomment them). -
Recompile the code and execute it.
-
-
This code models a series of key positions \(p_i\) (
keyframe_position) displayed as white spheres. Each position is associated to a specific time \(t_i\) (keyframe_time). -
The displacement of the blue sphere through time corresponds to the linear interpolation between these key positions.
-
The initalisation of the key position and time is done in the function
setup_data, while the linear interpolation is computed in the functionframe_draw. -
Key positions can be changed interactively. To this end, press Shift key while you are selecting and sliding one of the white sphere.
The selection and translation of the vertices is computed by the function mouse_click et mouse_move. You don’t have to change these functions.
Interpolation
Your objective is to modify the function computing the displacement of the blue sphere as a cardinal spline. This interpolation should allow, for instance, to model a smooth motion along a trajectory defined by the user.
-
Code the function
cardinal_spline_interpolationwith the following signature
vec3 cardinal_spline_interpolation(float t, float t0, float t1, float t2, float t3, const vec3& p0, const vec3& p1, const vec3& p2, const vec3& p3)
Replace the linear interpolation with the cardinal spline one, you should obtain a smooth continuous trajectory.
Hierarchical Animation
In this part, we focus on animation shapes made by articulated rigid parts. Articulated shapes can be modeled by simple primitive shapes (sphere, cylinder, etc.) linked together with hierarchical relations. For instance, in the case of a humanoid character, arms, legs, and the head are all children elements of the body, while feets are themselves children of their respective legs. Each child element inherit of the parent current transformatoin and can itself contain its own one. This representation allow to express the local position and transformation to be applied to an element within the frame of its parent.
-
Consider now the code associated to the file 01_animation_descriptive/articulated_hierarchy. This code set up an articulated model using the class
hierarchy_mesh_drawable. (You need to change the value in the file exercise_current.hpp to compile it.)
hierarchy_mesh_drawable models a hierarchy of elements. Each element is defined in the frame of its parent, and is associated to its own transformation (translation, rotation). Note that before displaying the element, all the transformations are updated along the hierarchical organization to be expressed within the global frame.
-
Compile and execute the code
-
Observe the creation of the character in the
setup_datafunction, in particular the addition of new elements in the hierarchy.-
Each element is associated to a name allowing to retrieve it later one within the hierarchy.
-
The name of the parent element should be given in order to set the correct position of the current one in the hierarchy (note that the name of the parent element of root can be arbitrary chosen).
-
Each element can be associated to a translation (null by default), and rotation (identity by defaut) expressed locally with respect to the frame of the parent.
-
Note that the relative translation and rotation are stored independently in order to modify them during the animation if needed.
-
Observe the drawing function
frame_draw.-
Translations and rotations associated to elements can be retrieved and modified to generate an animation. Note that these translation and rotations are expressed with respect to the frame of the parent element.
-
-
When
hierarchy.drawis called, the respective transformation of every element are expressed in the global frame and used as uniform parameters.
Adapt the shape and the animation of your model to a bird-like character.
Example of possible model
(You are free to generate another type of model if you wish)
Bonus question (skip it if you are not in advance)
Merge your 3D animated model with an interactive user-guided trajectory into a virtual environment.