本文整理汇总了C#中BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable类的典型用法代码示例。如果您正苦于以下问题:C# EntityCollidable类的具体用法?C# EntityCollidable怎么用?C# EntityCollidable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntityCollidable类属于BEPUphysics.BroadPhaseEntries.MobileCollidables命名空间,在下文中一共展示了EntityCollidable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetShapeMeshData
public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
{
var shape = collidable.Shape as ConvexShape;
if (shape == null)
throw new ArgumentException("Wrong shape type for this helper.");
var vertexPositions = new BEPUutilities.Vector3[SampleDirections.Length];
for (int i = 0; i < SampleDirections.Length; ++i)
{
shape.GetLocalExtremePoint(SampleDirections[i], out vertexPositions[i]);
}
var hullIndices = new RawList<int>();
ConvexHullHelper.GetConvexHull(vertexPositions, hullIndices);
var hullTriangleVertices = new RawList<BEPUutilities.Vector3>();
foreach (int i in hullIndices)
{
hullTriangleVertices.Add(vertexPositions[i]);
}
for (ushort i = 0; i < hullTriangleVertices.Count; i += 3)
{
Vector3 normal = MathConverter.Convert(BEPUutilities.Vector3.Normalize(BEPUutilities.Vector3.Cross(hullTriangleVertices[i + 2] - hullTriangleVertices[i], hullTriangleVertices[i + 1] - hullTriangleVertices[i])));
vertices.Add(new VertexPositionNormalTexture(MathConverter.Convert(hullTriangleVertices[i]), normal, new Vector2(0, 0)));
vertices.Add(new VertexPositionNormalTexture(MathConverter.Convert(hullTriangleVertices[i + 1]), normal, new Vector2(1, 0)));
vertices.Add(new VertexPositionNormalTexture(MathConverter.Convert(hullTriangleVertices[i + 2]), normal, new Vector2(0, 1)));
indices.Add(i);
indices.Add((ushort)(i + 1));
indices.Add((ushort)(i + 2));
}
}
示例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: GetShapeMeshData
public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
{
var convexHullShape = collidable.Shape as ConvexHullShape;
if (convexHullShape == null)
throw new ArgumentException("Wrong shape type.");
var hullTriangleVertices = new List<BEPUutilities.Vector3>();
var hullTriangleIndices = new List<int>();
ConvexHullHelper.GetConvexHull(convexHullShape.Vertices, hullTriangleIndices, hullTriangleVertices);
//The hull triangle vertices are used as a dummy to get the unnecessary hull vertices, which are cleared afterwards.
hullTriangleVertices.Clear();
foreach (int i in hullTriangleIndices)
{
hullTriangleVertices.Add(convexHullShape.Vertices[i]);
}
var toReturn = new VertexPositionNormalTexture[hullTriangleVertices.Count];
Vector3 normal;
for (ushort i = 0; i < hullTriangleVertices.Count; i += 3)
{
normal = MathConverter.Convert(BEPUutilities.Vector3.Normalize(BEPUutilities.Vector3.Cross(hullTriangleVertices[i + 2] - hullTriangleVertices[i], hullTriangleVertices[i + 1] - hullTriangleVertices[i])));
vertices.Add(new VertexPositionNormalTexture(MathConverter.Convert(hullTriangleVertices[i]), normal, new Vector2(0, 0)));
vertices.Add(new VertexPositionNormalTexture(MathConverter.Convert(hullTriangleVertices[i + 1]), normal, new Vector2(1, 0)));
vertices.Add(new VertexPositionNormalTexture(MathConverter.Convert(hullTriangleVertices[i + 2]), normal, new Vector2(0, 1)));
indices.Add(i);
indices.Add((ushort)(i + 1));
indices.Add((ushort)(i + 2));
}
}
示例4: CompoundChild
internal CompoundChild(CompoundShape shape, EntityCollidable collisionInformation, Material material, int index)
{
this.shape = shape;
this.collisionInformation = collisionInformation;
Material = material;
this.shapeIndex = index;
}
示例5: Events_InitialCollisionDetected
void Events_InitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
if ("Environment".Equals(other.Tag))
{
// do something on collision
}
}
示例6: GetShapeMeshData
public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
{
var compoundCollidable = collidable as CompoundCollidable;
if (compoundCollidable == null)
throw new ArgumentException("Wrong shape type.");
var tempIndices = new List<ushort>();
var tempVertices = new List<VertexPositionNormalTexture>();
for (int i = 0; i < compoundCollidable.Children.Count; i++)
{
var child = compoundCollidable.Children[i];
ModelDrawer.ShapeMeshGetter shapeMeshGetter;
if (ModelDrawer.ShapeMeshGetters.TryGetValue(child.CollisionInformation.GetType(), out shapeMeshGetter))
{
shapeMeshGetter(child.CollisionInformation, tempVertices, tempIndices);
for (int j = 0; j < tempIndices.Count; j++)
{
indices.Add((ushort)(tempIndices[j] + vertices.Count));
}
RigidTransform localTransform = child.Entry.LocalTransform;
Vector3 localPosition = child.CollisionInformation.LocalPosition;
for (int j = 0; j < tempVertices.Count; j++)
{
VertexPositionNormalTexture vertex = tempVertices[j];
Vector3.Add(ref vertex.Position, ref localPosition, out vertex.Position);
RigidTransform.Transform(ref vertex.Position, ref localTransform, out vertex.Position);
Vector3.Transform(ref vertex.Normal, ref localTransform.Orientation, out vertex.Normal);
vertices.Add(vertex);
}
tempVertices.Clear();
tempIndices.Clear();
}
}
}
示例7: GetShapeMeshData
public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
{
var minkowskiShape = collidable.Shape as MinkowskiSumShape;
if (minkowskiShape == null)
throw new ArgumentException("Wrong shape type.");
var points = new List<Vector3>();
Vector3 max;
var direction = new Vector3();
float angleChange = MathHelper.TwoPi / NumSamples;
for (int i = 1; i < NumSamples / 2 - 1; i++)
{
float phi = MathHelper.PiOver2 - i * angleChange;
var sinPhi = (float)Math.Sin(phi);
var cosPhi = (float)Math.Cos(phi);
for (int j = 0; j < NumSamples; j++)
{
float theta = j * angleChange;
direction.X = (float)Math.Cos(theta) * cosPhi;
direction.Y = sinPhi;
direction.Z = (float)Math.Sin(theta) * cosPhi;
minkowskiShape.GetLocalExtremePoint(direction, out max);
points.Add(max);
}
}
minkowskiShape.GetLocalExtremePoint(Toolbox.UpVector, out max);
points.Add(max);
minkowskiShape.GetLocalExtremePoint(Toolbox.DownVector, out max);
points.Add(max);
var hullTriangleVertices = new List<Vector3>();
var hullTriangleIndices = new List<int>();
ConvexHullHelper.GetConvexHull(points, hullTriangleIndices, hullTriangleVertices);
//The hull triangle vertices are used as a dummy to get the unnecessary hull vertices, which are cleared afterwards.
hullTriangleVertices.Clear();
foreach (int i in hullTriangleIndices)
{
hullTriangleVertices.Add(points[i]);
}
Vector3 normal;
for (ushort i = 0; i < hullTriangleVertices.Count; i += 3)
{
normal = Vector3.Normalize(Vector3.Cross(hullTriangleVertices[i + 2] - hullTriangleVertices[i], hullTriangleVertices[i + 1] - hullTriangleVertices[i]));
vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i], normal, new Vector2(0, 0)));
vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i + 1], normal, new Vector2(1, 0)));
vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i + 2], normal, new Vector2(0, 1)));
indices.Add(i);
indices.Add((ushort)(i + 1));
indices.Add((ushort)(i + 2));
}
}
示例8: 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;
}
}
示例9: 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);
}
}
示例10: GetShapeMeshData
public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
{
ConeShape coneShape = collidable.Shape as ConeShape;
if (coneShape == null)
throw new ArgumentException("Wrong shape type.");
float verticalOffset = -coneShape.Height / 4;
float angleBetweenFacets = MathHelper.TwoPi / NumSides;
float radius = coneShape.Radius;
//Create the vertex list
var topVertexPosition = new Vector3(0, coneShape.Height + verticalOffset, 0);
for (int i = 0; i < NumSides; i++)
{
float theta = i * angleBetweenFacets;
var position = new Vector3((float)Math.Cos(theta) * radius, verticalOffset, (float)Math.Sin(theta) * radius);
Vector3 offset = topVertexPosition - position;
Vector3 normal = Vector3.Normalize(Vector3.Cross(Vector3.Cross(offset, Vector3.Up), offset));
//Top vertex
vertices.Add(new VertexPositionNormalTexture(topVertexPosition, normal, Vector2.Zero));
//Sloped vertices
vertices.Add(new VertexPositionNormalTexture(position, normal, Vector2.Zero));
//Bottom vertices
vertices.Add(new VertexPositionNormalTexture(position, Vector3.Down, Vector2.Zero));
}
//Create the index list
for (ushort i = 0; i < vertices.Count; i += 3)
{
//Each iteration, the loop advances to the next vertex 'column.'
//Four triangles per column (except for the four degenerate cap triangles).
//Sloped Triangles
indices.Add(i);
indices.Add((ushort)(i + 1));
indices.Add((ushort)((i + 4) % vertices.Count));
//Bottom cap triangles.
var nextIndex = (ushort)((i + 5) % vertices.Count);
if (nextIndex != 2) //Don't add cap indices if it's going to be a degenerate triangle.
{
indices.Add((ushort)(i + 2));
indices.Add(2);
indices.Add(nextIndex);
}
}
}
示例11: 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();
}
}
示例12: TryToAdd
protected void TryToAdd(EntityCollidable collidable)
{
CollisionRule rule;
if ((rule = CollisionRules.collisionRuleCalculator(DetectorVolume, collidable)) < CollisionRule.NoNarrowPhasePair)
{
//Clamp the rule to the parent's rule. Always use the more restrictive option.
//Don't have to test for NoNarrowPhasePair rule on the parent's rule because then the parent wouldn't exist!
if (rule < CollisionRule)
rule = CollisionRule;
if (!subPairs.ContainsKey(collidable))
{
var newPair = NarrowPhaseHelper.GetPairHandler(DetectorVolume, collidable, rule) as DetectorVolumePairHandler;
if (newPair != null)
{
newPair.Parent = this;
subPairs.Add(collidable, newPair);
}
}
containedPairs.Add(collidable);
}
}
示例13: GetShapeMeshData
public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
{
var triangleShape = collidable.Shape as TriangleShape;
if(triangleShape == null)
throw new ArgumentException("Wrong shape type.");
Vector3 normal = triangleShape.GetLocalNormal();
vertices.Add(new VertexPositionNormalTexture(triangleShape.VertexA, -normal, new Vector2(0, 0)));
vertices.Add(new VertexPositionNormalTexture(triangleShape.VertexB, -normal, new Vector2(0, 1)));
vertices.Add(new VertexPositionNormalTexture(triangleShape.VertexC, -normal, new Vector2(1, 0)));
vertices.Add(new VertexPositionNormalTexture(triangleShape.VertexA, normal, new Vector2(0, 0)));
vertices.Add(new VertexPositionNormalTexture(triangleShape.VertexB, normal, new Vector2(0, 1)));
vertices.Add(new VertexPositionNormalTexture(triangleShape.VertexC, normal, new Vector2(1, 0)));
indices.Add(0);
indices.Add(1);
indices.Add(2);
indices.Add(3);
indices.Add(5);
indices.Add(4);
}
示例14: GetShapeMeshData
public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
{
MobileMeshShape shape = collidable.Shape as MobileMeshShape;
var tempVertices = new VertexPositionNormalTexture[shape.TriangleMesh.Data.Vertices.Length];
for (int i = 0; i < shape.TriangleMesh.Data.Vertices.Length; i++)
{
BEPUutilities.Vector3 position;
shape.TriangleMesh.Data.GetVertexPosition(i, out position);
tempVertices[i] = new VertexPositionNormalTexture(
MathConverter.Convert(position),
Vector3.Zero,
Vector2.Zero);
}
for (int i = 0; i < shape.TriangleMesh.Data.Indices.Length; i++)
{
indices.Add((ushort)shape.TriangleMesh.Data.Indices[i]);
}
for (int i = 0; i < indices.Count; i += 3)
{
int a = indices[i];
int b = indices[i + 1];
int c = indices[i + 2];
Vector3 normal = Vector3.Normalize(Vector3.Cross(
tempVertices[c].Position - tempVertices[a].Position,
tempVertices[b].Position - tempVertices[a].Position));
tempVertices[a].Normal += normal;
tempVertices[b].Normal += normal;
tempVertices[c].Normal += normal;
}
for (int i = 0; i < tempVertices.Length; i++)
{
tempVertices[i].Normal.Normalize();
vertices.Add(tempVertices[i]);
}
}
示例15: PrepareQueryObject
private void PrepareQueryObject(EntityCollidable queryObject, ref Vector3 position)
{
RigidTransform transform;
transform.Position = position;
transform.Orientation = characterBody.Orientation;
queryObject.UpdateBoundingBoxForTransform(ref transform, 0);
}