public void InitializePhysicsBulletXNA() { #if BULLETXNA CollisionFilterGroups colGroup = CollisionFilterGroups.DefaultFilter; CollisionFilterGroups colMask = CollisionFilterGroups.AllFilter; float sphereMass = 5f; CollisionShape sphereShape = new Bullet.BulletCollision.SphereShape(1); Bullet.LinearMath.IndexedVector3 sphereLocalInertia; sphereShape.CalculateLocalInertia(sphereMass, out sphereLocalInertia); BulletXNAObject ball = new BulletXNAObject(this, "Models/Sphere", sphereMass, new Bullet.DefaultMotionState(Matrix.CreateTranslation(camera.Position + new Vector3(0, 10, -5)), Matrix.Identity), sphereShape, sphereLocalInertia, colGroup, colMask); ball.TranslateAA(camera.Position + new Vector3(0, 10, 0)); ball.TextureMaterials.Add("Textures/core1"); ball.NormalMaterials.Add("Textures/core1Normal"); ball.RigidBody.SetFriction(1); boxs.Add(ball); Components.Add(ball); // create a few dynamic rigidbodies float mass = 1.0f; Bullet.BulletCollision.CollisionShape colShape = new Bullet.BulletCollision.BoxShape(Vector3.One); //CollisionShapes.Add(colShape); Vector3 localInertia = Vector3.Zero; Bullet.LinearMath.IndexedVector3 li = Bullet.LinearMath.IndexedVector3.Zero; colShape.CalculateLocalInertia(mass, out li); localInertia = li; float start_x = StartPosX - ArraySizeX / 2; float start_y = StartPosY; float start_z = StartPosZ - ArraySizeZ / 2; start_z -= 8; Random rnd = new Random(); int k, i, j; for (k = 0; k < ArraySizeY; k++) { for (i = 0; i < ArraySizeX; i++) { for (j = 0; j < ArraySizeZ; j++) { Matrix startTransform = Matrix.CreateTranslation( 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 BulletXNAObject box = new BulletXNAObject(this, "Models/Box", mass, new Bullet.DefaultMotionState(startTransform, Matrix.Identity), colShape, localInertia, colGroup, colMask); box.TextureMaterials.Add("Textures/BoxColor"); box.NormalMaterials.Add("Textures/BoxNormal"); box.TranslateAA(new Vector3(0, 7, 0)); boxs.Add(box); Components.Add(box); } } } start_x -= 8; for (k = 0; k < 2; k++) { for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { Matrix startTransform = Matrix.CreateTranslation( 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 BulletXNAObject box = new BulletXNAObject(this, "Models/Box", mass, new Bullet.DefaultMotionState(startTransform, Matrix.Identity), colShape, localInertia, colGroup, colMask); box.TextureMaterials.Add("Textures/BoxColor01"); box.NormalMaterials.Add("Textures/BoxNormal01"); box.TranslateAA(new Vector3(0, 7, 0)); boxs.Add(box); Components.Add(box); } } } IsPhysicsEnabled = false; #endif }
public void InitializePhysicsBulletXNA() { #if BULLETXNA CollisionFilterGroups colGroup = CollisionFilterGroups.DefaultFilter; CollisionFilterGroups colMask = CollisionFilterGroups.AllFilter; float sphereMass = 5f; CollisionShape sphereShape = new Bullet.BulletCollision.SphereShape(1); Bullet.LinearMath.IndexedVector3 sphereLocalInertia; sphereShape.CalculateLocalInertia(sphereMass,out sphereLocalInertia); BulletXNAObject ball = new BulletXNAObject(this, "Models/Sphere", sphereMass, new Bullet.DefaultMotionState(Matrix.CreateTranslation(camera.Position + new Vector3(0, 10, -5)), Matrix.Identity),sphereShape , sphereLocalInertia, colGroup, colMask); ball.TranslateAA(camera.Position + new Vector3(0, 10, 0)); ball.TextureMaterials.Add("Textures/core1"); ball.NormalMaterials.Add("Textures/core1Normal"); ball.RigidBody.SetFriction(1); boxs.Add(ball); Components.Add(ball); // create a few dynamic rigidbodies float mass = 1.0f; Bullet.BulletCollision.CollisionShape colShape = new Bullet.BulletCollision.BoxShape(Vector3.One); //CollisionShapes.Add(colShape); Vector3 localInertia = Vector3.Zero; Bullet.LinearMath.IndexedVector3 li = Bullet.LinearMath.IndexedVector3.Zero; colShape.CalculateLocalInertia(mass, out li); localInertia = li; float start_x = StartPosX - ArraySizeX / 2; float start_y = StartPosY; float start_z = StartPosZ - ArraySizeZ / 2; start_z -= 8; Random rnd = new Random(); int k, i, j; for (k = 0; k < ArraySizeY; k++) { for (i = 0; i < ArraySizeX; i++) { for (j = 0; j < ArraySizeZ; j++) { Matrix startTransform = Matrix.CreateTranslation( 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 BulletXNAObject box = new BulletXNAObject(this, "Models/Box", mass, new Bullet.DefaultMotionState(startTransform, Matrix.Identity), colShape, localInertia, colGroup, colMask); box.TextureMaterials.Add("Textures/BoxColor"); box.NormalMaterials.Add("Textures/BoxNormal"); box.TranslateAA(new Vector3(0, 7, 0)); boxs.Add(box); Components.Add(box); } } } start_x -= 8; for (k = 0; k < 2; k++) { for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { Matrix startTransform = Matrix.CreateTranslation( 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 BulletXNAObject box = new BulletXNAObject(this, "Models/Box", mass, new Bullet.DefaultMotionState(startTransform, Matrix.Identity), colShape, localInertia, colGroup, colMask); box.TextureMaterials.Add("Textures/BoxColor01"); box.NormalMaterials.Add("Textures/BoxNormal01"); box.TranslateAA(new Vector3(0, 7, 0)); boxs.Add(box); Components.Add(box); } } } IsPhysicsEnabled = false; #endif }