public void GImpactVsCompoundshape(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, CompoundShape shape1, bool swapped) { IndexedMatrix orgtrans1 = body1.GetWorldTransform(); if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsCompoundshape"); } int i = shape1.GetNumChildShapes(); while (i-- != 0) { CollisionShape colshape1 = shape1.GetChildShape(i); IndexedMatrix childtrans1 = orgtrans1 * shape1.GetChildTransform(i); body1.SetWorldTransform(ref childtrans1); //collide child shape GImpactVsShape(body0, body1, shape0, colshape1, swapped); //restore transforms body1.SetWorldTransform(ref orgtrans1); } }
public void GImpactVsConcave( CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, ConcaveShape shape1, bool swapped) { GImpactTriangleCallback tricallback = new GImpactTriangleCallback(); tricallback.algorithm = this; tricallback.body0 = body0; tricallback.body1 = body1; tricallback.gimpactshape0 = shape0; tricallback.swapped = swapped; tricallback.margin = shape1.GetMargin(); //getting the trimesh AABB IndexedMatrix gimpactInConcaveSpace; gimpactInConcaveSpace = body1.GetWorldTransform().Inverse() * body0.GetWorldTransform(); IndexedVector3 minAABB, maxAABB; shape0.GetAabb(gimpactInConcaveSpace, out minAABB, out maxAABB); shape1.ProcessAllTriangles(tricallback, ref minAABB, ref maxAABB); }
protected void GImpactVsShapeFindPairs( ref IndexedMatrix trans0, ref IndexedMatrix trans1, GImpactShapeInterface shape0, CollisionShape shape1, ObjectArray <int> collided_primitives) { AABB boxshape = new AABB(); if (shape0.HasBoxSet()) { IndexedMatrix trans1to0 = trans0.Inverse(); //trans1to0 *= trans1; trans1to0 = trans1to0 * trans1; //trans1to0 = MathUtil.BulletMatrixMultiply(trans1,trans1to0); shape1.GetAabb(ref trans1to0, out boxshape.m_min, out boxshape.m_max); #if DEBUG if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, "GImpactAglo::GImpactVsShapeFindPairs trans1to0", trans1to0); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "box min", boxshape.m_min); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "box max", boxshape.m_max); } #endif shape0.GetBoxSet().BoxQuery(ref boxshape, collided_primitives); } else { shape1.GetAabb(ref trans1, out boxshape.m_min, out boxshape.m_max); AABB boxshape0 = new AABB(); int i = shape0.GetNumChildShapes(); while (i-- != 0) { shape0.GetChildAabb(i, ref trans0, out boxshape0.m_min, out boxshape0.m_max); if (boxshape.HasCollision(ref boxshape0)) { collided_primitives.Add(i); } } } }
public void Initialize(GImpactShapeInterface gim_shape) { m_gim_shape = gim_shape; //select retriever if (m_gim_shape.NeedsRetrieveTriangles()) { m_current_retriever = m_tri_retriever; } else if (m_gim_shape.NeedsRetrieveTetrahedrons()) { m_current_retriever = m_tetra_retriever; } else { m_current_retriever = m_child_retriever; } m_current_retriever.m_parent = this; }
protected void GImpactVsGImpactFindPairs( ref IndexedMatrix trans0, ref IndexedMatrix trans1, GImpactShapeInterface shape0, GImpactShapeInterface shape1, PairSet pairset) { if (shape0.HasBoxSet() && shape1.HasBoxSet()) { GImpactQuantizedBvh.FindCollision(shape0.GetBoxSet(), ref trans0, shape1.GetBoxSet(), ref trans1, pairset); } else { AABB boxshape0 = new AABB(); AABB boxshape1 = new AABB(); int i = shape0.GetNumChildShapes(); while (i-- != 0) { shape0.GetChildAabb(i, ref trans0, out boxshape0.m_min, out boxshape0.m_max); int j = shape1.GetNumChildShapes(); while (j-- != 0) { shape1.GetChildAabb(i, ref trans1, out boxshape1.m_min, out boxshape1.m_max); if (boxshape1.HasCollision(ref boxshape0)) { pairset.PushPair(i, j); } } } } #if DEBUG if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsGImpactFindPairs [{0}]", pairset.Count); } #endif }
public void GImpactVsConcave( CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, ConcaveShape shape1, bool swapped) { GImpactTriangleCallback tricallback = new GImpactTriangleCallback(); tricallback.algorithm = this; tricallback.body0 = body0; tricallback.body1 = body1; tricallback.gimpactshape0 = shape0; tricallback.swapped = swapped; tricallback.margin = shape1.GetMargin(); //getting the trimesh AABB IndexedMatrix gimpactInConcaveSpace; gimpactInConcaveSpace = body1.GetWorldTransform().Inverse() * body0.GetWorldTransform(); IndexedVector3 minAABB, maxAABB; shape0.GetAabb(gimpactInConcaveSpace, out minAABB, out maxAABB); shape1.ProcessAllTriangles(tricallback, ref minAABB, ref maxAABB); }
public void GImpactVsCompoundshape(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, CompoundShape shape1, bool swapped) { IndexedMatrix orgtrans1 = body1.GetWorldTransform(); if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsCompoundshape"); } int i = shape1.GetNumChildShapes(); while (i-- != 0) { CollisionShape colshape1 = shape1.GetChildShape(i); IndexedMatrix childtrans1 = orgtrans1 * shape1.GetChildTransform(i); body1.SetWorldTransform(ref childtrans1); //collide child shape GImpactVsShape(body0, body1, shape0, colshape1, swapped); //restore transforms body1.SetWorldTransform(ref orgtrans1); } }
public void GImpactVsShape(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, CollisionShape shape1, bool swapped) { if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsShape"); } if (shape0.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE) { GImpactMeshShape meshshape0 = shape0 as GImpactMeshShape; // check this... //int& part = swapped ? m_part1 : m_part0; //part = meshshape0.GetMeshPartCount(); int part = meshshape0.GetMeshPartCount(); while (part-- != 0) { GImpactVsShape(body0, body1, meshshape0.GetMeshPart(part), shape1, swapped); } if (swapped) { m_part1 = part; } else { m_part0 = part; } return; } #if GIMPACT_VS_PLANE_COLLISION if(shape0.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE_PART && shape1.GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE) { GImpactMeshShapePart shapepart = shape0 as GImpactMeshShapePart; StaticPlaneShape planeshape = shape1 as StaticPlaneShape; GImpactTrimeshpartVsPlaneCollision(body0, body1, shapepart, planeshape, swapped); return; } #endif if (shape1.IsCompound()) { CompoundShape compoundshape = shape1 as CompoundShape; GImpactVsCompoundshape(body0, body1, shape0, compoundshape, swapped); return; } else if (shape1.IsConcave()) { ConcaveShape concaveshape = shape1 as ConcaveShape; GImpactVsConcave(body0, body1, shape0, concaveshape, swapped); return; } IndexedMatrix orgtrans0 = body0.GetWorldTransform(); IndexedMatrix orgtrans1 = body1.GetWorldTransform(); ObjectArray<int> collided_results = new ObjectArray<int>(64); GImpactVsShapeFindPairs(ref orgtrans0, ref orgtrans1, shape0, shape1, collided_results); if (collided_results.Count == 0) return; shape0.LockChildShapes(); using (GIM_ShapeRetriever retriever0 = BulletGlobals.GIM_ShapeRetrieverPool.Get()) { retriever0.Initialize(shape0); bool child_has_transform0 = shape0.ChildrenHasTransform(); int i = collided_results.Count; if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsShape [{0}]", collided_results.Count); } while (i-- != 0) { int child_index = collided_results[i]; if (swapped) m_triface1 = child_index; else m_triface0 = child_index; CollisionShape colshape0 = retriever0.GetChildShape(child_index); if (child_has_transform0) { body0.SetWorldTransform(orgtrans0 * shape0.GetChildTransform(child_index)); } //collide two shapes if (swapped) { ShapeVsShapeCollision(body1, body0, shape1, colshape0); } else { ShapeVsShapeCollision(body0, body1, colshape0, shape1); } //restore transforms if (child_has_transform0) { body0.SetWorldTransform(ref orgtrans0); } } shape0.UnlockChildShapes(); } }
//! Collides two gimpact shapes /*! \pre shape0 and shape1 couldn't be btGImpactMeshShape objects */ public void GImpactVsGImpact(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, GImpactShapeInterface shape1) { if (shape0.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE) { GImpactMeshShape meshshape0 = shape0 as GImpactMeshShape; m_part0 = meshshape0.GetMeshPartCount(); while (m_part0-- != 0) { GImpactVsGImpact(body0, body1, meshshape0.GetMeshPart(m_part0), shape1); } return; } if (shape1.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE) { GImpactMeshShape meshshape1 = shape1 as GImpactMeshShape; m_part1 = meshshape1.GetMeshPartCount(); while (m_part1-- != 0) { GImpactVsGImpact(body0, body1, shape0, meshshape1.GetMeshPart(m_part1)); } return; } IndexedMatrix orgtrans0 = body0.GetWorldTransform(); IndexedMatrix orgtrans1 = body1.GetWorldTransform(); PairSet pairset = new PairSet(); GImpactVsGImpactFindPairs(ref orgtrans0, ref orgtrans1, shape0, shape1, pairset); if (pairset.Count == 0) return; if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsGImpact [{0}]",pairset.Count); } if (shape0.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE_PART && shape1.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE_PART) { GImpactMeshShapePart shapepart0 = shape0 as GImpactMeshShapePart; GImpactMeshShapePart shapepart1 = shape1 as GImpactMeshShapePart; //specialized function #if BULLET_TRIANGLE_COLLISION CollideGjkTriangles(body0,body1,shapepart0,shapepart1,&pairset[0].m_index1,pairset.size()); #else CollideSatTriangles(body0, body1, shapepart0, shapepart1, pairset, pairset.Count); #endif return; } //general function shape0.LockChildShapes(); shape1.LockChildShapes(); using(GIM_ShapeRetriever retriever0 = BulletGlobals.GIM_ShapeRetrieverPool.Get()) using (GIM_ShapeRetriever retriever1 = BulletGlobals.GIM_ShapeRetrieverPool.Get()) { retriever0.Initialize(shape0); retriever1.Initialize(shape1); bool child_has_transform0 = shape0.ChildrenHasTransform(); bool child_has_transform1 = shape1.ChildrenHasTransform(); int i = pairset.Count; while (i-- != 0) { GIM_PAIR pair = pairset[i]; m_triface0 = pair.m_index1; m_triface1 = pair.m_index2; CollisionShape colshape0 = retriever0.GetChildShape(m_triface0); CollisionShape colshape1 = retriever1.GetChildShape(m_triface1); if (child_has_transform0) { body0.SetWorldTransform(orgtrans0 * shape0.GetChildTransform(m_triface0)); } if (child_has_transform1) { body1.SetWorldTransform(orgtrans1 * shape1.GetChildTransform(m_triface1)); } //collide two convex shapes ConvexVsConvexCollision(body0, body1, colshape0, colshape1); if (child_has_transform0) { body0.SetWorldTransform(ref orgtrans0); } if (child_has_transform1) { body1.SetWorldTransform(ref orgtrans1); } } shape0.UnlockChildShapes(); shape1.UnlockChildShapes(); } }
protected void GImpactVsShapeFindPairs( ref IndexedMatrix trans0, ref IndexedMatrix trans1, GImpactShapeInterface shape0, CollisionShape shape1, ObjectArray<int> collided_primitives) { AABB boxshape = new AABB(); if (shape0.HasBoxSet()) { IndexedMatrix trans1to0 = trans0.Inverse(); //trans1to0 *= trans1; trans1to0 = trans1to0 * trans1; //trans1to0 = MathUtil.BulletMatrixMultiply(trans1,trans1to0); shape1.GetAabb(ref trans1to0, out boxshape.m_min, out boxshape.m_max); if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, "GImpactAglo::GImpactVsShapeFindPairs trans1to0", trans1to0); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "box min", boxshape.m_min); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "box max", boxshape.m_max); } shape0.GetBoxSet().BoxQuery(ref boxshape, collided_primitives); } else { shape1.GetAabb(ref trans1, out boxshape.m_min, out boxshape.m_max); AABB boxshape0 = new AABB(); int i = shape0.GetNumChildShapes(); while (i-- != 0) { shape0.GetChildAabb(i, ref trans0, out boxshape0.m_min, out boxshape0.m_max); if (boxshape.HasCollision(ref boxshape0)) { collided_primitives.Add(i); } } } }
protected void GImpactVsGImpactFindPairs( ref IndexedMatrix trans0, ref IndexedMatrix trans1, GImpactShapeInterface shape0, GImpactShapeInterface shape1, PairSet pairset) { if (shape0.HasBoxSet() && shape1.HasBoxSet()) { GImpactQuantizedBvh.FindCollision(shape0.GetBoxSet(), ref trans0, shape1.GetBoxSet(), ref trans1, pairset); } else { AABB boxshape0 = new AABB(); AABB boxshape1 = new AABB(); int i = shape0.GetNumChildShapes(); while (i-- != 0) { shape0.GetChildAabb(i, ref trans0, out boxshape0.m_min, out boxshape0.m_max); int j = shape1.GetNumChildShapes(); while (j-- != 0) { shape1.GetChildAabb(i, ref trans1, out boxshape1.m_min, out boxshape1.m_max); if (boxshape1.HasCollision(ref boxshape0)) { pairset.PushPair(i, j); } } } } if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsGImpactFindPairs [{0}]", pairset.Count); } }
public void Initialize(GImpactShapeInterface gim_shape) { m_gim_shape = gim_shape; //select retriever if (m_gim_shape.NeedsRetrieveTriangles()) { m_current_retriever = m_tri_retriever; } else if (m_gim_shape.NeedsRetrieveTetrahedrons()) { m_current_retriever = m_tetra_retriever; } else { m_current_retriever = m_child_retriever; } m_current_retriever.m_parent = this; }
public void GImpactVsShape(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, CollisionShape shape1, bool swapped) { if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsShape"); } if (shape0.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE) { GImpactMeshShape meshshape0 = shape0 as GImpactMeshShape; // check this... //int& part = swapped ? m_part1 : m_part0; //part = meshshape0.GetMeshPartCount(); int part = meshshape0.GetMeshPartCount(); while (part-- != 0) { GImpactVsShape(body0, body1, meshshape0.GetMeshPart(part), shape1, swapped); } if (swapped) { m_part1 = part; } else { m_part0 = part; } return; } #if GIMPACT_VS_PLANE_COLLISION if (shape0.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE_PART && shape1.GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE) { GImpactMeshShapePart shapepart = shape0 as GImpactMeshShapePart; StaticPlaneShape planeshape = shape1 as StaticPlaneShape; GImpactTrimeshpartVsPlaneCollision(body0, body1, shapepart, planeshape, swapped); return; } #endif if (shape1.IsCompound()) { CompoundShape compoundshape = shape1 as CompoundShape; GImpactVsCompoundshape(body0, body1, shape0, compoundshape, swapped); return; } else if (shape1.IsConcave()) { ConcaveShape concaveshape = shape1 as ConcaveShape; GImpactVsConcave(body0, body1, shape0, concaveshape, swapped); return; } IndexedMatrix orgtrans0 = body0.GetWorldTransform(); IndexedMatrix orgtrans1 = body1.GetWorldTransform(); ObjectArray <int> collided_results = new ObjectArray <int>(64); GImpactVsShapeFindPairs(ref orgtrans0, ref orgtrans1, shape0, shape1, collided_results); if (collided_results.Count == 0) { return; } shape0.LockChildShapes(); using (GIM_ShapeRetriever retriever0 = BulletGlobals.GIM_ShapeRetrieverPool.Get()) { retriever0.Initialize(shape0); bool child_has_transform0 = shape0.ChildrenHasTransform(); int i = collided_results.Count; if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsShape [{0}]", collided_results.Count); } while (i-- != 0) { int child_index = collided_results[i]; if (swapped) { m_triface1 = child_index; } else { m_triface0 = child_index; } CollisionShape colshape0 = retriever0.GetChildShape(child_index); if (child_has_transform0) { body0.SetWorldTransform(orgtrans0 * shape0.GetChildTransform(child_index)); } //collide two shapes if (swapped) { ShapeVsShapeCollision(body1, body0, shape1, colshape0); } else { ShapeVsShapeCollision(body0, body1, colshape0, shape1); } //restore transforms if (child_has_transform0) { body0.SetWorldTransform(ref orgtrans0); } } shape0.UnlockChildShapes(); } }
//! Collides two gimpact shapes /*! * \pre shape0 and shape1 couldn't be btGImpactMeshShape objects */ public void GImpactVsGImpact(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, GImpactShapeInterface shape1) { if (shape0.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE) { GImpactMeshShape meshshape0 = shape0 as GImpactMeshShape; m_part0 = meshshape0.GetMeshPartCount(); while (m_part0-- != 0) { GImpactVsGImpact(body0, body1, meshshape0.GetMeshPart(m_part0), shape1); } return; } if (shape1.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE) { GImpactMeshShape meshshape1 = shape1 as GImpactMeshShape; m_part1 = meshshape1.GetMeshPartCount(); while (m_part1-- != 0) { GImpactVsGImpact(body0, body1, shape0, meshshape1.GetMeshPart(m_part1)); } return; } IndexedMatrix orgtrans0 = body0.GetWorldTransform(); IndexedMatrix orgtrans1 = body1.GetWorldTransform(); PairSet pairset = new PairSet(); GImpactVsGImpactFindPairs(ref orgtrans0, ref orgtrans1, shape0, shape1, pairset); if (pairset.Count == 0) { return; } if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsGImpact [{0}]", pairset.Count); } if (shape0.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE_PART && shape1.GetGImpactShapeType() == GIMPACT_SHAPE_TYPE.CONST_GIMPACT_TRIMESH_SHAPE_PART) { GImpactMeshShapePart shapepart0 = shape0 as GImpactMeshShapePart; GImpactMeshShapePart shapepart1 = shape1 as GImpactMeshShapePart; //specialized function #if BULLET_TRIANGLE_COLLISION CollideGjkTriangles(body0, body1, shapepart0, shapepart1, &pairset[0].m_index1, pairset.size()); #else CollideSatTriangles(body0, body1, shapepart0, shapepart1, pairset, pairset.Count); #endif return; } //general function shape0.LockChildShapes(); shape1.LockChildShapes(); using (GIM_ShapeRetriever retriever0 = BulletGlobals.GIM_ShapeRetrieverPool.Get()) using (GIM_ShapeRetriever retriever1 = BulletGlobals.GIM_ShapeRetrieverPool.Get()) { retriever0.Initialize(shape0); retriever1.Initialize(shape1); bool child_has_transform0 = shape0.ChildrenHasTransform(); bool child_has_transform1 = shape1.ChildrenHasTransform(); int i = pairset.Count; while (i-- != 0) { GIM_PAIR pair = pairset[i]; m_triface0 = pair.m_index1; m_triface1 = pair.m_index2; CollisionShape colshape0 = retriever0.GetChildShape(m_triface0); CollisionShape colshape1 = retriever1.GetChildShape(m_triface1); if (child_has_transform0) { body0.SetWorldTransform(orgtrans0 * shape0.GetChildTransform(m_triface0)); } if (child_has_transform1) { body1.SetWorldTransform(orgtrans1 * shape1.GetChildTransform(m_triface1)); } //collide two convex shapes ConvexVsConvexCollision(body0, body1, colshape0, colshape1); if (child_has_transform0) { body0.SetWorldTransform(ref orgtrans0); } if (child_has_transform1) { body1.SetWorldTransform(ref orgtrans1); } } shape0.UnlockChildShapes(); shape1.UnlockChildShapes(); } }