public void DrawCylinder(float topRadius, float bottomRadius, float halfHeight, int upAxis, ref IndexedMatrix matrix, ref IndexedMatrix view, ref IndexedMatrix projection, ref IndexedVector3 color) { IndexedVector3 scale = new IndexedVector3(topRadius, halfHeight, bottomRadius); IndexedMatrix rotate = IndexedMatrix.Identity; if (upAxis == 0) { rotate = IndexedMatrix.CreateRotationZ(MathUtil.SIMD_HALF_PI); } if (upAxis == 1) { rotate = IndexedMatrix.CreateRotationY(MathUtil.SIMD_HALF_PI); } else if (upAxis == 2) { rotate = IndexedMatrix.CreateRotationX(MathUtil.SIMD_HALF_PI); } IndexedMatrix copy = matrix; copy._origin = IndexedVector3.Zero; copy = copy * rotate; copy._origin = matrix._origin; ModelScalingData modelScalingData = new ModelScalingData(m_cylinderModel, scale, copy); modelScalingData.color = color; m_modelScalingData.Add(modelScalingData); }
public override void InitializeDemo() { SetCameraDistance(30f); //string filename = @"E:\users\man\bullet\xna-basic-output-1.txt"; //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read); //BulletGlobals.g_streamWriter = new StreamWriter(filestream); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new DefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //pairCache = new SortedOverlappingPairCache(); m_broadphase = new SimpleBroadphase(1000, pairCache); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver(); m_constraintSolver = sol; m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); ///create a few basic rigid bodies IndexedVector3 halfExtents = new IndexedVector3(50, 50, 50); //IndexedVector3 halfExtents = new IndexedVector3(10, 10, 10); CollisionShape groundShape = new BoxShape(ref halfExtents); //CollisionShape groundShape = new StaticPlaneShape(new IndexedVector3(0,1,0), 50); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, -50, 0)); //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0)); float mass = 0f; LocalCreateRigidBody(mass, ref groundTransform, groundShape); { int numBlocksTall = 10; //18; //How many 'stories' tall. float blockWidth = 6f; //Total width/length of the tower. float blockHeight = 2f; //create a few dynamic rigidbodies IndexedVector3 extents = new IndexedVector3(blockWidth / 3, blockHeight, blockWidth); IndexedVector3 boxHalfExtents = extents * 0.5f; CollisionShape colShape = new BoxShape(boxHalfExtents); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); //CollisionShape colShape = new CylinderShape(new IndexedVector3(1f, 1, 1f)); //m_collisionShapes.Add(colShape); /// Create Dynamic Objects IndexedMatrix startTransform = IndexedMatrix.Identity; mass = 1f; //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = mass != 0f; IndexedVector3 localInertia = IndexedVector3.Zero; if (isDynamic) { colShape.CalculateLocalInertia(mass, out localInertia); } //The default number of iterations is 10, which works fine, but this demo //is all about stability (it's jenga!). Increase the iterations a bit. //Even though it's using twice as many iterations, it will early-out //before reaching the limit MOST of the time. //It's still pretty playable at around 7-8 max iterations, though. IndexedMatrix transform = IndexedMatrix.Identity; for (int i = 0; i < numBlocksTall; i++) { if (i % 2 == 0) { for (int j = 0; j < 3; j++) { transform = IndexedMatrix.Identity; IndexedVector3 position = new IndexedVector3(j * (blockWidth / 3) - blockWidth / 3, blockHeight / 2 + i * (blockHeight), 0); //position += boxHalfExtents; transform._origin = position; RigidBody rb = LocalCreateRigidBody(mass, transform, colShape); rb.SetActivationState(ActivationState.ISLAND_SLEEPING); } } else { transform = IndexedMatrix.CreateRotationY(MathUtil.SIMD_HALF_PI); for (int j = 0; j < 3; j++) { IndexedVector3 position = new IndexedVector3(0, blockHeight / 2 + (i) * (blockHeight), j * (blockWidth / 3) - blockWidth / 3f); transform._origin = position; //position += boxHalfExtents; transform._origin = position; RigidBody rb = LocalCreateRigidBody(mass, transform, colShape); rb.SetActivationState(ActivationState.ISLAND_SLEEPING); } } } //game.Camera.Position = new Vector3(0, 5, 15); } ClientResetScene(); }