Пример #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 btBoxShape( ref btVector3.One );

				btVector3 origin = new btVector3( -1, 10, 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 staticShape = new btBoxShape( ref btVector3.One );

				btVector3 origin = new btVector3( -1, 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] );
			}
			//-------------------------------------------------------

			{
				btCompoundShape fallShape2 = new btCompoundShape();

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

				btCollisionShape part = new btBoxShape( ref btVector3.One );
				{
					int x, y, z;
					for( x = -2; x <= 2; x++ )
						for( y = -2; y <= 2; y++ )
							for( z = -2; z <= 2; z++ )
							{
								tmp = btVector3.Zero;
								tmp.AddScale( ref btVector3.xAxis, x * 2, out tmp );
								tmp.AddScale( ref btVector3.yAxis, y * 2, out tmp );
								tmp.AddScale( ref btVector3.zAxis, z * 2, out tmp );
								init.setOrigin( ref tmp );
								fallShape2.addChildShape( ref init, part );
							}
				}

				double mass = 125;// .001;
				btVector3 fallInertia;
				fallShape2.calculateLocalInertia( mass, out fallInertia ); // fills fallInertia

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



				fallingRigidBody2 = new btRigidBody( fallingRigidBodyCI );

				world.addRigidBody( fallingRigidBody2 );
			}

			if( false )
			{
				//---------------------------------------------------
				// 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 );
			}
		}
Пример #2
0
			internal RayTester( btCollisionObject collisionObject,
					btCompoundShape compoundShape,
					ref btTransform colObjWorldTransform,
					ref btTransform rayFromTrans,
					ref btTransform rayToTrans,
					RayResultCallback resultCallback )
			{
				m_collisionObject = ( collisionObject );
				m_compoundShape = ( compoundShape );
				m_colObjWorldTransform = ( colObjWorldTransform );
				m_rayFromTrans = ( rayFromTrans );
				m_rayToTrans = ( rayToTrans );
				m_resultCallback = ( resultCallback );

			}