本文整理汇总了C#中FarseerPhysics.Collision.AABB类的典型用法代码示例。如果您正苦于以下问题:C# AABB类的具体用法?C# AABB怎么用?C# AABB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AABB类属于FarseerPhysics.Collision命名空间,在下文中一共展示了AABB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Particle
// Constructor
public Particle(FluidSystem fluidSystem, int index, Vector2 position)
{
//this.simulation = simulation;
this.index = index;
this.position = position;
active = false;
alive = false;
aabb = new AABB();
neighbors = new int[FluidSystem.MAX_NEIGHBORS];
distances = new float[FluidSystem.MAX_NEIGHBORS];
relativePosition = new Vector2[FluidSystem.MAX_NEIGHBORS];
oneminusq = new float[FluidSystem.MAX_NEIGHBORS];
entitiesToInfluence = new int[MAX_INFLUENCES];
fixturesToTest = new Fixture[MAX_FIXTURES_TO_TEST];
collisionVertices = new Vector2[Settings.MaxPolygonVertices];
collisionNormals = new Vector2[Settings.MaxPolygonVertices];
int i = fluidSystem.getFluidGridX(position.X);
int j = fluidSystem.getFluidGridY(position.Y);
if (!fluidSystem.fluidGrid.ContainsKey(i))
fluidSystem.fluidGrid[i] = new Dictionary<int, List<int>>();
if (!fluidSystem.fluidGrid[i].ContainsKey(j))
fluidSystem.fluidGrid[i][j] = new List<int>();
fluidSystem.fluidGrid[i][j].Add(index);
ci = i;
cj = j;
}
示例3: Terrain
/// <summary>
/// Creates a new terrain.
/// </summary>
/// <param name="world">The World</param>
/// <param name="area">The area of the terrain.</param>
public Terrain(World world, AABB area)
{
World = world;
Width = area.Width;
Height = area.Height;
Center = area.Center;
}
示例4: GetBodyAtMouse
public virtual Body GetBodyAtMouse(bool includeStatic)
{
// Make a small box
mousePVec.X = MouseXWorldPhys;
mousePVec.Y = MouseYWorldPhys;
FVector2 lowerBound = new FVector2(MouseXWorldPhys - 0.001f, MouseYWorldPhys - 0.001f);
FVector2 upperBound = new FVector2(MouseXWorldPhys + 0.001f, MouseYWorldPhys + 0.001f);
AABB aabb = new AABB(lowerBound, upperBound);
Body body = null;
// Query the world for overlapping shapes
System.Func<Fixture, bool> GetBodyCallback = delegate (Fixture fixture0)
{
Shape shape = fixture0.Shape;
if(fixture0.Body.BodyType != BodyType.Static || includeStatic)
{
FarseerPhysics.Common.Transform transform0;
fixture0.Body.GetTransform(out transform0);
bool inside = shape.TestPoint(ref transform0, ref mousePVec);
if(inside)
{
body = fixture0.Body;
return false;
}
}
return true;
};
FSWorldComponent.PhysicsWorld.QueryAABB(GetBodyCallback, ref aabb);
return body;
}
示例5: BuoyancyTest
private BuoyancyTest()
{
World.Gravity = new Vector2(0, -9.82f);
BodyFactory.CreateEdge(World, new Vector2(-40, 0), new Vector2(40, 0));
float offset = 5;
for (int i = 0; i < 3; i++)
{
Body rectangle = BodyFactory.CreateRectangle(World, 2, 2, 1, new Vector2(-30 + offset, 20));
rectangle.Rotation = Rand.RandomFloat(0, 3.14f);
rectangle.BodyType = BodyType.Dynamic;
offset += 7;
}
for (int i = 0; i < 3; i++)
{
Body rectangle = BodyFactory.CreateCircle(World, 1, 1, new Vector2(-30 + offset, 20));
rectangle.Rotation = Rand.RandomFloat(0, 3.14f);
rectangle.BodyType = BodyType.Dynamic;
offset += 7;
}
AABB container = new AABB(new Vector2(0, 10), 60, 10);
BuoyancyController buoyancy = new BuoyancyController(container, 2, 2, 1, World.Gravity);
World.AddController(buoyancy);
}
示例6: QuadTreeBroadPhase
/// <summary>
/// Creates a new quad tree broadphase with the specified span.
/// </summary>
/// <param name="span">the maximum span of the tree (world size)</param>
public QuadTreeBroadPhase(AABB span)
{
QuadTree = new QuadTree<FixtureProxy>(span, 5, 10);
_idRegister = new Dictionary<int, Element<FixtureProxy>>();
_moveBuffer = new List<Element<FixtureProxy>>();
_pairBuffer = new List<Pair>();
}
示例7: Update
public override void Update()
{
base.Update();
// udpate selected body
if (SelectedBody != null)
{
if (SelectedBody.IsDisposed || !SelectedBody.Enabled)
SelectedBody = null;
}
// update highlighted body
if(!UI.Mouse.ScreenPosition.IsStriclyInside(Render.Viewport.Area))
return;
var mousePos = UI.Mouse.WorldPosition;
var aabb = new AABB(mousePos, .001f, .001f);
HighlightedBody = null;
Physic.World.QueryAABB(OnMouseOverFixture, ref aabb);
if (HighlightedBody != null)
{
Focus();
}
else
{
Unfocus();
}
}
示例8: GetFatAABB
public void GetFatAABB(int proxyID, out AABB aabb)
{
if (_idRegister.ContainsKey(proxyID))
aabb = _idRegister[proxyID].Span;
else
throw new KeyNotFoundException("proxyID not found in register");
}
示例9: attemptRopeGrab
public void attemptRopeGrab(string levelUid, int characterId, CharacterMovementComponent characterMovementComponent, PhysicsComponent physicsComponent, RopeGrabComponent existingRopeGrabComponent)
{
float margin = 0.5f;
AABB region = new AABB();
RopeNode ropeNode = null;
int nodeCount = 0;
region.LowerBound = physicsComponent.body.Position - new Vector2(margin, margin);
region.UpperBound = physicsComponent.body.Position + new Vector2(margin, margin);
if (physicsComponent == null)
return;
// Query the world for a body, and check to see if it's a rope
physicsComponent.body.World.QueryAABB((fixture) =>
{
int ropeEntityId = (int)fixture.Body.UserData;
RopeComponent ropeComponent = (RopeComponent)_entityManager.getComponent(levelUid, ropeEntityId, ComponentType.Rope);
RopeGrabComponent ropeGrabComponent = null;
if (ropeComponent != null && !ropeComponent.doubleAnchor)
{
RopeNode current = ropeComponent.ropeNodeHead;
characterMovementComponent.allowRopeGrab = false;
while (current != null)
{
if (current.body == fixture.Body)
{
ropeNode = current;
break;
}
nodeCount++;
current = current.next;
}
if (existingRopeGrabComponent != null)
{
RopeComponent existingRopeComponent = (RopeComponent)_entityManager.getComponent(levelUid, existingRopeGrabComponent.ropeEntityId, ComponentType.Rope);
if (existingRopeComponent.destroyAfterRelease)
existingRopeComponent.timeToLive = 100;
_ropeSystem.releaseRope(existingRopeGrabComponent, physicsComponent.body);
_entityManager.removeComponent(levelUid, characterId, existingRopeGrabComponent);
}
ropeGrabComponent = new RopeGrabComponent(ropeEntityId, ropeNode, (float)nodeCount, ropeComponent.reverseClimbDirection);
_ropeSystem.grabRope(ropeGrabComponent, physicsComponent.body);
_entityManager.addComponent(levelUid, characterId, ropeGrabComponent);
return false;
}
return true;
},
ref region);
}
示例10: Midgard
public Midgard(AABB boundBox, Vector2 gravity, int tickRate)
{
_tickRate = tickRate;
_invTickRate = 1f / (float)_tickRate;
FarseerPhysics.Settings.ContinuousPhysics = false;
_world = new World(gravity);
}
示例11: Water
/// <summary>
///
/// </summary>
/// <param name="game"></param>
/// <param name="world"></param>
/// <param name="position">The top left corner</param>
/// <param name="width">The width of the container</param>
/// <param name="height">The height of a container</param>
public Water(Game game, SpriteBatch spriteBatch, World world, Vector2 position, float width, float height)
{
sprite = new LoopSpriteAnimator(game, spriteBatch, game.Content.Load<Texture2D>("Images/Sprites/gb"), 200, 6, 1, 6);
position = new Vector2(position.X + width/2,position.Y + height/2);
texture = new TexturedGameEntity(game, position,0,"Images/water",0.3f);
var container = new AABB(ConvertUnits.ToSimUnits(position),ConvertUnits.ToSimUnits(width),ConvertUnits.ToSimUnits(height));
var buoyancy = new BuoyancyController(container, 1.1f, 2, 1, world.Gravity);
world.AddController(buoyancy);
}
示例12: BuoyancyController
/// <summary>
/// Initializes a new instance of the <see cref="BuoyancyController"/> class.
/// </summary>
/// <param name="container">Only bodies inside this AABB will be influenced by the controller</param>
/// <param name="density">Density of the fluid</param>
/// <param name="linearDragCoefficient">Linear drag coefficient of the fluid</param>
/// <param name="rotationalDragCoefficient">Rotational drag coefficient of the fluid</param>
/// <param name="gravity">The direction gravity acts. Buoyancy force will act in opposite direction of gravity.</param>
public BuoyancyController(AABB container, float density, float linearDragCoefficient, float rotationalDragCoefficient, Vector2 gravity)
: base(ControllerType.BuoyancyController)
{
Container = container;
_normal = new Vector2(0, 1);
Density = density;
LinearDragCoefficient = linearDragCoefficient;
AngularDragCoefficient = rotationalDragCoefficient;
_gravity = gravity;
}
示例13: Emit
public void Emit()
{
var p = UI.Mouse.WorldPosition;
var aabb = new AABB(p, 0.01f, 0.01f);
var bodies = Physic.World.QueryAABB(ref aabb);
if(bodies.Any())
return;
_emitter.StartEmitting();
}
示例14: DrawAABB
public void DrawAABB(ref AABB aabb, Color color)
{
Vector2[] verts = new Vector2[4];
verts[0] = new Vector2(aabb.LowerBound.X, aabb.LowerBound.Y);
verts[1] = new Vector2(aabb.UpperBound.X, aabb.LowerBound.Y);
verts[2] = new Vector2(aabb.UpperBound.X, aabb.UpperBound.Y);
verts[3] = new Vector2(aabb.LowerBound.X, aabb.UpperBound.Y);
DrawPolygon(verts, 4, color);
}
示例15: TestThinningAndFattening
public void TestThinningAndFattening()
{
var aabb = new AABB(new Vector2(-10, 5), new Vector2(0, 35));
Assert.AreEqual(aabb, aabb.Thinned.Fattened);
Assert.AreEqual(aabb, aabb.Fattened.Thinned);
AssertFattened(new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0));
AssertThinned(new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0));
AssertFattened(new Vector2(0, 0), new Vector2(40, 40), new Vector2(10, 10), new Vector2(30, 30));
AssertThinned(new Vector2(-40, -40), new Vector2(-20, -20), new Vector2(-50, -50), new Vector2(-10, -10));
}