コード例 #1
0
ファイル: Test_002.cs プロジェクト: d3x0r/Voxelarium
		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 );
		}
コード例 #2
0
ファイル: Test_005.cs プロジェクト: d3x0r/Voxelarium
		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 );
		}
コード例 #3
0
ファイル: Test_001.cs プロジェクト: d3x0r/Voxelarium
		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 );
			}
		}