本文整理汇总了C#中FarseerPhysics.Collision.AABB.Combine方法的典型用法代码示例。如果您正苦于以下问题:C# AABB.Combine方法的具体用法?C# AABB.Combine怎么用?C# AABB.Combine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Collision.AABB
的用法示例。
在下文中一共展示了AABB.Combine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateBounds
public void CalculateBounds()
{
if (connectedBody == null)
{
_bodyBounds = new Bounds();
return;
}
AABB aabb_full = new AABB();
bool combine = false;
for (int i = 0; i < connectedBody.FixtureList.Count; i++)
{
for (int j = 0; j < connectedBody.FixtureList[i].Shape.ChildCount; j++)
{
AABB aabb;
connectedBody.FixtureList[i].Shape.ComputeAABB(out aabb, ref connectedBody.Xf, j);
if (!combine)
{
combine = true;
aabb_full = aabb;
}
else
{
aabb_full.Combine(ref aabb);
}
}
}
_bodyBounds = Bounds.FromAABB(ref aabb_full, to2dMode, GetSize());
}
示例2: GetAABB
public static Rectangle GetAABB(EasyGameComponent component)
{
AABB overallAABB = new AABB();
component.Body.FixtureList.ForEach(delegate(Fixture fixture)
{
for (int i = 0; i < fixture.Shape.ChildCount; i++)
{
AABB currentAABB;
Transform transform;
fixture.Body.GetTransform(out transform);
fixture.Shape.ComputeAABB(out currentAABB, ref transform, i);
overallAABB.Combine(ref currentAABB);
}
});
int left = (int)overallAABB.UpperBound.X;
int right = (int)overallAABB.LowerBound.X;
int top = (int)overallAABB.UpperBound.Y;
int bottom = (int)overallAABB.LowerBound.Y;
Rectangle rectangle = new Rectangle(left, top, right - left, bottom - top);
return rectangle;
}
示例3: CreateAndDestroyTerrainFixtures
/// <summary>
/// Creates terrain fixtures that are nearby physics entities and destroys those that are no longer in range of
/// any entities.
/// </summary>
private void CreateAndDestroyTerrainFixtures()
{
Entity terrainEntity = this.EntityManager.GetFirstEntityWithComponent(typeof(TerrainComponent));
// Get the terrain components
var cTerrain =
(TerrainComponent)this.EntityManager.GetComponent(terrainEntity, typeof(TerrainComponent));
var cTerrainPhysics =
(PhysicsComponent)this.EntityManager.GetComponent(terrainEntity, typeof(PhysicsComponent));
var cTerrainPosition =
(PositionComponent)this.EntityManager.GetComponent(terrainEntity, typeof(PositionComponent));
var cTerrainScale =
(ScaleComponent)this.EntityManager.GetComponent(terrainEntity, typeof(ScaleComponent));
// Build the list of terrain blocks that are in range of a physics entity
var blocksInRange = new HashSet<Square>();
foreach (Entity physicsEntity in this.EntityManager.GetEntitiesWithComponent(typeof(PhysicsComponent)))
{
var cPhysics =
(PhysicsComponent)this.EntityManager.GetComponent(physicsEntity, typeof(PhysicsComponent));
// Skip the body if it is static or has no fixtures
if (cPhysics.Body.IsStatic || cPhysics.Body.FixtureList.Count == 0)
{
continue;
}
// Get the bounds of body in physics-world coordinates
AABB bodyAABB = new AABB();
bool firstStep = true;
foreach (Fixture fixture in cPhysics.Body.FixtureList)
{
AABB fixtureBounds;
fixture.GetAABB(out fixtureBounds, 0);
if (firstStep)
{
bodyAABB = fixtureBounds;
firstStep = false;
}
else
{
bodyAABB.Combine(ref fixtureBounds);
}
}
// Translate the body AABB with the body position
bodyAABB.LowerBound += cPhysics.Body.Position;
bodyAABB.UpperBound += cPhysics.Body.Position;
// Add the body padding
bodyAABB.LowerBound -= new Vector2(Const.BodyCollisionPadding);
bodyAABB.UpperBound += new Vector2(Const.BodyCollisionPadding);
// Get the distance of the top-left point of the body relative to the terrain's top-left position
// Remember that the terrain quad tree goes top-left to bottom-right, so Y increases as the body is
// further down
var terrainRelativeDistance = new Vector2(
bodyAABB.LowerBound.X - cTerrainPosition.Position.X,
cTerrainPosition.Position.Y - bodyAABB.UpperBound.Y);
// Scale the distance by the terrain scale factor (ie. if the terrain is x2 sized, the body's
// relative distance should be halved)
terrainRelativeDistance /= cTerrainScale.Scale;
// Scale the length/width of the body by the terrain scale factor to get the size
Vector2 bodySize = (bodyAABB.UpperBound - bodyAABB.LowerBound) / cTerrainScale.Scale;
var bodyBounds = new Rectangle(
(int)terrainRelativeDistance.X,
(int)terrainRelativeDistance.Y,
(int)(Math.Abs(bodySize.X) + 0.5),
(int)(Math.Abs(bodySize.Y) + 0.5));
// Get the terrain blocks which intersect the body
foreach (ClipQuadTree<TerrainData> block in cTerrain.Terrain.GetNodesIntersecting(bodyBounds))
{
if (block.Data.State == TerrainState.Terrain)
{
blocksInRange.Add(block.Bounds);
}
}
}
// Determine which terrain fixtures which are no longer in range of any bodies
var blocksToRemove = new List<KeyValuePair<Square, Fixture>>();
foreach (KeyValuePair<Square, Fixture> kvp in cTerrain.Fixtures)
{
if (!blocksInRange.Contains(kvp.Key))
{
blocksToRemove.Add(kvp);
}
}
// Remove terrain fixtures which are no longer in range of any bodies
foreach (KeyValuePair<Square, Fixture> kvp in blocksToRemove)
{
//.........这里部分代码省略.........