OpenClonk
StdMeshTrack Class Reference

#include <StdMesh.h>

Public Member Functions

StdMeshTransformation GetTransformAt (float time, float length) const
 

Friends

class StdMeshSkeleton
 
class StdMeshSkeletonLoader
 

Detailed Description

Definition at line 72 of file StdMesh.h.

Member Function Documentation

◆ GetTransformAt()

StdMeshTransformation StdMeshTrack::GetTransformAt ( float  time,
float  length 
) const

Definition at line 291 of file StdMesh.cpp.

292 {
293  std::map<float, StdMeshKeyFrame>::const_iterator iter = Frames.lower_bound(time);
294 
295  // We are at or before the first keyframe. This short typically not
296  // happen, since all animations have a keyframe 0. Simply return the
297  // first keyframe.
298  if (iter == Frames.begin())
299  return iter->second.Transformation;
300 
301  std::map<float, StdMeshKeyFrame>::const_iterator prev_iter = iter;
302  --prev_iter;
303 
304  float iter_pos;
305  if (iter == Frames.end())
306  {
307  // We are beyond the last keyframe.
308  // Interpolate between the last and the first keyframe.
309  // See also bug #1406.
310  iter = Frames.begin();
311  iter_pos = length;
312  }
313  else
314  {
315  iter_pos = iter->first;
316  }
317 
318  // No two keyframes with the same position:
319  assert(iter_pos > prev_iter->first);
320 
321  // Requested position is between the two selected keyframes:
322  assert(time >= prev_iter->first);
323  assert(iter_pos >= time);
324 
325  float dt = iter_pos - prev_iter->first;
326  float weight1 = (time - prev_iter->first) / dt;
327  float weight2 = (iter_pos - time) / dt;
328  (void)weight2; // used in assertion only
329 
330  assert(weight1 >= 0 && weight2 >= 0 && weight1 <= 1 && weight2 <= 1);
331  assert(fabs(weight1 + weight2 - 1) < 1e-6);
332 
333  return StdMeshTransformation::Nlerp(prev_iter->second.Transformation, iter->second.Transformation, weight1);
334 }
static StdMeshTransformation Nlerp(const StdMeshTransformation &lhs, const StdMeshTransformation &rhs, float w)

References StdMeshTransformation::Nlerp().

Referenced by StdMeshInstanceAnimationNode::GetBoneTransform().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ StdMeshSkeleton

friend class StdMeshSkeleton
friend

Definition at line 74 of file StdMesh.h.

◆ StdMeshSkeletonLoader

friend class StdMeshSkeletonLoader
friend

Definition at line 75 of file StdMesh.h.


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