本文整理汇总了C#中FarseerPhysics.Dynamics.Fixture类的典型用法代码示例。如果您正苦于以下问题:C# Fixture类的具体用法?C# Fixture怎么用?C# Fixture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Fixture类属于FarseerPhysics.Dynamics命名空间,在下文中一共展示了Fixture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreaBody_OnSeparation
public void AreaBody_OnSeparation(Fixture fixa, Fixture fixb)
{
if (fixb.Body.BodyId == 19)
{
isTouchingPickUp = false;
}
}
示例2: CreateBody
public override Body CreateBody(World world)
{
Int32 count = 0;
foreach (var key in _resource.TileDefinitionKeys)
{
var tileDefinition = (TerrainTileDefinitionResource)ResourceDictionary.GetResource(key);
if (!String.IsNullOrEmpty(tileDefinition.CollisionHullKey))
{
var vertices = new Vertices((Vector2[])this.ResourceDictionary.GetResource(tileDefinition.CollisionHullKey));
var body = new Body(world);
_bodies.Add(body);
body.BodyType = BodyType.Static;
var location = ((ILocatable)_actor).Location;
body.Position = new Vector2(((count % _resource.Columns) * _resource.TileWidth + location.X) / Settings.MetersToPixels, ((Int32)(count / _resource.Columns) * _resource.TileHeight + location.Y) / Settings.MetersToPixels);
var shape = new PolygonShape(vertices, 0f);
var fixture = new Fixture(body, shape, 1.0f);
fixture.UserData = new CollisionData { Actor = _actor, Data = tileDefinition.CollisionData };
}
count++;
}
return null;
}
示例3: OnCollision
protected override bool OnCollision(Fixture projectile, Fixture collided, Contact contact)
{
if (NoCollide)
return false;
var collidedUnit = (collided.Body.UserData is Unit) ? (Unit)(collided.Body.UserData) : null;
if (collidedUnit != null) {
if (collidedUnit == Owner) {
Owner.ModifyAttackCooldown(-1000f);
Expire();
}
else {
foreach (Aura aura in Auras) {
collidedUnit.AddAura(aura);
}
collidedUnit.Hurt(Damage);
Body.LinearVelocity = Vector2.Zero;
Body.IgnoreGravity = false;
Body.ApplyLinearImpulse(new Vector2((Owner.Position.X - collidedUnit.Position.X)*7, -200));
Body.ApplyTorque(-2000f);
Body.CollidesWith = Category.Cat1 | Category.Cat2;
Body.CollisionCategories = Category.Cat5;
}
}
return false;
}
示例4: Turret
public Turret(Vector2 farseerLoc, World w, RagdollManager r, Fixture f)
{
DebugMaterial gray = new DebugMaterial(MaterialType.Blank)
{
Color = Color.DarkGray
};
body = new Body(w);
pivot = FixtureFactory.AttachCircle(.9f, 1, body, gray);
FixtureFactory.AttachRectangle(barrelLength, .5f, 1, new Vector2(barrelLength / 2, 0), body, gray);
body.Position = farseerLoc;
body.BodyType = BodyType.Dynamic;
//b.CollidesWith = Category.None;
if (f == null)
{
motor = JointFactory.CreateFixedRevoluteJoint(w, body, Vector2.Zero, farseerLoc);
}
else
{
motor = new RevoluteJoint(body, f.Body, Vector2.Zero, f.Body.GetLocalPoint(farseerLoc));
w.AddJoint(motor);
}
motor.MotorEnabled = true;
motor.MaxMotorTorque = 5000;
Init(w, r);
}
示例5: ProximityTrigger
public ProximityTrigger(Body sensorBody, Fixture sensorTemplate)
{
this.sensorBody = sensorBody;
this.CreateSensors(sensorTemplate);
this.IsEnabled = true;
this.IsContinuous = false;
}
示例6: body_OnCollision
bool body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
{
if (body.BodyType == BodyType.Static) return true;
Fixture surface;
if (fixtureA.Body == body)
surface = fixtureB;
else
surface = fixtureA;
if (surface.Body.BodyType == BodyType.Static && surface.Shape.MassData.Area > 100)
{
// rotate to contact normal
Vector2 normal = contact.Manifold.LocalNormal;
if (Vector2.Dot(normal, body.LinearVelocity) > 0)
{
return false;
}
isPendingAttach = true;
pendingRotation = (float)Math.Atan2(normal.Y, normal.X);
body.CollidesWith = Category.None;
return false;
}
return true;
}
示例7: CollisionWithEnemy
// Collision handlers
public bool CollisionWithEnemy(Fixture f1, Fixture f2, Contact contact)
{
Vector2 normal;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal, out points);
foreach (IGameComponent comp in this.game.Components)
{
GameEnemy enemy = comp as GameEnemy;
if (enemy != null)
{
if (enemy.getFixture() == f2)
{
if ((Math.Abs(normal.Y) > Math.Abs(normal.X)) && (normal.Y < 0)) // The contact is coming from above
{
enemy.Die(); // Uncomment this line if we decide to fix the timing so we dispose after the animation
this.increaseScore(10);
this.Jump();
break;
}
else
{
this.Die();
}
break;
}
}
}
return true;
}
示例8: OnCollision
public virtual bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
Vector2 normal = Vector2.Zero;
Contact currentContact = contact;
Vector2 nextNormal = Vector2.Zero;
FixedArray2<Vector2> fx; // No idea what that is, but the function wants it
// Iterate through the contacts, summing the normals
do
{
Vector2 vec = Vector2.Zero;
contact.GetWorldManifold(out vec, out fx);
normal += vec;
currentContact = currentContact.Next;
} while (currentContact != null);
if (normal.Y > Y && normal.X == 0)
{
Pressed = true;
_pressing.Add(fixtureB);
}
return true;
}
示例9: Ship
public Ship(World world, SpawnData spawn, int id)
{
Ball = null;
Id = id;
IsThrusting = false;
IsReversing = false;
IsBoosting = false;
IsLeftTurning = false;
IsRightTurning = false;
IsShooting = false;
IsBlocked = false;
IsBlockedFrame = false;
Color = spawn.Color;
var body = new Body(world);
body.Rotation = FMath.Atan2(-spawn.Position.Y, -spawn.Position.X);
body.Position = spawn.Position;
var shape = new CircleShape(radius, 1f);
body.BodyType = BodyType.Dynamic;
body.FixedRotation = true;
Fixture = body.CreateFixture(shape);
Fixture.Restitution = restitution;
var bodyGravity = new Body(world);
bodyGravity.Position = spawn.Position;
var shapeGravity = new CircleShape(radiusGravity, 1f);
bodyGravity.FixedRotation = true;
FixtureGravity = bodyGravity.CreateFixture(shapeGravity);
FixtureGravity.IsSensor = true;
}
示例10: HandleRaycast
private float HandleRaycast(Fixture fixture, Vector2 point, Vector2 normal, float fraction)
{
if (fixture.CollisionCategories == _type.Category)
return fraction;
var dist = (point - Body.Position).Length();
var linksCount = (int)(Math.Floor(dist / LinksHeight) / 2);
if (linksCount == 0)
return fraction;
// TODO: adapt this to Farseer 3.5
/*var chain = Add(K2.World.CreateChain(Body.Position, point, .005f, LinksHeight, linksCount, 1, false));
if (!chain.Bodies.Any())
return 0;
chain.Bodies.ForEach(b => b.SetCollisionType(_type));
var first = chain.Bodies.First();
var last = chain.Bodies.Last();
K2.World.CreateRevoluteJoint(fixture.Body, last, new Vector2(0, LinksHeight));
K2.World.CreateRevoluteJoint(Body, chain.Bodies.First(), Vector2.Zero);
//_joint = _factory.CreateDistanceJoint(first, last, new Vector2(0, LinksHeight), Vector2.Zero);*/
return 0;
}
示例11: PhysicsGameObject
public PhysicsGameObject(Texture2D texture, World world, bool isStatic,
Vector2 position, float scale, float density, float depth)
{
this.texture = texture;
this.scale = scale;
this.density = density;
this.depth = depth;
//loads body details
objectBody = new Body(world);
objectBody.Position = position;
if (isStatic)
objectBody.BodyType = BodyType.Static;
else
objectBody.IsStatic = false;
this.scale = scale;
this.depth = depth;
//loads fixture details
objectFixture = FixtureFactory.AttachRectangle(
texture.Width / PIXELS_PER_METER,
texture.Height / PIXELS_PER_METER,
1, Vector2.Zero, objectBody);
objectFixture.Restitution = RESTITUTION;
objectFixture.Friction = FRICTION;
}
示例12: LoadContent
public void LoadContent(ContentManager content, World world, Vector2 position, Vector2 size)
{
body = BodyFactory.CreateRectangle(world, size.X, size.Y, 1f);
body.FixedRotation = true;
body.FixtureList[0].UserData = 9000;
body.Position = ConvertUnits.ToSimUnits(position);
body.BodyType = BodyType.Dynamic;
CircleShape circle1 = new CircleShape(size.X / 4, 1f);
CircleShape circle2 = new CircleShape(size.Y / 6, 1f);
CircleShape circle3 = new CircleShape(size.Y / 6, 1f);
circle1.Position = new Vector2(0, -size.Y / 3);
circle2.Position = new Vector2(-1.5f * size.X / 5, -size.Y / 10);
circle3.Position = new Vector2(-0.4f * size.X / 5, -size.Y / 10);
head = body.CreateFixture(circle1);
hands[0] = body.CreateFixture(circle2);
hands[1] = body.CreateFixture(circle3);
head.UserData = (int)10000;
hands[0].UserData = (int)11000;
hands[1].UserData = (int)11000;
image.LoadContent(content, "Graphics/tezka", Color.White, position);
image.ScaleToMeters(size);
image.position = ConvertUnits.ToDisplayUnits(body.Position);
}
示例13: DebrisComponent
public DebrisComponent(Fixture fixture, int timeToLive, float restitutionIncrement)
{
_fixture = fixture;
_timeToLive = timeToLive;
_restitutionIncrement = restitutionIncrement;
_restitutionCount = 0;
}
示例14: ColEvent
public ColEvent(EventType type, Fixture fxA, Fixture fxB, CollisionData data)
{
this.Type = type;
this.FixtureA = fxA;
this.FixtureB = fxB;
this.Data = data;
}
示例15: OnCollisionExit
public override void OnCollisionExit(Fixture fixtureA, Fixture fixtureB)
{
//Is the CameraObject for the X or Y axis?
if (this.height > this.width) // It is for the X axis
{
//Check which side the player is leaving
if (fixtureB.Body.Position.X < fixtureA.Body.Position.X && fixtureB.Body.LinearVelocity.X < 0) //Player is moving to the left
{
if (this.unlockDirection == UnlockWhenPlayerMovesLeft)
{
this.UnlockCameraHorizontally();
}
else
{
this.LockCameraHorizontally();
}
}
else if (fixtureB.Body.Position.X > fixtureA.Body.Position.X && fixtureB.Body.LinearVelocity.X > 0) //Player is moving to the right
{
if (this.unlockDirection == UnlockWhenPlayerMovesRight)
{
this.UnlockCameraHorizontally();
}
else
{
this.LockCameraHorizontally();
}
}
}
else //It is for the Y axis
{
}
}