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


C++ AABB::Translate方法代码示例

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


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

示例1: TransformBy

void BVaabb::TransformBy(const Transformation& transform,
	BoundingVolumePtr result)
{
	assert(result);
	BVaabb* pNewBound = (BVaabb*)result.get();
	AABB newAABB = mAABB;
	newAABB.Translate(transform.GetTranslation());
	pNewBound->SetAABB(newAABB);
}
开发者ID:fastbird,项目名称:fastbirdEngine_NewAPI,代码行数:9,代码来源:BVaabb.cpp

示例2: UnCollide

void UnCollide(GameObject* go, const Vec3f& oldPos, const AABB& aabb)
{
  /* 
  Move back so not interpenetrating:
  Boxes now intersect in all axes. Moving away by penetration depth in any
  axis will resolve the intersection. To choose which axis, use the previous
  position. E.g. if previously not intersecting in X, move away in X axis.
  */

  // Intersecton region
  AABB ir = aabb.Intersection(go->GetAABB());
  Vec3f goPos = go->GetPos();

  AABB oldBox = go->GetAABB();
  Vec3f move = oldPos - goPos;
  oldBox.Translate(move);
  // Oldbox should NOT be intersecting in one or more axes

  Vec3f penDist(
    ir.GetMax(0) - ir.GetMin(0), 
    ir.GetMax(1) - ir.GetMin(1),
    ir.GetMax(2) - ir.GetMin(2));
  penDist *= 1.01f; // move away a bit more to be sure of clearing the collision

  if (oldBox.GetMax(0) < aabb.GetMin(0))
  {
    // Old box to left of box, so move away to the left
    goPos.x -= penDist.x; 
  }
  else if (oldBox.GetMin(0) > aabb.GetMax(0))
  {
    goPos.x += penDist.x;
  }
  /*
  else if (oldBox.GetMax(1) < aabb.GetMin(1))
  {
    goPos.y -= penDist.y;
  }
  else if (oldBox.GetMin(1) > aabb.GetMax(1))
  {
    goPos.y += penDist.y;
  }
  */
  else if (oldBox.GetMax(2) < aabb.GetMin(2))
  {
    goPos.z -= penDist.z;
  }
  else if (oldBox.GetMin(2) > aabb.GetMax(2))
  {
    goPos.z += penDist.z;
  }

  go->SetPos(goPos);
}
开发者ID:jason-amju,项目名称:amjulib,代码行数:54,代码来源:UnCollide.cpp

示例3: PreventIntersection

// Move moving object away from stationary object so they do not intersect.
// Relies on knowing the old (non-intersecting) position of the moving object.
void PreventIntersection(
  GameObject* moving, const GameObject* stationary, const Vec3f& oldPos)
{
std::cout << "Moving apart: moving: " << Describe(moving) << " stnry: " << Describe(stationary) << ": ";

  /* 
  Move back so not interpenetrating:
  Boxes now intersect in all axes. Moving away by penetration depth in any
  axis will resolve the intersection. To choose which axis, use the previous
  position. E.g. if previously not intersecting in X, move away in X axis.
  */

  // Intersecton region
  AABB ir = stationary->GetAABB().Intersection(moving->GetAABB());
  Vec3f goPos = moving->GetPos();

  // Create AABB in old position
  AABB oldBox = moving->GetAABB();
  Vec3f move = oldPos - goPos;
  oldBox.Translate(move);
  // Oldbox should not be intersecting in one or more axes

  const AABB& stationaryBox = stationary->GetAABB();

  // Penetration depth in each axis
  Vec3f penDist(
    ir.GetMax(0) - ir.GetMin(0), 
    ir.GetMax(1) - ir.GetMin(1),
    ir.GetMax(2) - ir.GetMin(2));
  penDist *= 1.01f; // move away a bit more to be sure of clearing the collision

std::cout << "Pen depths: " << Describe(penDist) << ": ";

  //Vec3f vel = moving->GetVel();

  if (oldBox.GetMax(0) < stationaryBox.GetMin(0))
  {
    // Old box to left of stationary object, so move away to the left
//    Assert(penDist.x > 0);
    goPos.x -= penDist.x; 

std::cout << "x -= " << penDist.x;
  }
  else if (oldBox.GetMin(0) > stationaryBox.GetMax(0))
  {
//    Assert(penDist.x > 0);
    goPos.x += penDist.x;

std::cout << "x += " << penDist.x;
  }
  if (oldBox.GetMax(1) < stationaryBox.GetMin(1))
  {
//    Assert(penDist.y > 0);
    goPos.y -= penDist.y;
std::cout << "y -= " << penDist.y;
  }
  else if (oldBox.GetMin(1) > stationaryBox.GetMax(1))
  {
//    Assert(penDist.y > 0);
    goPos.y += penDist.y;
std::cout << "y += " << penDist.y;
  }
  if (oldBox.GetMax(2) < stationaryBox.GetMin(2))
  {
//    Assert(penDist.z > 0);
    goPos.z -= penDist.z;
std::cout << "z -= " << penDist.z;
  }
  else if (oldBox.GetMin(2) > stationaryBox.GetMax(2))
  {
//    Assert(penDist.z > 0);
    goPos.z += penDist.z;
std::cout << "z += " << penDist.z;
  }

std::cout << "\n";

  moving->SetPos(goPos);


//  moving->RecalcAABB();
  // Test that AABBs are no longer intersecting
//  if (stationary->GetAABB().Intersects(moving->GetAABB()))
//  {
//    AABB ir = stationary->GetAABB().Intersection(moving->GetAABB());
//  }
}
开发者ID:jason-amju,项目名称:amju-ww,代码行数:89,代码来源:PreventIntersection.cpp


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