本文整理汇总了C#中FarseerPhysics.Dynamics.Contacts.Contact.GetWorldManifold方法的典型用法代码示例。如果您正苦于以下问题:C# Contact.GetWorldManifold方法的具体用法?C# Contact.GetWorldManifold怎么用?C# Contact.GetWorldManifold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Dynamics.Contacts.Contact
的用法示例。
在下文中一共展示了Contact.GetWorldManifold方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: PreSolve
private void PreSolve(Contact contact, ref Manifold oldManifold)
{
if ((Flags & DebugViewFlags.ContactPoints) == DebugViewFlags.ContactPoints)
{
Manifold manifold = contact.Manifold;
if (manifold.PointCount == 0)
return;
Fixture fixtureA = contact.FixtureA;
FixedArray2<PointState> state1, state2;
Collision.Collision.GetPointStates(out state1, out state2, ref oldManifold, ref manifold);
FixedArray2<Vector2> points;
Vector2 normal;
contact.GetWorldManifold(out normal, out points);
for (int i = 0; i < manifold.PointCount && _pointCount < MaxContactPoints; ++i)
{
if (fixtureA == null)
_points[i] = new ContactPoint();
ContactPoint cp = _points[_pointCount];
cp.Position = points[i];
cp.Normal = normal;
cp.State = state2[i];
_points[_pointCount] = cp;
++_pointCount;
}
}
}
示例3: 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;
}
示例4: SolveChangeDirection
private void SolveChangeDirection(Contact contact)
{
Vector2 normal;
FixedArray2<Vector2> array;
contact.GetWorldManifold(out normal, out array);
if (Math.Abs(normal.X) < Comparator.EPS)
return;
Transform transform;
phys_body.GetTransform(out transform);
if (array[0].X < transform.p.X)
rotation = 1;
else
rotation = -1;
}
示例5: OpenTrap
private bool OpenTrap(Fixture a, Fixture b, Contact c)
{
if (b.Body.UserData is Wall)
{
Vector2 normal;
FarseerPhysics.Common.FixedArray2<Vector2> pointlist;
c.GetWorldManifold(out normal, out pointlist);
Vector2 position = pointlist[0];
// Create open trap
body.UserData = null;
}
return c.IsTouching;
}
示例6: OnCollision
bool OnCollision(Fixture platformFixture, Entity entity, Fixture entityFixture, Contact contact)
{
if (entityFixture.IsSensor)
return false;
bool result = false;
if (!collided.Contains(entityFixture))
{
Vector2 normal;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal, out points);
//check if contact points are moving into platform
for (int i = 0; i < contact.Manifold.PointCount; i++)
{
var pointVelPlatform = platformFixture.Body.GetLinearVelocityFromWorldPoint(points[i]);
var pointVelEntity = entity.Physics.GetLinearVelocityFromWorldPoint(points[i]);
var relativeVel = platformFixture.Body.GetLocalVector(pointVelEntity - pointVelPlatform);
if (relativeVel.Y > 1) //if moving down faster than 1 m/s, handle as before
{
result = true;//point is moving into platform, leave contact solid and exit
break;
}
else if (relativeVel.Y > -1)
{
//if moving slower than 1 m/s
//borderline case, moving only slightly out of platform
var relativePoint = platformFixture.Body.GetLocalPoint(points[i]);
float platformFaceY = 0.5f;//front of platform, from fixture definition :(
if (relativePoint.Y > platformFaceY - 0.05)
{
result = true;//contact point is less than 5cm inside front face of platfrom
break;
}
}
}
}
collided.Add(entityFixture);
return result;
}
示例7: onCollision
protected virtual bool onCollision(Fixture f1, Fixture f2, Contact contact)
{
Fixture obstacle = (f1 == PhysicsBody) ? f2 : f1;
//if beneath the feet, treat it as ground
WorldManifold manifold;
contact.GetWorldManifold(out manifold);
if (contact.IsTouching())
{
if (isGround(manifold, obstacle))
{
ground.Add(obstacle);
groundNormal = manifold.Normal;
groundVector = getGroundVector();
groundSlope = groundVector.Y / groundVector.X;
//Console.Out.WriteLine("OnCollision called");
}
}
return true;
}
示例8: PhysicsPostSolve
private void PhysicsPostSolve(Fixture f1, Fixture f2, Contact contact)
{
Fixture self = null, other = null;
Vector2 normal;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal, out points);
if (contact.FixtureA == _fsFixture)
{
self = contact.FixtureA;
other = contact.FixtureB;
}
else if (contact.FixtureB == _fsFixture)
{
self = contact.FixtureB;
other = contact.FixtureA;
}
// sticky behavior: null out all velocity normal to the surface of the wall,
// apply some shitty fake friction to the velocity parallel to the surface of the wall.
Vector2 normalComponent, parallelComponent;
normalComponent = normal * Vector2.Dot(normal, other.Body.LinearVelocity);
parallelComponent = other.Body.LinearVelocity - normalComponent;
float velMultiplier = 1f - Stickiness * (1 / 100000f);
Vector2 newVelocity;
if (other.Body.LinearVelocity.Length() < 1e-10 || parallelComponent.Length() < 1e-10)
{
newVelocity = Vector2.Zero;
}
else if (other.Body.LinearVelocity.Y > 0)
{
newVelocity = parallelComponent * Math.Min(parallelComponent.Length(), UpwardSpeedLimit) / parallelComponent.Length();
}
else
{
newVelocity = parallelComponent * velMultiplier;
}
other.Body.LinearVelocity = newVelocity;
}
示例9: SolveContact
private void SolveContact(Contact contact)
{
Vector2 norm;
FixedArray2<Vector2> array;
contact.GetWorldManifold(out norm, out array);
if (array[0].Y <= GetPosition().Y && array[1].Y <= GetPosition().Y)
canUp = 2;
}
示例10: PostSolve
public void PostSolve(Contact contact, ContactConstraint contactConstraint)
{
string levelUid = LevelSystem.currentLevelUid;
List<int> characterEntities = _entityManager.getEntitiesPosessing(levelUid, ComponentType.CharacterMovement);
int entityAId = (int)contact.FixtureA.Body.UserData;
int entityBId = (int)contact.FixtureB.Body.UserData;
CharacterMovementComponent characterMovementComponent = null;
FixedArray2<Vector2> points;
Vector2 normal;
characterMovementComponent = (_entityManager.getComponent(levelUid, entityAId, ComponentType.CharacterMovement) ?? _entityManager.getComponent(levelUid, entityBId, ComponentType.CharacterMovement)) as CharacterMovementComponent;
if (characterMovementComponent != null)
{
if (contact.FixtureA == characterMovementComponent.feetFixture || contact.FixtureB == characterMovementComponent.feetFixture)
{
contact.GetWorldManifold(out normal, out points);
characterMovementComponent.collisionNormals.Add(normal);
//if (characterMovementComponent.allowJumpResetOnCollision)
// characterMovementComponent.alreadyJumped = false;
}
}
}
示例11: BeginContact
public bool BeginContact(Contact contact)
{
string levelUid = LevelSystem.currentLevelUid;
List<int> levelGoalEntities = _entityManager.getEntitiesPosessing(levelUid, ComponentType.RegionGoal);
List<int> explosionEntities = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Explosion);
LevelSystem levelSystem = (LevelSystem)_systemManager.getSystem(SystemType.Level);
ExplosionSystem explosionSystem = (ExplosionSystem)_systemManager.getSystem(SystemType.Explosion);
int playerId = PlayerSystem.PLAYER_ID;
// See if player is touching a level goal
if (levelGoalEntities.Count > 0)
{
int entityA = (int)contact.FixtureA.Body.UserData;
int entityB = (int)contact.FixtureB.Body.UserData;
if (entityA == playerId)
{
if (levelGoalEntities.Contains(entityB))
levelSystem.completeRegionGoal(entityB);
}
else if (entityB == playerId)
{
if (levelGoalEntities.Contains(entityA))
levelSystem.completeRegionGoal(entityA);
}
}
// Explosions
if (explosionEntities.Count > 0)
{
int entityA = (int)contact.FixtureA.Body.UserData;
int entityB = (int)contact.FixtureB.Body.UserData;
IComponent component = null;
ExplosionComponent explosionComponent = null;
Fixture targetFixture = null;
FixedArray2<Vector2> points;
if (_entityManager.tryGetComponent(levelUid, entityA, ComponentType.Explosion, out component))
targetFixture = contact.FixtureB;
else if (_entityManager.tryGetComponent(levelUid, entityB, ComponentType.Explosion, out component))
targetFixture = contact.FixtureA;
if (targetFixture != null && component != null)
{
DestructibleGeometryComponent destructibleGeometryComponent = (DestructibleGeometryComponent)_entityManager.getComponent(levelUid, (int)targetFixture.Body.UserData, ComponentType.DestructibleGeometry);
Vector2 contactNormal;
Vector2 relative;
Vector2 force;
float distance;
//contact.GetWorldManifold(out worldManifold);
contact.GetWorldManifold(out contactNormal, out points);
explosionComponent = (ExplosionComponent)component;
relative = (targetFixture.Shape.Center + targetFixture.Body.Position) - explosionComponent.position;
distance = Math.Max(relative.Length(), 0.1f);
force = relative * (1 / distance) * explosionComponent.strength;
if (destructibleGeometryComponent != null)
{
// Break fixture off from body
explosionSystem.breakFixture(targetFixture, force, 180);
return false;
}
else
{
// Apply generic explosion force
targetFixture.Body.ApplyForce(force, points[0]);
return false;
}
}
}
return true;
}
示例12: dog_OnCollision
public static bool dog_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
GameObject dog = (GameObject)fixtureA.Body.UserData;
GameObject otherObject = (GameObject)fixtureB.Body.UserData;
Vector2 normal;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal, out points);
Vector2 collidePoint = ConvertUnits.ToDisplayUnits(points[0]);
dog.collisioncount++;
if (otherObject.typeid == (int)GameObjectTypes.GROUND)
{
if (dog.collisioncount == 1)
{
SunManager.Instance.Mood = SunMood.MAD;
AudioManager.Instance.SoundEffect("dog_oof").Play(0.5f, 0, 0);
if (dog.sprite.PlayerNumber == 1)
{
ScoreKeeper.Instance.PlayerLeftScore -= ScoreKeeper.Missing;
}
if (dog.sprite.PlayerNumber == 2)
{
ScoreKeeper.Instance.PlayerRightScore -= ScoreKeeper.Missing;
}
SpriteHelper.Instance.TriggerAfter(delegate()
{
AudioManager.Instance.SoundEffect("cat_soclose").Play(0.5f, 0, 0);
}, 1000);
}
//SpriteHelper.Instance.RemoveAfter(dog.id, 8000);
if (dog.alive)
{
dog.alive = false;
SpriteHelper.Instance.TriggerAfter(delegate()
{
if (dog.sprite != null)
{
Vector2 dogCenter = dog.sprite.Center;
SpriteHelper.Instance.TriggerAnimation(GameObjectTypes.PUFF, dogCenter - new Vector2(128, 128), "spritesheet", 15);
}
SpriteHelper.Instance.TriggerAfter(delegate()
{
GameObjectFactory.Instance.Remove(dog.id);
}, 100);
}, 6000);
return true;
}
}
else if (otherObject.typeid == (int)GameObjectTypes.CAT)
{
if (dog.collisioncount == 1)
{
Instance.NewestCollision = dog.sprite.PlayerNumber;
}
}
//something here giving 50 points
else if (otherObject.typeid == (int)GameObjectTypes.DOG)
{
SpriteHelper.Instance.TriggerAfter(delegate()
{
if (otherObject.sprite != null)
{
Vector2 otherCenter = otherObject.sprite.Center;
SpriteHelper.Instance.TriggerAnimation(GameObjectTypes.PUFF, otherCenter - new Vector2(128, 128), "spritesheet", 15);
}
SpriteHelper.Instance.TriggerAfter(delegate()
{
GameObjectFactory.Instance.Remove(otherObject.id);
}, 100);
}, 1000);
if (dog.collisioncount == 1)
{
AudioManager.Instance.SoundEffect("dog_impact").Play(0.5f, 0, 0);
}
}
else if (otherObject.typeid == (int)GameObjectTypes.WOOD1 ||
otherObject.typeid == (int)GameObjectTypes.WOOD2 ||
otherObject.typeid == (int)GameObjectTypes.WOOD3 ||
otherObject.typeid == (int)GameObjectTypes.WOOD4
)
{
SunManager.Instance.Mood = SunMood.TOOTHYSMILE;
//otherObject.collisiontime = System.Environment.TickCount;
//otherObject.sprite.PlayerNumber = dog.sprite.PlayerNumber;
//.........这里部分代码省略.........
示例13: IsContactValid
/// <summary>
/// Returns true if a contact should not be disabled due to portal clipping.
/// </summary>
private bool IsContactValid(Contact contact)
{
FixtureData[] fixtureData = new FixtureData[2];
fixtureData[0] = FixtureExt.GetData(contact.FixtureA);
fixtureData[1] = FixtureExt.GetData(contact.FixtureB);
BodyData[] bodyData = new BodyData[2];
bodyData[0] = BodyExt.GetData(contact.FixtureA.Body);
bodyData[1] = BodyExt.GetData(contact.FixtureB.Body);
Xna.Vector2 normal;
FixedArray2<Xna.Vector2> vList;
contact.GetWorldManifold(out normal, out vList);
if (bodyData[0].IsChild || bodyData[1].IsChild)
{
if (bodyData[0].IsChild && bodyData[1].IsChild)
{
//return true;
}
int childIndex = bodyData[0].IsChild ? 0 : 1;
int otherIndex = bodyData[0].IsChild ? 1 : 0;
BodyData bodyDataChild = bodyData[childIndex];
BodyData bodyDataOther = bodyData[otherIndex];
FixtureData fixtureDataChild = fixtureData[childIndex];
FixtureData fixtureDataOther = fixtureData[otherIndex];
}
//Contact is invalid if it is between two fixtures where one fixture is colliding with a portal on the other fixture.
if (fixtureData[0].IsPortalParentless() && fixtureData[1].IsPortalParentless())
{
for (int i = 0; i < fixtureData.Length; i++)
{
int iNext = (i + 1) % fixtureData.Length;
var intersection = fixtureData[iNext].GetPortalChildren().Intersect(fixtureData[i].PortalCollisions);
if (intersection.Count() > 0)
{
//Debug.Fail("Fixtures with portal collisions should be filtered.");
return false;
}
}
}
//Contact is invalid if it is too close to a portal.
foreach (IPortal p in Scene.GetPortalList())
{
if (!Portal.IsValid(p))
{
continue;
}
FixturePortal portal = p as FixturePortal;
if (portal != null)
{
//Don't consider this portal if its fixtures are part of the contact.
if (fixtureData[0].PartOfPortal(portal) || fixtureData[1].PartOfPortal(portal))
{
continue;
}
LineF line = new LineF(Portal.GetWorldVerts(portal));
double[] vDist = new double[] {
MathExt.PointLineDistance(vList[0], line, true),
MathExt.PointLineDistance(vList[1], line, true)
};
//Only consider contacts that are between the fixture this portal is parented too and some other fixture.
if (contact.FixtureA == FixtureExt.GetFixtureAttached(portal) || contact.FixtureB == FixtureExt.GetFixtureAttached(portal))
{
if (contact.Manifold.PointCount == 1)
{
if (vDist[0] < FixturePortal.CollisionMargin)
{
return false;
}
}
else if (vDist[0] < FixturePortal.CollisionMargin && vDist[1] < FixturePortal.CollisionMargin)
{
return false;
}
}
}
}
//Contact is invalid if it is on the opposite side of a colliding portal.
for (int i = 0; i < fixtureData.Length; i++)
{
int iNext = (i + 1) % fixtureData.Length;
foreach (IPortal portal in fixtureData[i].PortalCollisions)
{
LineF line = new LineF(Portal.GetWorldVerts(portal));
FixturePortal cast = portal as FixturePortal;
if (cast != null)
{
if (fixtureData[i].PartOfPortal(cast) || fixtureData[iNext].PartOfPortal(cast))
{
//.........这里部分代码省略.........
示例14: AfterLowerShapeCollision
private void AfterLowerShapeCollision(Fixture fA, Fixture fB, Contact contact)
{
var v = new Vector2();
var fa = new FixedArray2<Vector2>();
contact.GetWorldManifold(out v, out fa);
v = fa[0];
_groundContactPoint = v;
if (v.Y > Body.Position.Y + 1.1f)
IsTouchingGround = true;
contact.Enabled = true;
}
示例15: OnAfterCollision
public void OnAfterCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
Vector2 vec = Vector2.Zero;
FixedArray2<Vector2> fx;
contact.GetWorldManifold(out vec, out fx);
for (int i = 0; i < contact.Manifold.PointCount; i++)
{
fx[i].Normalize();
}
}