当前位置: 首页>>代码示例>>C++>>正文


C++ Phase::evaluateLength方法代码示例

本文整理汇总了C++中Phase::evaluateLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Phase::evaluateLength方法的具体用法?C++ Phase::evaluateLength怎么用?C++ Phase::evaluateLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phase的用法示例。


在下文中一共展示了Phase::evaluateLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getValue

float WalkingEngineKick::getValue(Track track, float externValue)
{
  std::vector<Phase>& phases = tracks[track];
  const int phasesSize = int(phases.size());
  int currentPhase = currentPhases[track];

  const bool init = currentPhase < 0;
  if(init)
    currentPhase = currentPhases[track] = 0;

  ASSERT(currentPhase < phasesSize - 1);
  Phase* phase = &phases[currentPhase];
  Phase* nextPhase = &phases[currentPhase + 1];

  if(init)
  {
    const bool precomputedLength = length >= 0.f;
    if(!precomputedLength)
    {
      phase->evaluateLength(0.f);
      nextPhase->evaluateLength(phase->end);
    }
    phase->evaluatePos(externValue);
    nextPhase->evaluatePos(externValue);
    Phase* const nextNextPhase = currentPhase + 2 < phasesSize ? &phases[currentPhase + 2] : 0;
    if(nextNextPhase)
    {
      if(!precomputedLength)
        nextNextPhase->evaluateLength(nextPhase->end);
      nextNextPhase->evaluatePos(externValue);
      nextPhase->velocity = ((nextPhase->pos - phase->pos) / phase->length + (nextNextPhase->pos - nextPhase->pos) / nextPhase->length) * 0.5f;
    }
  }

  while(phase->end <= currentPosition)
  {
    Phase* nextNextPhase = currentPhase + 2 < phasesSize ? &phases[currentPhase + 2] : 0;
    if(!nextNextPhase)
    {
      ASSERT(nextPhase->posValue == 0);
      return externValue;
    }

    currentPhase = ++currentPhases[track];
    phase = nextPhase;
    nextPhase = nextNextPhase;
    if(currentPhase + 2 < phasesSize)
    {
      nextNextPhase = &phases[currentPhase + 2];
      const bool precomputedLength = length >= 0.f;
      if(!precomputedLength)
        nextNextPhase->evaluateLength(nextPhase->end);
      nextNextPhase->evaluatePos(externValue);
      nextPhase->velocity = ((nextPhase->pos - phase->pos) / phase->length + (nextNextPhase->pos - nextPhase->pos) / nextPhase->length) * 0.5f;
    }
  }

  if(!phase->posValue)
    phase->pos = externValue;
  if(!nextPhase->posValue)
    nextPhase->pos = externValue;

  const float nextRatio = (currentPosition - phase->start) / phase->length;
  const float d = phase->pos;
  const float c = phase->velocity;
  const float v2 = nextPhase->velocity;
  const float p2 = nextPhase->pos;
  const float p2mcmd = p2 - c - d;
  const float a = -2.f * p2mcmd + (v2 - c);
  const float b = p2mcmd - a;
  const float x = nextRatio;
  const float xx = x * x;
  return a * xx * x + b * xx + c * x + d;
}
开发者ID:MisterSquishy,项目名称:nbites,代码行数:74,代码来源:WalkingEngineKick.cpp


注:本文中的Phase::evaluateLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。