Пример #1
0
		void Setup()
		{
			world = new btDiscreteDynamicsWorld();
			world.setDebugDrawer( Program.Drawer );

			btVector3 tmp; btVector3.yAxis.Add( ref btVector3.xAxis, out tmp );
			tmp.normalized( out tmp );
			btCollisionShape groundShape;
			if( sloped )
				groundShape = new btStaticPlaneShape( ref btVector3.Zero, ref tmp );
			else
				groundShape = new btStaticPlaneShape( ref btVector3.Zero, ref btVector3.yAxis );

			btDefaultMotionState groundMotionState = new btDefaultMotionState();

			btRigidBody.btRigidBodyConstructionInfo
				groundRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( 0, groundMotionState
							, groundShape, ref btVector3.Zero );
			btRigidBody groundRigidBody = new btRigidBody( groundRigidBodyCI );
			world.addRigidBody( groundRigidBody );

			//-------------------------------------------------------

			btCollisionShape fallShape = new btSphereShape( btScalar.BT_ONE );

			btVector3 origin = new btVector3( 0, 50, 0 );
			btTransform init = new btTransform( ref btQuaternion.Identity, ref origin );
			btDefaultMotionState fallMotionState = new btDefaultMotionState( ref init );

			btScalar mass = 1;
			btVector3 fallInertia;
			fallShape.calculateLocalInertia( mass, out fallInertia );

			btRigidBody.btRigidBodyConstructionInfo
				fallingRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( mass, fallMotionState
							, fallShape, ref fallInertia );

			fallingRigidBody = new btRigidBody( fallingRigidBodyCI );

			world.addRigidBody( fallingRigidBody );

			//-------------------------------------------------------

			btCollisionShape fallShape2;
			if( !box )
				fallShape2 = new btSphereShape( btScalar.BT_ONE );
			else
				fallShape2 = new btBoxShape( ref btVector3.One );

			origin = new btVector3( sloped ? -34 : 0.25, 1, 0.25 );
			init = new btTransform( ref btQuaternion.Identity, ref origin );
			fallMotionState = new btDefaultMotionState( ref init );

			mass = 1;
			fallShape2.calculateLocalInertia( mass, out fallInertia );

			fallingRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( mass, fallMotionState
							, fallShape2, ref fallInertia );

			fallingRigidBody2 = new btRigidBody( fallingRigidBodyCI );

			world.addRigidBody( fallingRigidBody2 );
		}
Пример #2
0
		internal static void getClosestPoints( btBoxShape m_box1, btBoxShape m_box2
				, btDiscreteCollisionDetectorInterface.ClosestPointInput input
				, btDiscreteCollisionDetectorInterface.Result output
				, btIDebugDraw debugDraw, bool swapResults = false )
		{

			//btTransform transformA; input.m_transformA.Get( out transformA );
			//btTransform transformB; input.m_transformB.Get( out transformB );

			int skip = 0;
			//dContactGeom* contact = 0;

			double[] R1 = new double[12];
			double[] R2 = new double[12];
			//dMatrix3 R1;
			//dMatrix3 R2;

			for( int j = 0; j < 3; j++ )
			{
				R1[0 + 4 * j] = btMatrix3x3.getValue( ref input.m_transformA.m_basis, j,0 );
				R2[0 + 4 * j] = btMatrix3x3.getValue( ref input.m_transformB.m_basis, j, 0 );

				R1[1 + 4 * j] = btMatrix3x3.getValue( ref input.m_transformA.m_basis,j,1);
				R2[1 + 4 * j] = btMatrix3x3.getValue( ref input.m_transformB.m_basis,j,1 );

				R1[2 + 4 * j] = btMatrix3x3.getValue( ref input.m_transformA.m_basis,j,2 );
				R2[2 + 4 * j] = btMatrix3x3.getValue( ref input.m_transformB.m_basis,j,2 );
			}



			//btVector3 normal;
			//double depth;
			//int return_code;
			int maxc = 4;
			btVector3 half1, half2;

			m_box1.getHalfExtentsWithMargin( out half1 );
			half1.Mult( btScalar.BT_TWO, out half1 );
			m_box2.getHalfExtentsWithMargin( out half2 );
			half2.Mult( btScalar.BT_TWO, out half2 );

			dBoxBox2( ref input.m_transformA.m_origin,
					R1,
					ref half1,
					ref input.m_transformB.m_origin,
					R2,
					ref half2,
					//out normal, out depth, out return_code,
					maxc, skip,
					output
			);

		}
Пример #3
0
		void Setup()
		{
			world = new btDiscreteDynamicsWorld();
			world.setDebugDrawer( Program.Drawer );

			btVector3 tmp; btVector3.yAxis.Add( ref btVector3.xAxis, out tmp );
			tmp.normalized( out tmp );
			btCollisionShape groundShape;
			if( sloped )
				groundShape = new btStaticPlaneShape( ref btVector3.Zero, ref tmp );
			else
				groundShape = new btStaticPlaneShape( ref btVector3.Zero, ref btVector3.yAxis );

			btDefaultMotionState groundMotionState = new btDefaultMotionState();

			btRigidBody.btRigidBodyConstructionInfo
				groundRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( 0, groundMotionState
							, groundShape, ref btVector3.Zero );
			btRigidBody groundRigidBody = new btRigidBody( groundRigidBodyCI );
			world.addRigidBody( groundRigidBody );

			//-------------------------------------------------------

			btCollisionShape staticShape = new btBoxShape( ref btVector3.One );

			btVector3 origin = new btVector3( -3, 4, 0 );
			btTransform init = new btTransform( ref btQuaternion.Identity, ref origin );
			btDefaultMotionState fallMotionState = new btDefaultMotionState( ref init );

			btScalar mass = 0;
			btVector3 fallInertia;
			staticShape.calculateLocalInertia( mass, out fallInertia );

			btRigidBody.btRigidBodyConstructionInfo
				fallingRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( mass, fallMotionState
							, staticShape, ref fallInertia );

			staticRigidBody[0] = new btRigidBody( fallingRigidBodyCI );

			world.addRigidBody( staticRigidBody[0] );

			//-------------------------------------------------------

			btCollisionShape fallShape = new btBoxShape( ref btVector3.One );

			origin = new btVector3( -3, 10, 0 );
			init = new btTransform( ref btQuaternion.Identity, ref origin );
			fallMotionState = new btDefaultMotionState( ref init );

			mass = 1;
			fallShape.calculateLocalInertia( mass, out fallInertia );

			fallingRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( mass, fallMotionState
							, fallShape, ref fallInertia );

			fallingRigidBody = new btRigidBody( fallingRigidBodyCI );

			world.addRigidBody( fallingRigidBody );

			//-------------------------------------------------------

			btCollisionShape fallShape2 = new btBoxShape( ref btVector3.One );

			origin = new btVector3( 3, 10, 0 );
			init = new btTransform( ref btQuaternion.Identity, ref origin );
			fallMotionState = new btDefaultMotionState( ref init );

			mass = 1;
			fallShape2.calculateLocalInertia( mass, out fallInertia );

			fallingRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( mass, fallMotionState
							, fallShape2, ref fallInertia );

			fallingRigidBody2 = new btRigidBody( fallingRigidBodyCI );

			world.addRigidBody( fallingRigidBody2 );

			//---------------------------------------------------
			// Hinge them together
			btVector3 pivotInA; btVector3.xAxis.Mult( 3, out pivotInA );
			btVector3 axisInA = btVector3.yAxis;
			btVector3 pivotInB; btVector3.xAxis.Mult( -3, out pivotInB );
			btVector3 axisInB = btVector3.yAxis;

			btHingeConstraint constraint = new btHingeConstraint( fallingRigidBody, fallingRigidBody2
				, ref pivotInA, ref pivotInB, ref axisInA, ref axisInB );

			//constraint.enableMotor( true );
			//constraint.setMotorTargetVelocity( 1 );
			//constraint.setLimit( -btScalar.SIMD_2_PI, btScalar.SIMD_2_PI );

			constraint.enableAngularMotor( true, -1, -0.1 );

			world.addConstraint( constraint );
		}
Пример #4
0
		public void Setup()
		{
			world = new btDiscreteDynamicsWorld();
			world.setDebugDrawer( Program.Drawer );
			btVector3 tmp; btVector3.yAxis.Add( ref btVector3.xAxis, out tmp );
			tmp.normalized( out tmp );
			btCollisionShape groundShape;
			if( sloped )
				groundShape = new btStaticPlaneShape( ref btVector3.Zero, ref tmp );
			else
				groundShape = new btStaticPlaneShape( ref btVector3.Zero, ref btVector3.yAxis );

			btDefaultMotionState groundMotionState = new btDefaultMotionState();

			btRigidBody.btRigidBodyConstructionInfo
				groundRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( 0, groundMotionState
							, groundShape, ref btVector3.Zero );
			btRigidBody groundRigidBody = new btRigidBody( groundRigidBodyCI );
			world.addRigidBody( groundRigidBody );


			btCollisionShape fallShape = new btBoxShape( ref btVector3.One );
			if( large_count )
			{
				int n;
				int cubes = 5;
				for( n = 0; n < cubes * cubes * cubes; n++ )
				{
					btVector3 origin = new btVector3( ( n %cubes - cubes/2) * 3, 50 + ( n/(cubes*cubes))*3, (( n / cubes)%cubes - cubes/2 ) * 3 );
					btTransform init = new btTransform( ref btQuaternion.Identity, ref origin );
					btDefaultMotionState fallMotionState = new btDefaultMotionState( ref init );

					btScalar mass = 1;
					btVector3 fallInertia;
					fallShape.calculateLocalInertia( mass, out fallInertia );

					btRigidBody.btRigidBodyConstructionInfo
						fallingRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( mass, fallMotionState
									, fallShape, ref fallInertia );

					fallingRigidBody = new btRigidBody( fallingRigidBodyCI );

					world.addRigidBody( fallingRigidBody );
					if( n % (cubes* cubes ) == 0 )
						Console.Write( "." );
				}
			}
			else
			{
				btVector3 origin = new btVector3( 1, 50, 1 );
				btTransform init = new btTransform( ref btQuaternion.Identity, ref origin );
				btDefaultMotionState fallMotionState = new btDefaultMotionState( ref init );

				btScalar mass = 1;
				btVector3 fallInertia;
				fallShape.calculateLocalInertia( mass, out fallInertia );

				btRigidBody.btRigidBodyConstructionInfo
					fallingRigidBodyCI = new btRigidBody.btRigidBodyConstructionInfo( mass, fallMotionState
								, fallShape, ref fallInertia );

				fallingRigidBody = new btRigidBody( fallingRigidBodyCI );

				world.addRigidBody( fallingRigidBody );
			}
		}