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


C++ Portal::GetPos方法代码示例

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


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

示例1: Update

void Camera::Update()
{
  //float dt = TheTimer::Instance()->GetDt();
  Vec3f pos;

  if (m_target)
  {
    pos = m_target->GetPos();

    // yRotAuto = 0;
#ifdef AUTO_ROTATE
    // Swing behind target
    float dir = m_target->GetDir() + 180.0f;
    float angleDiff = yRotAuto - dir;

    // Rotate to face m_dir, taking the shortest route (CW or CCW)
    if (fabs(angleDiff) < 0.1f) // TODO CONFIG
    {
      yRotAuto  = dir;
    }
    else
    {
      float ROT_SPEED = 1.0f; // TODO CONFIG
      if (yRotAuto > dir)
      {
        yRotAuto -= ROT_SPEED * dt * fabs(angleDiff);
      }
      else if (yRotAuto < dir)
      {
        yRotAuto += ROT_SPEED * dt * fabs(angleDiff);
      }
    }
#endif // AUTO_ROTATE

#ifdef PORTAL_ROTATE
    // TODO Get closest portal
    static PGameObject lastportal = 0;
    // We want to get the closest portal to the target, even if they have never intersected it.
    int pid = m_target->GetIgnorePortalId();
    if (pid > -1)
    {
      lastportal = TheGame::Instance()->GetGameObject(pid);
    }
    else
    {
      // Look for portals in this room, find closest.
      // TODO Optimise
      // just check periodically ?
      Portals portals = GetPortals();
      float bestSqDist = 999999.9f;
      for (Portals::iterator it = portals.begin(); it != portals.end(); ++it)
      {
        Portal* p = *it;
        float sqDist = (p->GetPos() - pos).SqLen();
        if (sqDist < bestSqDist)
        {
          bestSqDist = sqDist;
          lastportal = p;
        }
      } 
    }
    
    if (lastportal)
    {
      float pdist = (pos - lastportal->GetPos()).SqLen(); // sq dist from portal to player
      static const float MAX_DIST = ROConfig()->GetFloat("portal-max-dist", 200.0f); 
      static const float MAX_SQ_DIST = MAX_DIST * MAX_DIST; 
      if (pdist < MAX_SQ_DIST) 
      {
        yRotAuto = atan2(-pos.x, pos.z) * (1.0f - pdist / MAX_SQ_DIST); 

//std::cout << "SQ Dist from portal: " << pdist << " pos.z=" << pos.z << " pos.x=" << pos.x << " yRotAuto degs=" << RadToDeg(yRotAuto) << "\n";
      }
    }
#endif // PORTAL_ROTATE
  }
  else
  {
    pos = posNoTarget; 
  }
  pos += posOffset;

  float y = DegToRad(yRotAuto + yRotUser); 

  SetEyePos(Vec3f(
    pos.x + sin(y) * cos(xRot) * zDist, 
    pos.y + sin(xRot) * zDist, 
    pos.z + cos(y) * cos(xRot) * zDist));

  SetLookAtPos(pos);
}
开发者ID:jason-amju,项目名称:amjulib,代码行数:91,代码来源:Camera.cpp


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