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


C++ UnitObj::WorldMatrix方法代码示例

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


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

示例1: StateInit

  //
  // Initial state
  //
  void SquadMoveTogether::StateInit()
  {
    LOG_DIAG(("SquadMoveTogether: Init"))

    // Find the slowest unit in the squad and use their traction type
    U8 traction = 0;
    F32 bottomSpeed = F32_MAX;

    // Work out the centre position of the squad
    Vector location(0.0f, 0.0f, 0.0f);
    U32 count = 0;
    SquadObj::UnitList::Iterator i(&subject->GetList());
    for (!i; *i; i++)
    {
      if ((*i)->Alive())
      {
        // Take this oportunity to reset the units node
        (*i)->completed = TRUE;
        (*i)->data = 0;

        if ((**i)->CanEverMove())
        {
          // Grab the unit so we don't need to continually pound the iterator
          UnitObj *unit = **i;

          // Flush its tasks
          unit->FlushTasks(Tasks::UnitMove::GetConfigBlockingPriority());

          // Add its position to the total
          location.x += unit->WorldMatrix().posit.x;
          location.z += unit->WorldMatrix().posit.z;
          count++;

          // Is this the slowest unit in the squad
          F32 speed = unit->GetMaxSpeed();
          if (speed < bottomSpeed)
          {
            bottomSpeed = speed;
            traction = unit->MapType()->GetTractionIndex(unit->MapType()->GetDefaultLayer());
          }
        }
      }
    }

    if (!count)
    {
      Quit();
      return;
    }

    // Work out the averate location
    location.x /= count;
    location.z /= count;
    location.y = TerrainData::FindFloor(location.x, location.z);

    // What is the direction from the source (location) to the dest (destination)
    VectorDir dir;
    Vector(destination - location).Convert(dir);
    direction = dir.u;

    // Build a formation from the units using the direction to the destination
    Formation::Create(location, direction, subject, 16.0f);

    // Get the source and destination in terms of cells
    Point<F32> avg(location.x, location.z);

    Point<U32> srcCell;
    WorldCtrl::MetresToCellPoint(avg, srcCell);

    Point<U32> destCell;
    WorldCtrl::MetresToCellPoint(Point<F32>(destination.x, destination.z), destCell);

    switch (subject->GetPathFinder().RequestPath(srcCell.x, srcCell.z, destCell.x, destCell.z, traction))
    {
      case PathSearch::Finder::RR_SUBMITTED:
        NextState(0xFDE9D5E3); // "Pathing"
        break;

      case PathSearch::Finder::RR_SAMECELL:
      case PathSearch::Finder::RR_OFFMAP:
        Quit();
        return;

      default:
        ERR_FATAL(("Unknown path request result"))
    }
  }
开发者ID:ZhouWeikuan,项目名称:darkreign2,代码行数:90,代码来源:tasks_squadmovetogether.cpp


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