本文整理汇总了C#中BEPUphysics.BroadPhaseEntries.Collidable类的典型用法代码示例。如果您正苦于以下问题:C# Collidable类的具体用法?C# Collidable怎么用?C# Collidable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Collidable类属于BEPUphysics.BroadPhaseEntries命名空间,在下文中一共展示了Collidable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RayCast
/// <summary>
/// Computes the intersection, if any, between a ray and the objects in the character's bounding box.
/// </summary>
/// <param name="ray">Ray to test.</param>
/// <param name="length">Length of the ray to use in units of the ray's length.</param>
/// <param name="earliestHit">Earliest intersection location and information.</param>
/// <param name="hitObject">Collidable intersected by the ray, if any.</param>
/// <returns>Whether or not the ray hit anything.</returns>
public bool RayCast(Ray ray, float length, out RayHit earliestHit, out Collidable hitObject)
{
earliestHit = new RayHit();
earliestHit.T = float.MaxValue;
hitObject = null;
foreach (var collidable in characterBody.CollisionInformation.OverlappedCollidables)
{
//Check to see if the collidable is hit by the ray.
float t;
if (ray.Intersects(ref collidable.boundingBox, out t) && t < length)
{
//Is it an earlier hit than the current earliest?
RayHit hit;
if (collidable.RayCast(ray, length, SupportRayFilter, out hit) && hit.T < earliestHit.T)
{
earliestHit = hit;
hitObject = collidable;
}
}
}
if (earliestHit.T == float.MaxValue)
return false;
return true;
}
示例2: CollisionDetectedHandler
private void CollisionDetectedHandler(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
EntityCollidable otherEntityCollidable = other as EntityCollidable;
Terrain otherTerrain = other as Terrain;
if (otherEntityCollidable != null &&
otherEntityCollidable.Entity != null &&
otherEntityCollidable.Entity.Tag != null)
{
int actorId = (int)(otherEntityCollidable.Entity.Tag);
if (actorId == mOwnerActorId)
return;
Actor actorHit = GameResources.ActorManager.GetActorById(actorId);
IDamagable damage = actorHit.GetBehaviorThatImplementsType<IDamagable>();
if (damage != null)
{
damage.TakeDamage(mDamage);
}
Impact();
}
else if (otherTerrain != null)
{
Impact();
}
}
示例3: Events_InitialCollisionDetected
void Events_InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
if ("Environment".Equals(other.Tag))
{
// do something on collision
}
}
示例4: InitialCollisionDetected
public void InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
{
if (other == acceptedTrigger)
{
//If the detector collided with the accepted trigger, move the box.
movedBox.Position = new Vector3(4, 5, 0);
movedBox.Orientation = Quaternion.Identity;
movedBox.LinearVelocity = Vector3.Zero;
movedBox.AngularVelocity = Vector3.Zero;
}
}
示例5: InitialCollisionDetectedHandler
private void InitialCollisionDetectedHandler(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
EntityCollidable otherEntityCollidable = other as EntityCollidable;
if (otherEntityCollidable != null &&
otherEntityCollidable.Entity != null &&
otherEntityCollidable.Entity.Tag != null &&
mTriggerSet &&
GameResources.ActorManager.IsPlayer((int)(otherEntityCollidable.Entity.Tag)))
{
mTriggerSet = false;
GameResources.LoadNewLevelDelegate(mLevelName);
}
}
示例6: Initialize
///<summary>
/// Initializes the manifold.
///</summary>
///<param name="newCollidableA">First collidable.</param>
///<param name="newCollidableB">Second collidable.</param>
public override void Initialize(Collidable newCollidableA, Collidable newCollidableB)
{
convex = newCollidableA as ConvexCollidable;
mesh = newCollidableB as MobileMeshCollidable;
if (convex == null || mesh == null)
{
convex = newCollidableB as ConvexCollidable;
mesh = newCollidableA as MobileMeshCollidable;
if (convex == null || mesh == null)
throw new ArgumentException("Inappropriate types used to initialize contact manifold.");
}
}
示例7: InitialCollisionDetectedHandler
private void InitialCollisionDetectedHandler(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
EntityCollidable otherEntityCollidable = other as EntityCollidable;
if (otherEntityCollidable != null &&
otherEntityCollidable.Entity != null &&
otherEntityCollidable.Entity.Tag != null &&
mTriggerSet &&
GameResources.ActorManager.IsPlayer((int)(otherEntityCollidable.Entity.Tag)))
{
PlayerView finder = GameResources.ActorManager.GetPlayerViewOfAvatar((int)(otherEntityCollidable.Entity.Tag));
finder.AvatarDesc.ObtainItem(Item);
mTriggerSet = false;
Owner.Despawn();
}
}
示例8: OnCollisionDetected
/// <summary>
/// Raises the appropriate ParentObject collision events depending on its CollisionType value
/// </summary>
/// <param name="sender">The current ISpaceObject instance</param>
/// <param name="other">The ISpaceObject instance which collided</param>
/// <param name="pair"/>
protected void OnCollisionDetected(Collidable sender, Collidable other, CollidablePairHandler pair)
{
if (sender.Tag == null || other.Tag == null)
return;
ICollisionObject senderCollisionObject = (ICollisionObject) sender.Tag;
ICollisionObject otherCollisionObject = (ICollisionObject) other.Tag;
switch (ParentObject.CollisionType)
{
case CollisionType.Trigger:
{
ParentObject.OnCollisionTrigger(senderCollisionObject, otherCollisionObject);
break;
}
case CollisionType.Collide:
{
var collisionPoint = new CollisionPoint
{
ContactObject = otherCollisionObject,
ContactPoint = pair.Contacts[0].Contact.Position,
ContactTime = pair.TimeOfImpact,
Material = null,
SurfaceNormal = pair.Contacts[0].Contact.Normal
};
ParentObject.OnCollisionReact(senderCollisionObject, otherCollisionObject, collisionPoint, ref _collisionHandled);
break;
}
default:
case CollisionType.None:
{
break;
}
}
}
示例9: UpdateTimeOfImpact
///<summary>
/// Updates the time of impact for the pair.
///</summary>
///<param name="requester">Collidable requesting the update.</param>
///<param name="dt">Timestep duration.</param>
public override void UpdateTimeOfImpact(Collidable requester, float dt)
{
//Notice that we don't test for convex entity null explicitly. The convex.IsActive property does that for us.
if (convex.IsActive && convex.entity.PositionUpdateMode == PositionUpdateMode.Continuous)
{
//TODO: This system could be made more robust by using a similar region-based rejection of edges.
//CCD events are awfully rare under normal circumstances, so this isn't usually an issue.
//Only perform the test if the minimum radii are small enough relative to the size of the velocity.
System.Numerics.Vector3 velocity;
Vector3Ex.Multiply(ref convex.entity.linearVelocity, dt, out velocity);
float velocitySquared = velocity.LengthSquared();
var minimumRadius = convex.Shape.MinimumRadius * MotionSettings.CoreShapeScaling;
timeOfImpact = 1;
if (minimumRadius * minimumRadius < velocitySquared)
{
var triangle = PhysicsThreadResources.GetTriangle();
triangle.collisionMargin = 0;
System.Numerics.Vector3 terrainUp = new System.Numerics.Vector3(terrain.worldTransform.LinearTransform.M21, terrain.worldTransform.LinearTransform.M22, terrain.worldTransform.LinearTransform.M23);
//Spherecast against all triangles to find the earliest time.
for (int i = 0; i < TerrainManifold.overlappedTriangles.Count; i++)
{
terrain.Shape.GetTriangle(TerrainManifold.overlappedTriangles.Elements[i], ref terrain.worldTransform, out triangle.vA, out triangle.vB, out triangle.vC);
//Put the triangle into 'localish' space of the convex.
Vector3Ex.Subtract(ref triangle.vA, ref convex.worldTransform.Position, out triangle.vA);
Vector3Ex.Subtract(ref triangle.vB, ref convex.worldTransform.Position, out triangle.vB);
Vector3Ex.Subtract(ref triangle.vC, ref convex.worldTransform.Position, out triangle.vC);
RayHit rayHit;
if (GJKToolbox.CCDSphereCast(new Ray(Toolbox.ZeroVector, velocity), minimumRadius, triangle, ref Toolbox.RigidIdentity, timeOfImpact, out rayHit) &&
rayHit.T > Toolbox.BigEpsilon)
{
System.Numerics.Vector3 AB, AC;
Vector3Ex.Subtract(ref triangle.vB, ref triangle.vA, out AB);
Vector3Ex.Subtract(ref triangle.vC, ref triangle.vA, out AC);
System.Numerics.Vector3 normal;
Vector3Ex.Cross(ref AC, ref AB, out normal);
float dot;
Vector3Ex.Dot(ref normal, ref terrainUp, out dot);
if (dot < 0)
Vector3Ex.Dot(ref normal, ref rayHit.Normal, out dot);
else
{
Vector3Ex.Dot(ref normal, ref rayHit.Normal, out dot);
dot = -dot;
}
//Only perform sweep if the object is in danger of hitting the object.
//Triangles can be one sided, so check the impact normal against the triangle normal.
if (dot < 0)
{
timeOfImpact = rayHit.T;
}
}
}
PhysicsThreadResources.GiveBack(triangle);
}
}
}
示例10: Initialize
///<summary>
/// Initializes the manifold.
///</summary>
///<param name="newCollidableA">First collidable.</param>
///<param name="newCollidableB">Second collidable.</param>
///<exception cref="Exception">Thrown when the collidables being used are not of the proper type.</exception>
public override void Initialize(Collidable newCollidableA, Collidable newCollidableB)
{
box = newCollidableA as ConvexCollidable<BoxShape>;
sphere = newCollidableB as ConvexCollidable<SphereShape>;
if (box == null || sphere == null)
{
box = newCollidableB as ConvexCollidable<BoxShape>;
sphere = newCollidableA as ConvexCollidable<SphereShape>;
if (box == null || sphere == null)
{
throw new ArgumentException("Inappropriate types used to initialize pair.");
}
}
}
示例11: Initialize
///<summary>
/// Initializes the manifold.
///</summary>
///<param name="newCollidableA">First collidable.</param>
///<param name="newCollidableB">Second collidable.</param>
public override void Initialize(Collidable newCollidableA, Collidable newCollidableB)
{
collidableA = newCollidableA as ConvexCollidable;
collidableB = newCollidableB as ConvexCollidable;
pairTester.Initialize(newCollidableA, newCollidableB);
if (collidableA == null || collidableB == null)
{
throw new Exception("Inappropriate types used to initialize pair tester.");
}
}
示例12: Remove
/// <summary>
/// Removes a collidable from the group.
/// </summary>
/// <param name="collidable">Collidable to remove.</param>
public void Remove(Collidable collidable)
{
CollidableTree.Remove(collidable);
}
示例13: Initialize
///<summary>
/// Initializes the manifold.
///</summary>
///<param name="newCollidableA">First collidable.</param>
///<param name="newCollidableB">Second collidable.</param>
public abstract void Initialize(Collidable newCollidableA, Collidable newCollidableB);
示例14: UpdateTimeOfImpact
///<summary>
/// Updates the time of impact for the pair.
///</summary>
///<param name="requester">Collidable requesting the update.</param>
///<param name="dt">Timestep duration.</param>
public override void UpdateTimeOfImpact(Collidable requester, float dt)
{
var collidableA = CollidableA as ConvexCollidable;
var collidableB = CollidableB as ConvexCollidable;
var modeA = collidableA.entity == null ? PositionUpdateMode.Discrete : collidableA.entity.PositionUpdateMode;
var modeB = collidableB.entity == null ? PositionUpdateMode.Discrete : collidableB.entity.PositionUpdateMode;
var overlap = BroadPhaseOverlap;
if (
(overlap.entryA.IsActive || overlap.entryB.IsActive) && //At least one has to be active.
(
(
modeA == PositionUpdateMode.Continuous && //If both are continuous, only do the process for A.
modeB == PositionUpdateMode.Continuous &&
overlap.entryA == requester
) ||
(
modeA == PositionUpdateMode.Continuous ^ //If only one is continuous, then we must do it.
modeB == PositionUpdateMode.Continuous
)
)
)
{
//Only perform the test if the minimum radii are small enough relative to the size of the velocity.
//Discrete objects have already had their linear motion integrated, so don't use their velocity.
Vector3 velocity;
if (modeA == PositionUpdateMode.Discrete)
{
//CollidableA is static for the purposes of this continuous test.
velocity = collidableB.entity.linearVelocity;
}
else if (modeB == PositionUpdateMode.Discrete)
{
//CollidableB is static for the purposes of this continuous test.
Vector3.Negate(ref collidableA.entity.linearVelocity, out velocity);
}
else
{
//Both objects are moving.
Vector3.Subtract(ref collidableB.entity.linearVelocity, ref collidableA.entity.linearVelocity, out velocity);
}
Vector3.Multiply(ref velocity, dt, out velocity);
float velocitySquared = velocity.LengthSquared();
var minimumRadiusA = collidableA.Shape.MinimumRadius * MotionSettings.CoreShapeScaling;
timeOfImpact = 1;
if (minimumRadiusA * minimumRadiusA < velocitySquared)
{
//Spherecast A against B.
RayHit rayHit;
if (GJKToolbox.CCDSphereCast(new Ray(collidableA.worldTransform.Position, -velocity), minimumRadiusA, collidableB.Shape, ref collidableB.worldTransform, timeOfImpact, out rayHit))
timeOfImpact = rayHit.T;
}
var minimumRadiusB = collidableB.Shape.MinimumRadius * MotionSettings.CoreShapeScaling;
if (minimumRadiusB * minimumRadiusB < velocitySquared)
{
//Spherecast B against A.
RayHit rayHit;
if (GJKToolbox.CCDSphereCast(new Ray(collidableB.worldTransform.Position, velocity), minimumRadiusB, collidableA.Shape, ref collidableA.worldTransform, timeOfImpact, out rayHit))
timeOfImpact = rayHit.T;
}
//If it's intersecting, throw our hands into the air and give up.
//This is generally a perfectly acceptable thing to do, since it's either sitting
//inside another object (no ccd makes sense) or we're still in an intersecting case
//from a previous frame where CCD took place and a contact should have been created
//to deal with interpenetrating velocity. Sometimes that contact isn't sufficient,
//but it's good enough.
if (timeOfImpact == 0)
timeOfImpact = 1;
}
}
示例15: FindSupport
/// <summary>
/// Finds a supporting entity, the contact location, and the contact normal.
/// </summary>
/// <param name="location">Contact point between the wheel and the support.</param>
/// <param name="normal">Contact normal between the wheel and the support.</param>
/// <param name="suspensionLength">Length of the suspension at the contact.</param>
/// <param name="supportingCollidable">Collidable supporting the wheel, if any.</param>
/// <param name="entity">Supporting object.</param>
/// <param name="material">Material of the wheel.</param>
/// <returns>Whether or not any support was found.</returns>
protected internal override bool FindSupport(out Vector3 location, out Vector3 normal, out float suspensionLength, out Collidable supportingCollidable, out Entity entity, out Material material)
{
suspensionLength = float.MaxValue;
location = Toolbox.NoVector;
supportingCollidable = null;
entity = null;
normal = Toolbox.NoVector;
material = null;
Collidable testCollidable;
RayHit rayHit;
bool hit = false;
for (int i = 0; i < detector.CollisionInformation.pairs.Count; i++)
{
var pair = detector.CollisionInformation.pairs[i];
testCollidable = (pair.BroadPhaseOverlap.entryA == detector.CollisionInformation ? pair.BroadPhaseOverlap.entryB : pair.BroadPhaseOverlap.entryA) as Collidable;
if (testCollidable != null)
{
if (CollisionRules.CollisionRuleCalculator(this, testCollidable) == CollisionRule.Normal &&
testCollidable.RayCast(new Ray(wheel.suspension.worldAttachmentPoint, wheel.suspension.worldDirection), wheel.suspension.restLength, out rayHit) &&
rayHit.T < suspensionLength)
{
suspensionLength = rayHit.T;
EntityCollidable entityCollidable;
if ((entityCollidable = testCollidable as EntityCollidable) != null)
{
entity = entityCollidable.Entity;
material = entityCollidable.Entity.Material;
}
else
{
entity = null;
supportingCollidable = testCollidable;
var materialOwner = testCollidable as IMaterialOwner;
if (materialOwner != null)
material = materialOwner.Material;
}
location = rayHit.Location;
normal = rayHit.Normal;
hit = true;
}
}
}
if (hit)
{
if (suspensionLength > 0)
normal.Normalize();
else
Vector3.Negate(ref wheel.suspension.worldDirection, out normal);
return true;
}
return false;
}