public void InitializePhysicsJitter() { #if JITTER if (jitterPhysics == null) { JitterPhysicsComponent jitterPhysics2 = new JitterPhysicsComponent(this); } JitterObject ball = new JitterObject(this, "Models/Sphere"); ball.Shape = new Jitter.Collision.Shapes.SphereShape(1f); ball.SetUpBulletPhysicsBody(); ball.TranslateAA(camera.Position + new Vector3(0, 10, -5)); ball.TextureMaterials.Add("Textures/core1"); ball.NormalMaterials.Add("Textures/core1Normal"); Components.Add(ball); // create a few dynamic rigidbodies float mass = 1.0f; Jitter.Collision.Shapes.BoxShape colShape = new Jitter.Collision.Shapes.BoxShape(Jitter.LinearMath.JVector.One); 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 JitterObject box = new JitterObject(this, "Models/Box"); box.Shape = new Jitter.Collision.Shapes.BoxShape(Jitter.LinearMath.JVector.One); box.SetUpBulletPhysicsBody(); box.Position = startTransform.Translation; box.TextureMaterials.Add("Textures/BoxColor"); box.NormalMaterials.Add("Textures/BoxNormal"); box.TranslateAA(new Vector3(0, 7, 0)); 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 JitterObject box = new JitterObject(this, "Models/Box"); box.Shape = new Jitter.Collision.Shapes.BoxShape(Jitter.LinearMath.JVector.One); box.SetUpBulletPhysicsBody(); box.Position = startTransform.Translation; box.TextureMaterials.Add("Textures/BoxColor01"); box.NormalMaterials.Add("Textures/BoxNormal01"); box.TranslateAA(new Vector3(0, 7, 0)); Components.Add(box); } } } IsPhysicsEnabled = false; #endif }
private void AddRigidBodyToWorld(RigidBody item) { // Initialize the shape Jitter.Collision.Shapes.Shape shape = null; // Box shape if (item.Shape is BoxShape) { var shapeInfo = item.Shape as BoxShape; shape = new Jitter.Collision.Shapes.BoxShape(shapeInfo.Size.X, shapeInfo.Size.Y, shapeInfo.Size.Z); } // Capsule shape else if (item.Shape is CapsuleShape) { var shapeInfo = item.Shape as CapsuleShape; shape = new Jitter.Collision.Shapes.CapsuleShape(shapeInfo.Length, shapeInfo.Radius); } // Default shape else { throw new NotImplementedException("The specified shape has not been implemented"); } // Initialize the body with the specified shape var body = new Jitter.Dynamics.RigidBody(shape) { Position = new JVector(item.Position.X, item.Position.Y, item.Position.Z), IsStatic = item.IsStatic, DynamicFriction = 0, Mass = item.Mass }; // Add the body to the world world.AddBody(body); // Map the item to the world item worldItems.Add(item, body); // TODO: DEBUG code only if (item.Id == "Player") { var constraint = new CharacterController(world, body); world.AddConstraint(constraint); item.Tag = constraint; } }
public BoxShape(float xSize, float ySize, float zSize) { boxShape = new Jitter.Collision.Shapes.BoxShape(xSize, ySize, zSize); }