public Physics(SceneManager sceneMgr) { // collision configuration contains default setup for memory, collision setup collisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(collisionConf); Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, collisionConf); World.Gravity = new Vector3(0, -10, 0); // create the ground CollisionShape groundShape = new BoxShape(50, 1, 50); CollisionShapes.Add(groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix4.IDENTITY, groundShape); ground.UserObject = "Ground"; // create a few dynamic rigidbodies float mass = 1.0f; CollisionShape colShape = new BoxShape(1); CollisionShapes.Add(colShape); Vector3 localInertia = colShape.CalculateLocalInertia(mass); var rbInfo = new RigidBodyConstructionInfo(mass, null, colShape, localInertia); float start_x = StartPosX - ArraySizeX / 2; float start_y = StartPosY; float start_z = StartPosZ - ArraySizeZ / 2; int k, i, j; for (k = 0; k < ArraySizeY; k++) { for (i = 0; i < ArraySizeX; i++) { for (j = 0; j < ArraySizeZ; j++) { Matrix4 startTransform = new Matrix4(); startTransform.MakeTrans( new Vector3( 2*i + start_x, 2*k + start_y, 2*j + start_z ) ); // using motionstate is recommended, it provides interpolation capabilities // and only synchronizes 'active' objects int index = (k * ArraySizeX + i) * ArraySizeZ + j; Entity box = sceneMgr.CreateEntity("Box" + index.ToString(), "box.mesh"); box.SetMaterialName("BoxMaterial/Active"); SceneNode boxNode = sceneMgr.RootSceneNode.CreateChildSceneNode("BoxNode" + index.ToString()); boxNode.AttachObject(box); boxNode.Scale(new Vector3(2, 2, 2)); var mogreMotionState = new MogreMotionState(box, boxNode, startTransform); rbInfo.MotionState = mogreMotionState; RigidBody body = new RigidBody(rbInfo); mogreMotionState.Body = body; // make it drop from a height body.Translate(new Vector3(0, 20, 0)); World.AddRigidBody(body); } } } rbInfo.Dispose(); }
public Physics(SceneManager sceneMgr) { // collision configuration contains default setup for memory, collision setup collisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(collisionConf); Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, collisionConf); World.Gravity = new Vector3(0, -10, 0); // create the ground CollisionShape groundShape = new BoxShape(50, 1, 50); CollisionShapes.Add(groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix4.IDENTITY, groundShape); ground.UserObject = "Ground"; // create a few dynamic rigidbodies float mass = 1.0f; CollisionShape colShape = new BoxShape(1); CollisionShapes.Add(colShape); Vector3 localInertia = colShape.CalculateLocalInertia(mass); float start_x = StartPosX - ArraySizeX / 2; float start_y = StartPosY; float start_z = StartPosZ - ArraySizeZ / 2; int k, i, j; for (k = 0; k < ArraySizeY; k++) { for (i = 0; i < ArraySizeX; i++) { for (j = 0; j < ArraySizeZ; j++) { Matrix4 startTransform = new Matrix4(); startTransform.MakeTrans( new Vector3( 2 * i + start_x, 2 * k + start_y, 2 * j + start_z ) ); // using motionstate is recommended, it provides interpolation capabilities // and only synchronizes 'active' objects int index = (k * ArraySizeX + i) * ArraySizeZ + j; Entity box = sceneMgr.CreateEntity("Box" + index.ToString(), "box.mesh"); box.SetMaterialName("BoxMaterial/Active"); SceneNode boxNode = sceneMgr.RootSceneNode.CreateChildSceneNode("BoxNode" + index.ToString()); boxNode.AttachObject(box); boxNode.Scale(new Vector3(2, 2, 2)); MogreMotionState myMotionState = new MogreMotionState(box, boxNode, startTransform); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia); RigidBody body = new RigidBody(rbInfo); myMotionState.Body = body; // make it drop from a height body.Translate(new Vector3(0, 20, 0)); World.AddRigidBody(body); } } } }