public void ProcessChildShape( btCollisionShape childShape, int index )
			{
				Debug.Assert( index >= 0 );
				btCompoundShape compoundShape = (btCompoundShape)( m_compoundColObjWrap.getCollisionShape() );
				Debug.Assert( index < compoundShape.getNumChildShapes() );


				//backup
				//btTransform orgTrans = m_compoundColObjWrap.getWorldTransform();

				//btTransform childTrans = compoundShape.getChildTransform( index );
				btTransform newChildWorldTrans; m_compoundColObjWrap.m_collisionObject.m_worldTransform.Apply( ref compoundShape.m_children.InternalArray[index].m_transform
								, out newChildWorldTrans );

				//perform an AABB check first
				btVector3 aabbMin0, aabbMax0, aabbMin1, aabbMax1;
				childShape.getAabb( ref newChildWorldTrans, out aabbMin0, out aabbMax0 );
				m_otherObjWrap.getCollisionShape().getAabb( ref m_otherObjWrap.m_collisionObject.m_worldTransform
					, out aabbMin1, out aabbMax1 );

				if( gCompoundChildShapePairCallback != null )
				{
					if( !gCompoundChildShapePairCallback( m_otherObjWrap.getCollisionShape(), childShape ) )
						return;
				}

				if( btAabbUtil.TestAabbAgainstAabb2( ref aabbMin0, ref aabbMax0, ref aabbMin1, ref aabbMax1 ) )
				{

					btCollisionObjectWrapper compoundWrap = BulletGlobals.CollisionObjectWrapperPool.Get();
					compoundWrap.Initialize( this.m_compoundColObjWrap, childShape, m_compoundColObjWrap.m_collisionObject, -1, index);


					//the contactpoint is still projected back using the original inverted worldtrans
					if( m_childCollisionAlgorithms[index] == null )
						m_childCollisionAlgorithms[index] = m_dispatcher.findAlgorithm( compoundWrap, m_otherObjWrap, m_sharedManifold );


					btCollisionObjectWrapper tmpWrap = null;

					///detect swapping case
					if( m_resultOut.getBody0Internal() == m_compoundColObjWrap.m_collisionObject )
					{
						tmpWrap = m_resultOut.m_body0Wrap;
						m_resultOut.m_body0Wrap = compoundWrap;
						m_resultOut.setShapeIdentifiersA( -1, index );
					}
					else
					{
						tmpWrap = m_resultOut.m_body1Wrap;
						m_resultOut.m_body1Wrap =( compoundWrap );
						m_resultOut.setShapeIdentifiersB( -1, index );
					}


					m_childCollisionAlgorithms[index].processCollision( compoundWrap, ref newChildWorldTrans
						, m_otherObjWrap
						, ref m_otherObjWrap.m_collisionObject.m_worldTransform
						, m_dispatchInfo, m_resultOut );

#if false
			if (m_dispatchInfo.m_debugDraw && (m_dispatchInfo.m_debugDraw.getDebugMode() & btIDebugDraw::DBG_DrawAabb))
			{
				btVector3 worldAabbMin,worldAabbMax;
				m_dispatchInfo.m_debugDraw.drawAabb(aabbMin0,aabbMax0,btVector3(1,1,1));
				m_dispatchInfo.m_debugDraw.drawAabb(aabbMin1,aabbMax1,btVector3(1,1,1));
			}
#endif

					if( m_resultOut.getBody0Internal() == m_compoundColObjWrap.m_collisionObject )
					{
						m_resultOut.m_body0Wrap = tmpWrap;
					}
					else
					{
						m_resultOut.m_body1Wrap =( tmpWrap );
					}

				}
			}
Beispiel #2
0
		public void addChildShape( ref btTransform localTransform, btCollisionShape shape )
		{
			m_updateRevision++;
			//m_childTransforms.Add(localTransform);
			//m_childShapes.Add(shape);
			btCompoundShapeChild child = new btCompoundShapeChild();
			child.m_node = null;
			child.m_transform = localTransform;
			child.m_childShape = shape;
			child.m_childShapeType = shape.getShapeType();
			child.m_childMargin = shape.getMargin();


			//extend the local aabbMin/aabbMax
			btVector3 localAabbMin, localAabbMax;
			shape.getAabb( ref localTransform, out localAabbMin, out localAabbMax );
			for( int i = 0; i < 3; i++ )
			{
				if( m_localAabbMin[i] > localAabbMin[i] )
				{
					m_localAabbMin[i] = localAabbMin[i];
				}
				if( m_localAabbMax[i] < localAabbMax[i] )
				{
					m_localAabbMax[i] = localAabbMax[i];
				}

			}
			if( m_dynamicAabbTree != null )
			{
				btDbvt.btDbvtVolume bounds = btDbvt.btDbvtVolume.FromMM( ref localAabbMin, ref localAabbMax );
				int index = m_children.Count;
				child.m_node = m_dynamicAabbTree.insert( ref bounds, index );
			}

			m_children.Add( child );

		}