本文整理汇总了C#中BulletXNA.BulletCollision.CollisionObject类的典型用法代码示例。如果您正苦于以下问题:C# CollisionObject类的具体用法?C# CollisionObject怎么用?C# CollisionObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CollisionObject类属于BulletXNA.BulletCollision命名空间,在下文中一共展示了CollisionObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessCollision
public override void ProcessCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut)
{
//resultOut = new ManifoldResult();
if (m_manifoldPtr == null)
{
return;
}
CollisionObject sphereObj = m_swapped ? body1 : body0;
CollisionObject triObj = m_swapped ? body0 : body1;
SphereShape sphere = sphereObj.GetCollisionShape() as SphereShape;
TriangleShape triangle = triObj.GetCollisionShape() as TriangleShape;
/// report a contact. internally this will be kept persistent, and contact reduction is done
resultOut.SetPersistentManifold(m_manifoldPtr);
using (SphereTriangleDetector detector = BulletGlobals.SphereTriangleDetectorPool.Get())
{
detector.Initialize(sphere, triangle, m_manifoldPtr.GetContactBreakingThreshold());
ClosestPointInput input = ClosestPointInput.Default();
input.m_maximumDistanceSquared = float.MaxValue;
sphereObj.GetWorldTransform(out input.m_transformA);
triObj.GetWorldTransform(out input.m_transformB);
bool swapResults = m_swapped;
detector.GetClosestPoints(ref input, resultOut, dispatchInfo.getDebugDraw(), swapResults);
if (m_ownManifold)
{
resultOut.RefreshContactPoints();
}
}
}
示例2: Initialize
public virtual void Initialize(PersistentManifold mf, CollisionAlgorithmConstructionInfo ci, CollisionObject body0, CollisionObject body1, bool swapped)
{
base.Initialize(ci, body0, body1);
m_ownManifold = false;
m_manifoldPtr = mf;
m_swapped = swapped;
}
示例3: PreallocateChildAlgorithms
private void PreallocateChildAlgorithms(CollisionObject body0, CollisionObject body1)
{
CollisionObject colObj = m_isSwapped ? body1 : body0;
CollisionObject otherObj = m_isSwapped ? body0 : body1;
Debug.Assert(colObj.GetCollisionShape().IsCompound());
CompoundShape compoundShape = (CompoundShape)(colObj.GetCollisionShape());
int numChildren = compoundShape.GetNumChildShapes();
int i;
//m_childCollisionAlgorithms.resize(numChildren);
m_childCollisionAlgorithms.Clear();
for (i = 0; i < numChildren; i++)
{
if (compoundShape.GetDynamicAabbTree() != null)
{
m_childCollisionAlgorithms.Add(null);
}
else
{
CollisionShape tmpShape = colObj.GetCollisionShape();
CollisionShape childShape = compoundShape.GetChildShape(i);
colObj.InternalSetTemporaryCollisionShape(childShape);
CollisionAlgorithm ca = m_dispatcher.FindAlgorithm(colObj, otherObj, m_sharedManifold);
m_childCollisionAlgorithms.Add(ca);
colObj.InternalSetTemporaryCollisionShape(tmpShape);
}
}
}
示例4: SphereTriangleCollisionAlgorithm
public SphereTriangleCollisionAlgorithm() { } // for pool
public SphereTriangleCollisionAlgorithm(PersistentManifold mf, CollisionAlgorithmConstructionInfo ci, CollisionObject body0, CollisionObject body1, bool swapped)
: base(ci, body0, body1)
{
m_ownManifold = false;
m_manifoldPtr = mf;
m_swapped = swapped;
}
示例5: ProcessCollision
public override void ProcessCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut)
{
if (m_manifoldPtr == null)
{
//swapped?
m_manifoldPtr = m_dispatcher.GetNewManifold(body0, body1);
m_ownManifold = true;
}
resultOut.SetPersistentManifold(m_manifoldPtr);
//comment-out next line to test multi-contact generation
//resultOut.getPersistentManifold().clearManifold();
ConvexShape min0 = body0.GetCollisionShape() as ConvexShape;
ConvexShape min1 = body1.GetCollisionShape() as ConvexShape;
IndexedVector3 normalOnB = IndexedVector3.Zero;
IndexedVector3 pointOnBWorld = IndexedVector3.Zero;
{
ClosestPointInput input = ClosestPointInput.Default();
using (GjkPairDetector gjkPairDetector = BulletGlobals.GjkPairDetectorPool.Get())
{
gjkPairDetector.Initialize(min0, min1, m_simplexSolver, m_pdSolver);
//TODO: if (dispatchInfo.m_useContinuous)
gjkPairDetector.SetMinkowskiA(min0);
gjkPairDetector.SetMinkowskiB(min1);
{
input.m_maximumDistanceSquared = min0.GetMargin() + min1.GetMargin() + m_manifoldPtr.GetContactBreakingThreshold();
input.m_maximumDistanceSquared *= input.m_maximumDistanceSquared;
}
input.m_transformA = body0.GetWorldTransform();
input.m_transformB = body1.GetWorldTransform();
gjkPairDetector.GetClosestPoints(ref input, resultOut, dispatchInfo.getDebugDraw(), false);
#if DEBUG
if (BulletGlobals.g_streamWriter != null)
{
BulletGlobals.g_streamWriter.WriteLine("c2dc2d processCollision");
MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, "transformA", input.m_transformA);
MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, "transformB", input.m_transformB);
}
#endif
}
//BulletGlobals.GjkPairDetectorPool.Free(gjkPairDetector);
//btVector3 v0,v1;
//btVector3 sepNormalWorldSpace;
}
if (m_ownManifold)
{
resultOut.RefreshContactPoints();
}
}
示例6: GetNewManifold
public virtual PersistentManifold GetNewManifold(CollisionObject b0, CollisionObject b1)
{
gNumManifold++;
CollisionObject body0 = b0;
CollisionObject body1 = b1;
//optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance)
float contactBreakingThreshold = ((m_dispatcherFlags & DispatcherFlags.CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) > 0) ?
Math.Min(body0.GetCollisionShape().GetContactBreakingThreshold(BulletGlobals.gContactBreakingThreshold), body1.GetCollisionShape().GetContactBreakingThreshold(BulletGlobals.gContactBreakingThreshold))
: BulletGlobals.gContactBreakingThreshold;
float contactProcessingThreshold = Math.Min(body0.GetContactProcessingThreshold(), body1.GetContactProcessingThreshold());
// nothing in our pool so create a new one and return it.
// need a way to flush the pool ideally
PersistentManifold manifold = BulletGlobals.PersistentManifoldPool.Get();
manifold.Initialise(body0, body1, 0, contactBreakingThreshold, contactProcessingThreshold);
manifold.m_index1a = m_manifoldsPtr.Count;
m_manifoldsPtr.Add(manifold);
#if DEBUG
if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugDispatcher)
{
BulletGlobals.g_streamWriter.WriteLine("GetNewManifold[{0}][{1}]", manifold.m_index1a,m_manifoldsPtr.Count);
}
#endif
return manifold;
}
示例7: Initialise
public void Initialise(CollisionObject body0, CollisionObject body1)
{
m_body0 = body0;
m_body1 = body1;
m_rootTransA = body0.GetWorldTransform();
m_rootTransB = body1.GetWorldTransform();
m_manifoldPtr = null;
}
示例8: Box2dBox2dCollisionAlgorithm
public Box2dBox2dCollisionAlgorithm(PersistentManifold mf,CollisionAlgorithmConstructionInfo ci,CollisionObject body0,CollisionObject body1) :
base(ci,body0,body1)
{
m_ownManifold = false;
m_manifoldPtr = mf;
if (m_manifoldPtr == null && m_dispatcher.NeedsCollision(body0, body1))
{
m_manifoldPtr = m_dispatcher.GetNewManifold(body0, body1);
m_ownManifold = true;
}
}
示例9: Convex2dConvex2dAlgorithm
public Convex2dConvex2dAlgorithm(PersistentManifold mf, CollisionAlgorithmConstructionInfo ci, CollisionObject body0, CollisionObject body1, ISimplexSolverInterface simplexSolver, IConvexPenetrationDepthSolver pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold)
: base(ci, body0, body1)
{
m_simplexSolver = simplexSolver;
m_pdSolver = pdSolver;
m_ownManifold = false;
m_manifoldPtr = mf;
m_lowLevelOfDetail = false;
m_numPerturbationIterations = numPerturbationIterations;
m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
}
示例10: Initialize
public virtual void Initialize(CollisionAlgorithmConstructionInfo ci, CollisionObject body0, CollisionObject body1, bool isSwapped)
{
base.Initialize(ci, body0, body1);
m_isSwapped = isSwapped;
m_sharedManifold = ci.GetManifold();
m_ownsManifold = false;
CollisionObject colObj = m_isSwapped ? body1 : body0;
Debug.Assert(colObj.GetCollisionShape().IsCompound());
CompoundShape compoundShape = (CompoundShape)(colObj.GetCollisionShape());
m_compoundShapeRevision = compoundShape.GetUpdateRevision();
PreallocateChildAlgorithms(body0, body1);
}
示例11: UpdateSingleAabb
public void UpdateSingleAabb(CollisionObject colObj)
{
IndexedVector3 minAabb;
IndexedVector3 maxAabb;
IndexedMatrix wt = colObj.GetWorldTransform();
colObj.GetCollisionShape().GetAabb(ref wt, out minAabb, out maxAabb);
//need to increase the aabb for contact thresholds
IndexedVector3 contactThreshold = new IndexedVector3(BulletGlobals.gContactBreakingThreshold);
minAabb -= contactThreshold;
maxAabb += contactThreshold;
if (GetDispatchInfo().m_useContinuous && colObj.GetInternalType() == CollisionObjectTypes.CO_RIGID_BODY && !colObj.IsStaticOrKinematicObject())
{
IndexedVector3 minAabb2,maxAabb2;
colObj.GetCollisionShape().GetAabb(colObj.GetInterpolationWorldTransform(),out minAabb2 ,out maxAabb2);
minAabb2 -= contactThreshold;
maxAabb2 += contactThreshold;
MathUtil.VectorMin(ref minAabb2,ref minAabb);
MathUtil.VectorMax(ref maxAabb2, ref maxAabb);
}
#if DEBUG
if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugCollisionWorld)
{
MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "updateSingleAabbMin", minAabb);
MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "updateSingleAabbMax", maxAabb);
}
#endif
IBroadphaseInterface bp = m_broadphasePairCache as IBroadphaseInterface;
//moving objects should be moderately sized, probably something wrong if not
if (colObj.IsStaticObject() || ((maxAabb - minAabb).LengthSquared() < 1e12f))
{
bp.SetAabb(colObj.GetBroadphaseHandle(), ref minAabb, ref maxAabb, m_dispatcher1);
}
else
{
//something went wrong, investigate
//this assert is unwanted in 3D modelers (danger of loosing work)
colObj.SetActivationState(ActivationState.DISABLE_SIMULATION);
//static bool reportMe = true;
bool reportMe = true;
if (reportMe && m_debugDrawer != null)
{
reportMe = false;
m_debugDrawer.ReportErrorWarning("Overflow in AABB, object removed from simulation");
m_debugDrawer.ReportErrorWarning("If you can reproduce this, please email [email protected]\n");
m_debugDrawer.ReportErrorWarning("Please include above information, your Platform, version of OS.\n");
m_debugDrawer.ReportErrorWarning("Thanks.\n");
}
}
}
示例12: ProcessCollision
public override void ProcessCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut)
{
if (m_manifoldPtr == null)
{
return;
}
resultOut.SetPersistentManifold(m_manifoldPtr);
SphereShape sphere0 = body0.GetCollisionShape() as SphereShape;
SphereShape sphere1 = body1.GetCollisionShape() as SphereShape;
IndexedVector3 diff = body0.GetWorldTransform()._origin - body1.GetWorldTransform()._origin;
float len = diff.Length();
float radius0 = sphere0.GetRadius();
float radius1 = sphere1.GetRadius();
#if CLEAR_MANIFOLD
m_manifoldPtr.clearManifold(); //don't do this, it disables warmstarting
#endif
///iff distance positive, don't generate a new contact
if (len > (radius0 + radius1))
{
#if !CLEAR_MANIFOLD
resultOut.RefreshContactPoints();
#endif //CLEAR_MANIFOLD
return;
}
///distance (negative means penetration)
float dist = len - (radius0 + radius1);
IndexedVector3 normalOnSurfaceB = new IndexedVector3(1, 0, 0);
if (len > MathUtil.SIMD_EPSILON)
{
normalOnSurfaceB = diff / len;
}
///point on A (worldspace)
///btVector3 pos0 = col0->getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB;
///point on B (worldspace)
IndexedVector3 pos1 = body1.GetWorldTransform()._origin + radius1 * normalOnSurfaceB;
/// report a contact. internally this will be kept persistent, and contact reduction is done
resultOut.AddContactPoint(ref normalOnSurfaceB, ref pos1, dist);
#if !CLEAR_MANIFOLD
resultOut.RefreshContactPoints();
#endif //CLEAR_MANIFOLD
}
示例13: Initialize
public virtual void Initialize(PersistentManifold mf, CollisionAlgorithmConstructionInfo ci, CollisionObject colObj0, CollisionObject colObj1)
{
base.Initialize(ci, colObj0, colObj1);
m_ownManifold = false;
m_manifoldPtr = mf;
if (m_manifoldPtr == null)
{
m_manifoldPtr = m_dispatcher.GetNewManifold(colObj0, colObj1);
m_ownManifold = true;
}
}
示例14: SphereSphereCollisionAlgorithm
public SphereSphereCollisionAlgorithm() { } // for pool
public SphereSphereCollisionAlgorithm(PersistentManifold mf, CollisionAlgorithmConstructionInfo ci, CollisionObject body0, CollisionObject body1)
: base(ci, body0, body1)
{
m_ownManifold = false;
m_manifoldPtr = mf;
// for some reason theres no check in 2.76 or 2.78 for a needs collision, just a check on pointer being null.
if (m_manifoldPtr == null)
{
m_manifoldPtr = m_dispatcher.GetNewManifold(body0, body1);
m_ownManifold = true;
}
}
示例15: Inititialize
public void Inititialize(CollisionAlgorithmConstructionInfo ci, CollisionObject body0, CollisionObject body1, bool isSwapped)
{
base.Initialize(ci, body0, body1);
m_isSwapped = isSwapped;
if (m_convexTriangleCallback == null)
{
m_convexTriangleCallback = new ConvexTriangleCallback(m_dispatcher, body0, body1, isSwapped);
}
else
{
m_convexTriangleCallback.Initialize(m_dispatcher, body0, body1, isSwapped);
}
}