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 289 of file StdMesh.cpp.

References StdMeshTransformation::Nlerp().

Referenced by StdMeshInstanceAnimationNode::GetBoneTransform().

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