本文整理汇总了C#中JigLibX.Collision.CollDetectInfo类 的典型用法代码示例。如果您正苦于以下问题:C# CollDetectInfo类的具体用法?C# CollDetectInfo怎么用?C# CollDetectInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CollDetectInfo类 属于JigLibX.Collision命名空间,在下文中一共展示了CollDetectInfo类 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CollDetect
public override void CollDetect(CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;
// todo - proper swept test
Capsule oldCapsule0 = (Capsule)info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0);
Capsule newCapsule0 = (Capsule)info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0);
Segment oldSeg0 = new Segment(oldCapsule0.Position, oldCapsule0.Length * oldCapsule0.Orientation.Backward);
Segment newSeg0 = new Segment(newCapsule0.Position, newCapsule0.Length * newCapsule0.Orientation.Backward);
Capsule oldCapsule1 = (Capsule)info.Skin1.GetPrimitiveOldWorld(info.IndexPrim1);
Capsule newCapsule1 = (Capsule)info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1);
Segment oldSeg1 = new Segment(oldCapsule1.Position, oldCapsule1.Length * oldCapsule1.Orientation.Backward);
Segment newSeg1 = new Segment(newCapsule1.Position, newCapsule1.Length * newCapsule1.Orientation.Backward);
float radSum = newCapsule0.Radius + newCapsule1.Radius;
float oldt0, oldt1;
float newt0, newt1;
float oldDistSq = Distance.SegmentSegmentDistanceSq(out oldt0, out oldt1, oldSeg0, oldSeg1);
float newDistSq = Distance.SegmentSegmentDistanceSq(out newt0, out newt1, newSeg0, newSeg1);
if (System.Math.Min(oldDistSq, newDistSq) < ((radSum + collTolerance) * (radSum + collTolerance)))
{
Vector3 pos0 = oldSeg0.GetPoint(oldt0);
Vector3 pos1 = oldSeg1.GetPoint(oldt1);
Vector3 delta = pos0 - pos1;
float dist = (float)System.Math.Sqrt((float)oldDistSq);
float depth = radSum - dist;
if (dist > JiggleMath.Epsilon)
{
delta /= dist;
}
else
{
// todo - make this not random
delta = Vector3.Transform(Vector3.Backward, Matrix.CreateFromAxisAngle(Vector3.Up, MathHelper.ToRadians(random.Next(360))));
}
Vector3 worldPos = pos1 +
(oldCapsule1.Radius - 0.5f * depth) * delta;
unsafe
{
SmallCollPointInfo collInfo = new SmallCollPointInfo(worldPos - body0Pos, worldPos - body1Pos, depth);
collisionFunctor.CollisionNotify(ref info, ref delta, &collInfo, 1);
}
}
}
开发者ID:bradleat, 项目名称:trafps, 代码行数:54, 代码来源:CapsuleCapsule.cs
示例2: CollDetect
/// <summary>
///
/// </summary>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
public override void CollDetect(CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
if (info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0).Type == this.Type1)
{
CollisionSkin skinSwap = info.Skin0;
info.Skin0 = info.Skin1;
info.Skin1 = skinSwap;
int primSwap = info.IndexPrim0;
info.IndexPrim0 = info.IndexPrim1;
info.IndexPrim1 = primSwap;
}
Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;
// todo - proper swept test
Sphere oldSphere = (Sphere)info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0);
Sphere newSphere = (Sphere)info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0);
JigLibX.Geometry.Plane oldPlane = (JigLibX.Geometry.Plane)info.Skin1.GetPrimitiveOldWorld(info.IndexPrim1);
JigLibX.Geometry.Plane newPlane = (JigLibX.Geometry.Plane)info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1);
Matrix newPlaneInvTransform = newPlane.InverseTransformMatrix;
Matrix oldPlaneInvTransform = oldPlane.InverseTransformMatrix;
Vector3 oldSpherePos = Vector3.Transform(oldSphere.Position, oldPlaneInvTransform);
Vector3 newSpherePos = Vector3.Transform(newSphere.Position, newPlaneInvTransform);
// consider it a contact if either old or new are touching
float oldDist = Distance.PointPlaneDistance(oldSpherePos, oldPlane);
float newDist = Distance.PointPlaneDistance(newSpherePos, newPlane);
if (System.Math.Min(newDist, oldDist) > collTolerance + newSphere.Radius)
return;
// collision - record depth using the old values
float oldDepth = oldSphere.Radius - oldDist;
// calc the world position based on the old position(s)
Vector3 worldPos = oldSphere.Position - oldSphere.Radius * oldPlane.Normal;
unsafe
{
SmallCollPointInfo collInfo = new SmallCollPointInfo(worldPos - body0Pos, worldPos - body1Pos, oldDepth);
collisionFunctor.CollisionNotify(ref info, ref oldPlane.normal, &collInfo, 1);
}
}
开发者ID:bradleat, 项目名称:trafps, 代码行数:53, 代码来源:SpherePlane.cs
示例3: CollDetect
/// <summary>
/// Detect BoxStaticMesh Collisions.
/// </summary>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
public override void CollDetect(CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
if (info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0).Type == Type1)
{
CollisionSkin skinSwap = info.Skin0;
info.Skin0 = info.Skin1;
info.Skin1 = skinSwap;
int primSwap = info.IndexPrim0;
info.IndexPrim0 = info.IndexPrim1;
info.IndexPrim1 = primSwap;
}
if (info.Skin0.CollisionSystem != null && info.Skin0.CollisionSystem.UseSweepTests)
CollDetectSweep(ref info, collTolerance, collisionFunctor);
else
CollDetectOverlap(ref info, collTolerance, collisionFunctor);
}
开发者ID:cody82, 项目名称:spacewar-arena, 代码行数:23, 代码来源:BoxStaticMesh.cs
示例4: CollDetect
/// <summary>
/// CollDetect
/// </summary>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
public override void CollDetect(CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;
// todo - proper swept test
Sphere oldSphere0 = (Sphere) info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0);
Sphere newSphere0 = (Sphere)info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0);
Sphere oldSphere1 = (Sphere)info.Skin1.GetPrimitiveOldWorld(info.IndexPrim1);
Sphere newSphere1 = (Sphere)info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1);
Vector3 oldDelta = oldSphere0.Position - oldSphere1.Position;
Vector3 newDelta = newSphere0.Position - oldSphere1.Position;
float oldDistSq = oldDelta.LengthSquared;
float newDistSq = newDelta.LengthSquared;
float radSum = newSphere0.Radius + newSphere1.Radius;
if (System.Math.Min(oldDistSq, newDistSq) < ((radSum + collTolerance) * (radSum + collTolerance)))
{
float oldDist = (float)System.Math.Sqrt((float)oldDistSq);
float depth = radSum - oldDist;
if (oldDist > JiggleMath.Epsilon)
{
oldDelta /= oldDist;
}
else
{
// TODO - make this not random...!
oldDelta = Vector3Extensions.TransformNormal(Vector3Extensions.Backward, Matrix4.CreateFromAxisAngle(Vector3Extensions.Up, OpenTKHelper.ToRadians(random.Next(360))));
}
Vector3 worldPos = oldSphere1.Position +
(oldSphere1.Radius - 0.5f * depth) * oldDelta;
unsafe
{
SmallCollPointInfo collInfo = new SmallCollPointInfo(worldPos - body0Pos, worldPos - body1Pos, depth);
collisionFunctor.CollisionNotify(ref info, ref oldDelta, &collInfo, 1);
}
}
}
开发者ID:cody82, 项目名称:spacewar-arena, 代码行数:51, 代码来源:SphereSphere.cs
示例5: CollDetect
/// <summary>
/// CollDetect
/// </summary>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
public override void CollDetect(CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
// get the skins in the order that we're expecting
if (info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0).Type == this.Type1)
{
CollisionSkin skinSwap = info.Skin0;
info.Skin0 = info.Skin1;
info.Skin1 = skinSwap;
int primSwap = info.IndexPrim0;
info.IndexPrim0 = info.IndexPrim1;
info.IndexPrim1 = primSwap;
}
if((info.Skin0.CollisionSystem != null) && info.Skin0.CollisionSystem.UseSweepTests)
CollDetectSweep(info, collTolerance, collisionFunctor);
else
CollDetectOverlap(info, collTolerance, collisionFunctor);
}
开发者ID:cody82, 项目名称:spacewar-arena, 代码行数:24, 代码来源:CapsuleStaticMesh.cs
示例6: CollDetect
/// <summary>
///
/// </summary>
/// <param name="infoOrig"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
public override void CollDetect(CollDetectInfo infoOrig, float collTolerance, CollisionFunctor collisionFunctor)
{
CollDetectInfo info = infoOrig;
if (info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0).Type == this.Type1)
{
CollisionSkin skinSwap = info.Skin0;
info.Skin0 = info.Skin1;
info.Skin1 = skinSwap;
int primSwap = info.IndexPrim0;
info.IndexPrim0 = info.IndexPrim1;
info.IndexPrim1 = primSwap;
}
Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;
// todo - proper swept test
Sphere oldSphere = (Sphere)info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0);
Sphere newSphere = (Sphere)info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0);
Heightmap oldHeightmap = (Heightmap)info.Skin1.GetPrimitiveOldWorld(info.IndexPrim1);
Heightmap newHeightmap = (Heightmap)info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1);
float newDist;
Vector3 normal;
newHeightmap.GetHeightAndNormal(out newDist, out normal,newSphere.Position);
if (newDist < collTolerance + newSphere.Radius)
{
float oldDist = oldHeightmap.GetHeight(oldSphere.Position);
float depth = oldSphere.Radius - oldDist;
// calc the world position when it just hit
Vector3 oldPt = oldSphere.Position - oldSphere.Radius * normal;
unsafe
{
SmallCollPointInfo ptInfo = new SmallCollPointInfo(oldPt - body0Pos, oldPt - body1Pos, depth);
collisionFunctor.CollisionNotify(ref info, ref normal, &ptInfo, 1);
}
}
}
开发者ID:bradleat, 项目名称:trafps, 代码行数:47, 代码来源:SphereHeightmap.cs
示例7: CollDetectSweep
/// <summary>
/// CollDetectSweep
/// </summary>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
private void CollDetectSweep(ref CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
// todo - proper swept test
// note - mesh is static and its triangles are in world space
TriangleMesh mesh = info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1) as TriangleMesh;
Box oldBox = info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0) as Box;
Box newBox = info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0) as Box;
Vector3 oldCentre;
oldBox.GetCentre(out oldCentre);
Vector3 newCentre;
newBox.GetCentre(out newCentre);
Vector3 delta;
Vector3.Subtract(ref newCentre, ref oldCentre, out delta);
float boxMinLen = 0.5f * System.Math.Min(newBox.SideLengths.X, System.Math.Min(newBox.SideLengths.Y, newBox.SideLengths.Z));
int nPositions = 1 + (int)(delta.Length / boxMinLen);
// limit the max positions...
if (nPositions > 50)
{
System.Diagnostics.Debug.WriteLine("Warning - clamping max positions in swept box test");
nPositions = 50;
}
if (nPositions == 1)
{
CollDetectBoxStaticMeshOverlap(oldBox, newBox, mesh,ref info, collTolerance, collisionFunctor);
}
else
{
BoundingBox bb = BoundingBoxHelper.InitialBox;
BoundingBoxHelper.AddBox(oldBox, ref bb);
BoundingBoxHelper.AddBox(newBox, ref bb);
unsafe
{
#if USE_STACKALLOC
int* potentialTriangles = stackalloc int[MaxLocalStackTris];
{
#else
int[] potTriArray = IntStackAlloc();
fixed( int* potentialTriangles = potTriArray)
{
#endif
int numTriangles = mesh.GetTrianglesIntersectingtAABox(potentialTriangles, MaxLocalStackTris, ref bb);
if (numTriangles > 0)
{
for (int i = 0; i <= nPositions; ++i)
{
float frac = ((float)i) / nPositions;
Vector3 centre;
Vector3.Multiply(ref delta, frac, out centre);
Vector3.Add(ref centre, ref oldCentre, out centre);
Matrix4 orient = Matrix4Extensions.Add(Matrix4Extensions.Multiply(oldBox.Orientation, 1.0f - frac), Matrix4Extensions.Multiply(newBox.Orientation, frac));
Box box = new Box(centre - 0.5f * Vector3Extensions.TransformNormal(newBox.SideLengths, orient), orient, newBox.SideLengths);
// ideally we'd break if we get one collision... but that stops us getting multiple collisions
// when we enter a corner (two walls meeting) - can let us pass through
CollDetectBoxStaticMeshOverlap(oldBox, box, mesh, ref info, collTolerance, collisionFunctor);
}
}
#if USE_STACKALLOC
}
#else
}
FreeStackAlloc(potTriArray);
#endif
}
}
}
开发者ID:cody82, 项目名称:spacewar-arena, 代码行数:77, 代码来源:BoxStaticMesh.cs
示例8: GetCollisionInfo
/// <summary>
/// CollisionInfos will be given out from a pool. If more than
/// MaxCollisionPoints are passed in, the input positions will
/// be silently truncated!
/// </summary>
/// <param name="info"></param>
/// <param name="dirToBody0"></param>
/// <param name="pointInfos"></param>
/// <param name="numPointInfos"></param>
/// <returns></returns>
public static unsafe CollisionInfo GetCollisionInfo(CollDetectInfo info,
Vector3 dirToBody0, SmallCollPointInfo* pointInfos, int numCollPts)
{
if (freeInfos.Count == 0)
freeInfos.Push(new CollisionInfo());
CollisionInfo collInfo = freeInfos.Pop();//[freeInfos.Count - 1];
collInfo.Init(info, dirToBody0, pointInfos, numCollPts);
//freeInfos.RemoveAt(freeInfos.Count - 1);
return collInfo;
}
开发者ID:bradleat, 项目名称:trafps, 代码行数:21, 代码来源:CollisionInfo.cs
示例9: CollDetect
/// <summary>
/// CollDetect
/// </summary>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
public override void CollDetect(CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
if (info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0).Type == this.Type1)
{
CollisionSkin skinSwap = info.Skin0;
info.Skin0 = info.Skin1;
info.Skin1 = skinSwap;
int primSwap = info.IndexPrim0;
info.IndexPrim0 = info.IndexPrim1;
info.IndexPrim1 = primSwap;
}
Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;
// todo - proper swept test
Capsule oldCapsule = (Capsule)info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0);
Capsule newCapsule = (Capsule)info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0);
JigLibX.Geometry.Plane oldPlane = (JigLibX.Geometry.Plane)info.Skin1.GetPrimitiveOldWorld(info.IndexPrim1);
JigLibX.Geometry.Plane newPlane = (JigLibX.Geometry.Plane)info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1);
Matrix newPlaneInvTransform = newPlane.InverseTransformMatrix;
Matrix oldPlaneInvTransform = oldPlane.InverseTransformMatrix;
unsafe
{
#if USE_STACKALLOC
SmallCollPointInfo* collPts = stackalloc SmallCollPointInfo[MaxLocalStackSCPI];
#else
SmallCollPointInfo[] collPtArray = SCPIStackAlloc();
fixed (SmallCollPointInfo* collPts = collPtArray)
#endif
{
int numCollPts = 0;
// the start
{
Vector3 oldCapsuleStartPos = Vector3.Transform(oldCapsule.Position, oldPlaneInvTransform);
Vector3 newCapsuleStartPos = Vector3.Transform(newCapsule.Position, newPlaneInvTransform);
float oldDist = Distance.PointPlaneDistance(oldCapsuleStartPos, oldPlane);
float newDist = Distance.PointPlaneDistance(newCapsuleStartPos, newPlane);
if (MathHelper.Min(newDist, oldDist) < collTolerance + newCapsule.Radius)
{
float oldDepth = oldCapsule.Radius - oldDist;
// calc the world position based on the old position8(s)
Vector3 worldPos = oldCapsule.Position - oldCapsule.Radius * oldPlane.Normal;
// BEN-OPTIMISATION: Now reuses existing collPts instead of reallocating.
collPts[numCollPts].R0 = worldPos - body0Pos;
collPts[numCollPts].R1 = worldPos - body1Pos;
collPts[numCollPts++].InitialPenetration = oldDepth;
}
}
// the end
{
Vector3 oldCapsuleEndPos = Vector3.Transform(oldCapsule.GetEnd(), oldPlaneInvTransform);
Vector3 newCapsuleEndPos = Vector3.Transform(newCapsule.GetEnd(), newPlaneInvTransform);
float oldDist = Distance.PointPlaneDistance(oldCapsuleEndPos, oldPlane);
float newDist = Distance.PointPlaneDistance(newCapsuleEndPos, newPlane);
if (System.Math.Min(newDist, oldDist) < collTolerance + newCapsule.Radius)
{
float oldDepth = oldCapsule.Radius - oldDist;
// calc the world position based on the old position(s)
Vector3 worldPos = oldCapsule.GetEnd() - oldCapsule.Radius * oldPlane.Normal;
// BEN-OPTIMISATION: Now reuses existing collPts instead of reallocating.
collPts[numCollPts].R0 = worldPos - body0Pos;
collPts[numCollPts].R1 = worldPos - body1Pos;
collPts[numCollPts++].InitialPenetration = oldDepth;
}
if (numCollPts > 0)
{
collisionFunctor.CollisionNotify(ref info, ref oldPlane.normal, collPts, numCollPts);
}
}
}
#if !USE_STACKALLOC
FreeStackAlloc(collPtArray);
#endif
}
}
开发者ID:colbybhearn, 项目名称:3DPhysics, 代码行数:93, 代码来源:CapsulePlane.cs
示例10: CollDetectSweep
private void CollDetectSweep(CollDetectInfo info, float collTolerance,
CollisionFunctor collisionFunctor)
{
// todo - proper swept test
Sphere oldSphere = info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0) as Sphere;
Sphere newSphere = info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0) as Sphere;
BoundingSphere oldBSphere = new BoundingSphere(oldSphere.Position, oldSphere.Radius);
BoundingSphere newBSphere = new BoundingSphere(newSphere.Position, newSphere.Radius);
// todo - proper swept test
// note - mesh is static and its triangles are in world space
TriangleMesh mesh = info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1) as TriangleMesh;
CollDetectSphereStaticMeshSweep(oldBSphere, newBSphere, mesh, info, collTolerance, collisionFunctor);
}
开发者ID:bradleat, 项目名称:trafps, 代码行数:15, 代码来源:SphereStaticMesh.cs
示例11: CollDetectSphereStaticMeshSweep
internal static void CollDetectSphereStaticMeshSweep(BoundingSphere oldSphere, BoundingSphere newSphere, TriangleMesh mesh,
CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
// really use a swept test - or overlap?
Vector3 delta = newSphere.Center - oldSphere.Center;
if (delta.LengthSquared() < (0.25f * newSphere.Radius * newSphere.Radius))
{
CollDetectSphereStaticMeshOverlap(oldSphere, newSphere, mesh, info, collTolerance, collisionFunctor);
}
else
{
Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;
float sphereTolR = collTolerance + oldSphere.Radius;
float sphereToR2 = sphereTolR * sphereTolR;
Vector3 collNormal = Vector3.Zero;
BoundingBox bb = BoundingBoxHelper.InitialBox;
BoundingBoxHelper.AddSphere(oldSphere, ref bb);
BoundingBoxHelper.AddSphere(newSphere, ref bb);
// get the spheres centers in triangle mesh space
Vector3 newSphereCen = Vector3.Transform(newSphere.Center, mesh.InverseTransformMatrix);
Vector3 oldSphereCen = Vector3.Transform(oldSphere.Center, mesh.InverseTransformMatrix);
unsafe
{
#if USE_STACKALLOC
SmallCollPointInfo* collPts = stackalloc SmallCollPointInfo[MaxLocalStackSCPI];
int* potentialTriangles = stackalloc int[MaxLocalStackTris];
{
{
#else
SmallCollPointInfo[] collPtArray = SCPIStackAlloc();
fixed (SmallCollPointInfo* collPts = collPtArray)
{
int[] potTriArray = IntStackAlloc();
fixed( int* potentialTriangles = potTriArray)
{
#endif
int numCollPts = 0;
int numTriangles = mesh.GetTrianglesIntersectingtAABox(potentialTriangles, MaxLocalStackTris, ref bb);
for (int iTriangle = 0; iTriangle < numTriangles; ++iTriangle)
{
// first test the old sphere for being on the wrong side
IndexedTriangle meshTriangle = mesh.GetTriangle(potentialTriangles[iTriangle]);
float distToCentreOld = meshTriangle.Plane.DotCoordinate(oldSphereCen);
if (distToCentreOld <= 0.0f)
continue;
// now test the new sphere for being clear
float distToCentreNew = meshTriangle.Plane.DotCoordinate(newSphereCen);
if (distToCentreNew > sphereTolR)
continue;
int i0, i1, i2;
meshTriangle.GetVertexIndices(out i0, out i1, out i2);
Triangle triangle = new Triangle(mesh.GetVertex(i0), mesh.GetVertex(i1), mesh.GetVertex(i2));
// If the old sphere is intersecting, just use that result
float s, t;
float d2 = Distance.PointTriangleDistanceSq(out s, out t, oldSphereCen, triangle);
if (d2 < sphereToR2)
{
float dist = (float)System.Math.Sqrt(d2);
float depth = oldSphere.Radius - dist;
Vector3 triangleN = triangle.Normal;
Vector3 normSafe = oldSphereCen - triangle.GetPoint(s, t);
JiggleMath.NormalizeSafe(ref normSafe);
Vector3 collisionN = (dist > float.Epsilon) ? normSafe : triangleN;
// since impulse gets applied at the old position
Vector3 pt = oldSphere.Center - oldSphere.Radius * collisionN;
if (numCollPts < MaxLocalStackSCPI)
{
collPts[numCollPts++] = new SmallCollPointInfo(pt - body0Pos, pt - body1Pos, depth);
}
collNormal += collisionN;
}
else if (distToCentreNew < distToCentreOld)
{
// old sphere is not intersecting - do a sweep, but only if the sphere is moving into the
// triangle
Vector3 pt, N; // CHECK THIS
float depth;
if (Intersection.SweptSphereTriangleIntersection(out pt, out N, out depth, oldSphere, newSphere, triangle,
distToCentreOld, distToCentreNew, Intersection.EdgesToTest.EdgeAll, Intersection.CornersToTest.CornerAll))
{
// collision point etc must be relative to the old position because that's
//where the impulses are applied
float dist = (float)System.Math.Sqrt(d2);
float depth2 = oldSphere.Radius - dist;
//.........这里部分代码省略.........
开发者ID:bradleat, 项目名称:trafps, 代码行数:101, 代码来源:SphereStaticMesh.cs
示例12: CollDetectCapsuleStaticMeshOverlap
/// <summary>
/// CollDetectCapsuleStaticMeshOverlap
/// </summary>
/// <param name="oldCapsule"></param>
/// <param name="newCapsule"></param>
/// <param name="mesh"></param>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
private void CollDetectCapsuleStaticMeshOverlap(Capsule oldCapsule, Capsule newCapsule,
TriangleMesh mesh, CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;
float capsuleTolR = collTolerance + newCapsule.Radius;
float capsuleTolR2 = capsuleTolR * capsuleTolR;
Vector3 collNormal = Vector3.Zero;
BoundingBox bb = BoundingBoxHelper.InitialBox;
BoundingBoxHelper.AddCapsule(newCapsule, ref bb);
unsafe
{
#if USE_STACKALLOC
SmallCollPointInfo* collPts = stackalloc SmallCollPointInfo[MaxLocalStackSCPI];
int* potentialTriangles = stackalloc int[MaxLocalStackTris];
{
{
#else
SmallCollPointInfo[] collPtArray = SCPIStackAlloc();
fixed (SmallCollPointInfo* collPts = collPtArray)
{
int[] potTriArray = IntStackAlloc();
fixed (int* potentialTriangles = potTriArray)
{
#endif
int numCollPts = 0;
int numTriangles = mesh.GetTrianglesIntersectingtAABox(potentialTriangles, MaxLocalStackTris, ref bb);
Vector3 capsuleStart = newCapsule.Position;
Vector3 capsuleEnd = newCapsule.GetEnd();
Matrix4 meshInvTransform = mesh.InverseTransformMatrix;
Vector3 meshSpaceCapsuleStart = Vector3.Transform(capsuleStart, meshInvTransform);
Vector3 meshSpaceCapsuleEnd = Vector3.Transform(capsuleEnd, meshInvTransform);
for (int iTriangle = 0; iTriangle < numTriangles; ++iTriangle)
{
IndexedTriangle meshTriangle = mesh.GetTriangle(potentialTriangles[iTriangle]);
// we do the plane test using the capsule in mesh space
float distToStart = meshTriangle.Plane.DotCoordinate(meshSpaceCapsuleStart);
float distToEnd = meshTriangle.Plane.DotCoordinate(meshSpaceCapsuleEnd);
// BEN-BUG-FIX: Fixed by replacing 0.0F with -capsuleTolR.
if ((distToStart > capsuleTolR && distToEnd > capsuleTolR)
|| (distToStart < -capsuleTolR && distToEnd < -capsuleTolR))
continue;
// we now transform the triangle into world space (we could keep leave the mesh alone
// but at this point 3 vector transforms is probably not a major slow down)
int i0, i1, i2;
meshTriangle.GetVertexIndices(out i0, out i1, out i2);
Vector3 triVec0;
Vector3 triVec1;
Vector3 triVec2;
mesh.GetVertex(i0, out triVec0);
mesh.GetVertex(i1, out triVec1);
mesh.GetVertex(i2, out triVec2);
// Deano move tri into world space
Matrix4 transformMatrix = mesh.TransformMatrix;
Vector3.Transform(ref triVec0, ref transformMatrix, out triVec0);
Vector3.Transform(ref triVec1, ref transformMatrix, out triVec1);
Vector3.Transform(ref triVec2, ref transformMatrix, out triVec2);
Triangle triangle = new Triangle(ref triVec0, ref triVec1, ref triVec2);
Segment seg = new Segment(capsuleStart, capsuleEnd - capsuleStart);
float tS, tT0, tT1;
float d2 = Distance.SegmentTriangleDistanceSq(out tS, out tT0, out tT1, seg, triangle);
if (d2 < capsuleTolR2)
{
Vector3 oldCapsuleStart = oldCapsule.Position;
Vector3 oldCapsuleEnd = oldCapsule.GetEnd();
Segment oldSeg = new Segment(oldCapsuleStart, oldCapsuleEnd - oldCapsuleStart);
d2 = Distance.SegmentTriangleDistanceSq(out tS, out tT0, out tT1, oldSeg, triangle);
// report result from old position
float dist = (float)System.Math.Sqrt(d2);
float depth = oldCapsule.Radius - dist;
Vector3 pt = triangle.GetPoint(tT0, tT1);
Vector3 collisionN = (d2 > JiggleMath.Epsilon) ? JiggleMath.NormalizeSafe(oldSeg.GetPoint(tS) - pt) :
meshTriangle.Plane.Normal;
if (numCollPts < MaxLocalStackSCPI)
{
//.........这里部分代码省略.........
开发者ID:cody82, 项目名称:spacewar-arena, 代码行数:101, 代码来源:CapsuleStaticMesh.cs
示例13: CollDetectSweep
/// <summary>
/// CollDetectSweep
/// </summary>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
private void CollDetectSweep(CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
Capsule oldCapsule = info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0) as Capsule;
Capsule newCapsule = info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0) as Capsule;
// todo - proper swept test
// note - mesh is static and its triangles are in world space
TriangleMesh mesh = info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1) as TriangleMesh;
CollDetectCapsulseStaticMeshSweep(oldCapsule, newCapsule, mesh, info, collTolerance, collisionFunctor);
}
开发者ID:cody82, 项目名称:spacewar-arena, 代码行数:17, 代码来源:CapsuleStaticMesh.cs
示例14: CollDetectCapsulseStaticMeshSweep
/// <summary>
/// CollDetectCapsulseStaticMeshSweep
/// </summary>
/// <param name="oldCapsule"></param>
/// <param name="newCapsule"></param>
/// <param name="mesh"></param>
/// <param name="info"></param>
/// <param name="collTolerance"></param>
/// <param name="collisionFunctor"></param>
private void CollDetectCapsulseStaticMeshSweep(Capsule oldCapsule, Capsule newCapsule,
TriangleMesh mesh, CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
{
// really use a swept test - or overlap?
Vector3 delta = newCapsule.Position - oldCapsule.Position;
if (delta.LengthSquared < (0.25f * newCapsule.Radius * newCapsule.Radius))
{
CollDetectCapsuleStaticMeshOverlap(oldCapsule, newCapsule, mesh, info, collTolerance, collisionFunctor);
}
else
{
float capsuleLen = oldCapsule.Length;
float capsuleRadius = oldCapsule.Radius;
int nSpheres = 2 + (int)(capsuleLen / (2.0f * oldCapsule.Radius));
for (int iSphere = 0; iSphere < nSpheres; ++iSphere)
{
float offset = ((float)iSphere) * capsuleLen / ((float)nSpheres - 1.0f);
BoundingSphere oldSphere = new BoundingSphere(oldCapsule.Position + oldCapsule.Orientation.Backward() * offset, capsuleRadius);
BoundingSphere newSphere = new BoundingSphere(newCapsule.Position + newCapsule.Orientation.Backward() * offset, capsuleRadius);
CollDetectSphereStaticMesh.CollDetectSphereStaticMeshSweep(oldSphere, newSphere, mesh, info, collTolerance, collisionFunctor);
}
}
}
开发者ID:cody82, 项目名称:spacewar-arena, 代码行数:33, 代码来源:CapsuleStaticMesh.cs
示例15: DetectAllCollisions
/// <summary>
/// DetectAllCollisions
/// </summary>
/// <param name="bodies"></param>
/// <param name="collisionFunctor"></param>
/// <param name="collisionPredicate"></param>
/// <param name="collTolerance"></param>
public override void DetectAllCollisions(List<Body> bodies, CollisionFunctor collisionFunctor, CollisionSkinPredicate2 collisionPredicate, float collTolerance)
{
int numSkins = skins.Count;
int numBodies = bodies.Count;
CollDetectInfo info = new CollDetectInfo();
for (int ibody = 0; ibody < numBodies; ++ibody)
{
Body body = bodies[ibody];
if(!body.IsActive)
continue;
info.Skin0 = body.CollisionSkin;
if (info.Skin0 == null)
continue;
for (int skin = 0; skin < numSkins; ++skin)
{
info.Skin1 = skins[skin];
if (info.Skin0 == info.Skin1)
continue;
// CHANGE
if (info.Skin1 == null)
continue;
bool skinSleeping = true;
if (info.Skin1.Owner != null && info.Skin1.Owner.IsActive)
skinSleeping = false;
if ((skinSleeping == false) && (info.Skin1.ID < info.Skin0.ID))
continue;
if((collisionPredicate != null) &&
collisionPredicate.ConsiderSkinPair(info.Skin0,info.Skin1) == false)
continue;
// basic bbox test
if(BoundingBoxHelper.OverlapTest(ref info.Skin0.WorldBoundingBox,
ref info.Skin1.WorldBoundingBox,collTolerance))
{
if (CheckCollidables(info.Skin0,info.Skin1))
{
int bodyPrimitives = info.Skin0.NumPrimitives;
int primitves = info.Skin1.NumPrimitives;
for(info.IndexPrim0 = 0; info.IndexPrim0 < bodyPrimitives; ++info.IndexPrim0)
{
for (info.IndexPrim1 = 0; info.IndexPrim1 < primitves; ++info.IndexPrim1)
{
DetectFunctor f = GetCollDetectFunctor(info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0).Type,
info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1).Type);
if (f != null)
f.CollDetect(info, collTolerance, collisionFunctor);
}
}
}
} // overlapt test
} // loop over skins
} // loop over bodies
}
开发者ID:tuannsofta, 项目名称:kinect4bag, 代码行数:70, 代码来源:CollisionSystemBrute.cs
示例16: CollisionNotify
public unsafe override void CollisionNotify(
ref CollDetectInfo collDetectInfo,
ref Vector3 dirToBody0,
SmallCollPointInfo* pointInfos,
int numCollPts)
{
CollisionFunctorEntity.CollisionNotify(ref CollDetectInfoEntity, ref dirToBody0, pointInfos, numCollPts);
}
开发者ID:willcraftia, 项目名称:WindowsGame, 代码行数:8, 代码来源:CollDetectCapsuleCubicHeightmap.cs
六六分期app的软件客服如何联系?不知道吗?加qq群【895510560】即可!标题:六六分期
阅读:18257| 2023-10-27
今天小编告诉大家如何处理win10系统火狐flash插件总是崩溃的问题,可能很多用户都不知
阅读:9673| 2022-11-06
今天小编告诉大家如何对win10系统删除桌面回收站图标进行设置,可能很多用户都不知道
阅读:8175| 2022-11-06
今天小编告诉大家如何对win10系统电脑设置节能降温的设置方法,想必大家都遇到过需要
阅读:8547| 2022-11-06
我们在使用xp系统的过程中,经常需要对xp系统无线网络安装向导设置进行设置,可能很多
阅读:8456| 2022-11-06
今天小编告诉大家如何处理win7系统玩cf老是与主机连接不稳定的问题,可能很多用户都不
阅读:9387| 2022-11-06
电脑对日常生活的重要性小编就不多说了,可是一旦碰到win7系统设置cf烟雾头的问题,很
阅读:8427| 2022-11-06
我们在日常使用电脑的时候,有的小伙伴们可能在打开应用的时候会遇见提示应用程序无法
阅读:7862| 2022-11-06
今天小编告诉大家如何对win7系统打开vcf文件进行设置,可能很多用户都不知道怎么对win
阅读:8411| 2022-11-06
今天小编告诉大家如何对win10系统s4开启USB调试模式进行设置,可能很多用户都不知道怎
阅读:7394| 2022-11-06
请发表评论