SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLNodeAnimTrack Class Reference

Specialized animation track for node animations. More...

#include <SLAnimTrack.h>

Inheritance diagram for SLNodeAnimTrack:
[legend]

Public Member Functions

 SLNodeAnimTrack (SLAnimation *parent)
 
virtual ~SLNodeAnimTrack ()
 
SLTransformKeyframecreateNodeKeyframe (SLfloat time)
 
void animatedNode (SLNode *target)
 
SLNodeanimatedNode ()
 
virtual void calcInterpolatedKeyframe (SLfloat time, SLAnimKeyframe *keyframe) const
 
virtual void apply (SLfloat time, SLfloat weight=1.0f, SLfloat scale=1.0f)
 
virtual void applyToNode (SLNode *node, SLfloat time, SLfloat weight=1.0f, SLfloat scale=1.0f)
 
virtual void drawVisuals (SLSceneView *sv)
 Draws all visualizations of node animations. More...
 
void interpolationCurve (SLCurve *curve)
 
void translationInterpolation (SLAnimInterpolation interp)
 
- Public Member Functions inherited from SLAnimTrack
 SLAnimTrack (SLAnimation *parent)
 
virtual ~SLAnimTrack ()
 
SLAnimKeyframecreateKeyframe (SLfloat time)
 
SLfloat getKeyframesAtTime (SLfloat time, SLAnimKeyframe **k1, SLAnimKeyframe **k2) const
 
SLint numKeyframes () const
 
SLAnimKeyframekeyframe (SLint index)
 

Protected Member Functions

void buildInterpolationCurve () const
 
virtual SLAnimKeyframecreateKeyframeImpl (SLfloat time)
 

Protected Attributes

SLNode_animatedNode
 the target node for this track_nodeID More...
 
SLCurve_interpolationCurve
 the translation interpolation curve More...
 
SLAnimInterpolation _translationInterpolation
 interpolation mode for translations (Bezier or linear) More...
 
SLbool _rebuildInterpolationCurve
 dirty flag of the Bezier curve More...
 
- Protected Attributes inherited from SLAnimTrack
SLAnimation_animation
 parent animation that created this track More...
 
SLVKeyframe _keyframes
 keyframe list for this track More...
 

Detailed Description

Specialized animation track for node animations.

Allows for translation, scale and rotation parameters to be animated. Also allows for either linear or Bezier interpolation of the position parameter in the track.

Definition at line 65 of file SLAnimTrack.h.

Constructor & Destructor Documentation

◆ SLNodeAnimTrack()

SLNodeAnimTrack::SLNodeAnimTrack ( SLAnimation animation)

Constructor for specialized NodeAnimationTrack

Definition at line 169 of file SLAnimTrack.cpp.

170  : SLAnimTrack(animation),
171  _animatedNode(nullptr),
172  _interpolationCurve(nullptr),
175 {
176 }
@ AI_linear
Definition: SLEnums.h:161
SLAnimTrack(SLAnimation *parent)
Definition: SLAnimTrack.cpp:18
SLbool _rebuildInterpolationCurve
dirty flag of the Bezier curve
Definition: SLAnimTrack.h:91
SLCurve * _interpolationCurve
the translation interpolation curve
Definition: SLAnimTrack.h:89
SLAnimInterpolation _translationInterpolation
interpolation mode for translations (Bezier or linear)
Definition: SLAnimTrack.h:90
SLNode * _animatedNode
the target node for this track_nodeID
Definition: SLAnimTrack.h:88

◆ ~SLNodeAnimTrack()

SLNodeAnimTrack::~SLNodeAnimTrack ( )
virtual

Destructor

Definition at line 181 of file SLAnimTrack.cpp.

182 {
184  delete _interpolationCurve;
185 }

Member Function Documentation

◆ animatedNode() [1/2]

SLNode* SLNodeAnimTrack::animatedNode ( )
inline

Definition at line 74 of file SLAnimTrack.h.

74 { return _animatedNode; }

◆ animatedNode() [2/2]

void SLNodeAnimTrack::animatedNode ( SLNode target)
inline

Definition at line 73 of file SLAnimTrack.h.

73 { _animatedNode = target; }

◆ apply()

void SLNodeAnimTrack::apply ( SLfloat  time,
SLfloat  weight = 1.0f,
SLfloat  scale = 1.0f 
)
virtual

Applies the animation with the input timestamp to the set animation target if it exists.

Implements SLAnimTrack.

Definition at line 239 of file SLAnimTrack.cpp.

240 {
241  if (_animatedNode)
242  applyToNode(_animatedNode, time, weight, scale);
243 }
virtual void applyToNode(SLNode *node, SLfloat time, SLfloat weight=1.0f, SLfloat scale=1.0f)

◆ applyToNode()

void SLNodeAnimTrack::applyToNode ( SLNode node,
SLfloat  time,
SLfloat  weight = 1.0f,
SLfloat  scale = 1.0f 
)
virtual

Applies the animation to the input node with the input timestamp and weight.

Definition at line 248 of file SLAnimTrack.cpp.

252 {
253  if (node == nullptr)
254  return;
255 
256  SLTransformKeyframe kf(nullptr, time);
257  calcInterpolatedKeyframe(time, &kf);
258 
259  SLVec3f translation = kf.translation() * weight * scale;
260  node->translate(translation, TS_parent);
261 
262  // @todo update the slerp and lerp implementation for quaternions
263  // there is currently no early out for 1.0 and 0.0 inputs
264  // also provide a non OO version.
265  SLQuat4f rotation = SLQuat4f().slerp(kf.rotation(), weight);
266  node->rotate(rotation, TS_parent);
267 
268  // @todo find a good way to combine scale animations,
269  // we can't just scale them by a weight factor...
270  SLVec3f scl = kf.scale();
271  node->scale(scl);
272 }
@ TS_parent
Definition: SLEnums.h:209
SLQuat4< SLfloat > SLQuat4f
Definition: SLQuat4.h:846
virtual void calcInterpolatedKeyframe(SLfloat time, SLAnimKeyframe *keyframe) const
void rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
void scale(SLfloat s)
Definition: SLNode.h:640
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
SLQuat4< T > slerp(const SLQuat4< T > &q2, T t) const
Definition: SLQuat4.h:745
SLTransformKeyframe is a specialized SLKeyframe for node transformations.
void scale(const T s)
Definition: SLVec3.h:116

◆ buildInterpolationCurve()

void SLNodeAnimTrack::buildInterpolationCurve ( ) const
protected

Rebuilds the translation interpolation Bezier curve.

Definition at line 289 of file SLAnimTrack.cpp.

290 {
291  if (numKeyframes() > 1)
292  {
294 
295  // Build curve data w. cumulated times
296  SLVVec4f points;
297  points.resize((SLuint)numKeyframes());
298  // SLfloat curTime = 0;
299  for (SLuint i = 0; i < (SLuint)numKeyframes(); ++i)
300  {
301  SLVec3f t = ((SLTransformKeyframe*)_keyframes[i])->translation();
302  points[i].set(t.x, t.y, t.z, _keyframes[i]->time());
303  }
304 
305  // create curve and delete temp arrays again
306  _interpolationCurve = new SLCurveBezier(points);
307  }
308 }
unsigned int SLuint
Definition: SL.h:171
vector< SLVec4f > SLVVec4f
Definition: SLVec4.h:239
SLint numKeyframes() const
Definition: SLAnimTrack.h:47
SLVKeyframe _keyframes
keyframe list for this track
Definition: SLAnimTrack.h:55
The SLCurveBezier class implements a Bezier curve interpolation.
Definition: SLCurveBezier.h:25
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59
T z
Definition: SLVec3.h:43

◆ calcInterpolatedKeyframe()

void SLNodeAnimTrack::calcInterpolatedKeyframe ( SLfloat  time,
SLAnimKeyframe keyframe 
) const
virtual

Calculates a new keyframe based on the input time and interpolation functions.

Implements SLAnimTrack.

Definition at line 198 of file SLAnimTrack.cpp.

200 {
201  SLAnimKeyframe* k1;
202  SLAnimKeyframe* k2;
203 
204  SLfloat t = getKeyframesAtTime(time, &k1, &k2);
205 
206  if (k1 == nullptr)
207  return;
208 
209  SLTransformKeyframe* kfOut = static_cast<SLTransformKeyframe*>(keyframe);
210  SLTransformKeyframe* kf1 = static_cast<SLTransformKeyframe*>(k1);
211  SLTransformKeyframe* kf2 = static_cast<SLTransformKeyframe*>(k2);
212 
213  SLVec3f base = kf1->translation();
214  SLVec3f translation;
216  translation = base + (kf2->translation() - base) * t;
217  else
218  {
221  translation = _interpolationCurve->evaluate(time);
222  }
223 
224  kfOut->translation(translation);
225 
226  SLQuat4f rotation;
227  rotation = kf1->rotation().slerp(kf2->rotation(), t); // @todo provide a 2 parameter implementation for lerp, slerp etc.
228  kfOut->rotation(rotation);
229 
230  base = kf1->scale();
231  SLVec3f scale;
232  scale = base + (kf2->scale() - base) * t;
233  kfOut->scale(scale);
234 }
float SLfloat
Definition: SL.h:173
Base class for all animation keyframes.
SLAnimKeyframe * keyframe(SLint index)
Definition: SLAnimTrack.cpp:48
SLfloat getKeyframesAtTime(SLfloat time, SLAnimKeyframe **k1, SLAnimKeyframe **k2) const
Definition: SLAnimTrack.cpp:62
virtual SLVec3f evaluate(const SLfloat t)=0
void buildInterpolationCurve() const
void translation(const SLVec3f &t)
void scale(const SLVec3f &s)
void rotation(const SLQuat4f &r)

◆ createKeyframeImpl()

SLAnimKeyframe * SLNodeAnimTrack::createKeyframeImpl ( SLfloat  time)
protectedvirtual

Implementation for the keyframe creation function.

Implements SLAnimTrack.

Definition at line 313 of file SLAnimTrack.cpp.

314 {
315  return new SLTransformKeyframe(this, time);
316 }

◆ createNodeKeyframe()

SLTransformKeyframe * SLNodeAnimTrack::createNodeKeyframe ( SLfloat  time)

Creates a new SLTransformKeyframe at 'time'.

Definition at line 190 of file SLAnimTrack.cpp.

191 {
192  return static_cast<SLTransformKeyframe*>(createKeyframe(time));
193 }
SLAnimKeyframe * createKeyframe(SLfloat time)
Definition: SLAnimTrack.cpp:38

◆ drawVisuals()

void SLNodeAnimTrack::drawVisuals ( SLSceneView sv)
virtual

Draws all visualizations of node animations.

Implements SLAnimTrack.

Definition at line 275 of file SLAnimTrack.cpp.

276 {
279  {
280  // Move the animation curve to the initial WM position of the node
281  SLMat4f parentWM = _animatedNode->parent()->updateAndGetWM();
282  SLMat4f initialOM = _animatedNode->initialOM();
283  _interpolationCurve->draw(parentWM * initialOM);
284  }
285 }
#define SL_DB_AXIS
Draw the coordinate axis of a node.
Definition: SLDrawBits.h:25
virtual void draw(const SLMat4f &wm)=0
SLbool drawBit(SLuint bit)
Definition: SLNode.h:300
void parent(SLNode *p)
Definition: SLNode.cpp:600
const SLMat4f & initialOM()
Definition: SLNode.h:296
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
SLbool drawBit(SLuint bit)
Definition: SLSceneView.h:199

◆ interpolationCurve()

void SLNodeAnimTrack::interpolationCurve ( SLCurve curve)

setter for the interpolation curve

Definition at line 321 of file SLAnimTrack.cpp.

322 {
324  delete _interpolationCurve;
325 
326  _interpolationCurve = curve;
328 }

◆ translationInterpolation()

void SLNodeAnimTrack::translationInterpolation ( SLAnimInterpolation  interp)
inline

Definition at line 82 of file SLAnimTrack.h.

82 { _translationInterpolation = interp; }

Member Data Documentation

◆ _animatedNode

SLNode* SLNodeAnimTrack::_animatedNode
protected

the target node for this track_nodeID

Definition at line 88 of file SLAnimTrack.h.

◆ _interpolationCurve

SLCurve* SLNodeAnimTrack::_interpolationCurve
mutableprotected

the translation interpolation curve

Definition at line 89 of file SLAnimTrack.h.

◆ _rebuildInterpolationCurve

SLbool SLNodeAnimTrack::_rebuildInterpolationCurve
protected

dirty flag of the Bezier curve

Definition at line 91 of file SLAnimTrack.h.

◆ _translationInterpolation

SLAnimInterpolation SLNodeAnimTrack::_translationInterpolation
protected

interpolation mode for translations (Bezier or linear)

Definition at line 90 of file SLAnimTrack.h.


The documentation for this class was generated from the following files: