public override void Init(BulletExampleWall ctx) { base.Init(ctx); //Creamos shapes y bodies. //El piso es un plano estatico se dice que si tiene masa 0 es estatico. var floorShape = new StaticPlaneShape(TGCVector3.Up.ToBulletVector3(), 0); var floorMotionState = new DefaultMotionState(); var floorInfo = new RigidBodyConstructionInfo(0, floorMotionState, floorShape); floorBody = new RigidBody(floorInfo); dynamicsWorld.AddRigidBody(floorBody); //Se crea una caja de tamaño 20 con rotaciones y origien en 10,100,10 y 1kg de masa. var boxShape = new BoxShape(10, 10, 10); var boxTransform = TGCMatrix.RotationYawPitchRoll(MathUtil.SIMD_HALF_PI, MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_2_PI).ToBsMatrix; boxTransform.Origin = new TGCVector3(10, 100, 10).ToBulletVector3(); DefaultMotionState boxMotionState = new DefaultMotionState(boxTransform); //Es importante calcular la inercia caso contrario el objeto no rotara. var boxLocalInertia = boxShape.CalculateLocalInertia(1f); var boxInfo = new RigidBodyConstructionInfo(1f, boxMotionState, boxShape, boxLocalInertia); boxBody = new RigidBody(boxInfo); dynamicsWorld.AddRigidBody(boxBody); //Crea una bola de radio 10 origen 50 de 1 kg. var ballShape = new SphereShape(10); var ballTransform = TGCMatrix.Identity; ballTransform.Origin = new TGCVector3(0, 50, 0); var ballMotionState = new DefaultMotionState(ballTransform.ToBsMatrix); //Podriamos no calcular la inercia para que no rote, pero es correcto que rote tambien. var ballLocalInertia = ballShape.CalculateLocalInertia(1f); var ballInfo = new RigidBodyConstructionInfo(1, ballMotionState, ballShape, ballLocalInertia); ballBody = new RigidBody(ballInfo); dynamicsWorld.AddRigidBody(ballBody); //Cargamos objetos de render del framework. var floorTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"Texturas\granito.jpg"); floorMesh = new TgcPlane(new TGCVector3(-200, 0, -200), new TGCVector3(400, 0f, 400), TgcPlane.Orientations.XZplane, floorTexture); var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"Texturas\madera.jpg"); //Es importante crear todos los mesh con centro en el 0,0,0 y que este coincida con el centro de masa definido caso contrario rotaria de otra forma diferente a la dada por el motor de fisica. boxMesh = TGCBox.fromSize(new TGCVector3(20, 20, 20), texture); //Se crea una esfera de tamaño 1 para escalarla luego (en render) sphereMesh = new TGCSphere(1, texture.Clone(), TGCVector3.Empty); //Tgc no crea el vertex buffer hasta invocar a update values. sphereMesh.updateValues(); }
public virtual void Init(BulletExampleWall ctx) { Ctx = ctx; //Creamos el mundo fisico por defecto. collisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfiguration); GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher); constraintSolver = new SequentialImpulseConstraintSolver(); overlappingPairCache = new DbvtBroadphase(); //AxisSweep3(new BsVector3(-5000f, -5000f, -5000f), new BsVector3(5000f, 5000f, 5000f), 8192); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration); dynamicsWorld.Gravity = new TGCVector3(0, -20f, 0).ToBsVector; }
public override void Init(BulletExampleWall ctx) { base.Init(ctx); //Creamos shapes y bodies. //El piso es un plano estatico se dice que si tiene masa 0 es estatico. var floorShape = new StaticPlaneShape(TGCVector3.Up.ToBsVector, 0); var floorMotionState = new DefaultMotionState(); var floorInfo = new RigidBodyConstructionInfo(0, floorMotionState, floorShape); floorBody = new RigidBody(floorInfo); floorBody.Friction = 1; floorBody.RollingFriction = 1; // ballBody.SetDamping(0.1f, 0.9f); floorBody.Restitution = 1f; floorBody.UserObject = "floorBody"; dynamicsWorld.AddRigidBody(floorBody); for (var i = -10; i < 10; i++) { for (var j = 0; j < 10; j++) { var boxBody = BulletRigidBodyConstructor.CreateBox(new TGCVector3(10, 10, 10), 1, new TGCVector3(i * 20f + 5f, j * 20f + 5f, 0f), 0, 0, 0, 0.5f); boxBodys.Add(boxBody); dynamicsWorld.AddRigidBody(boxBody); } } //Cargamos objetos de render del framework. var floorTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"Texturas\granito.jpg"); floorMesh = new TgcPlane(new TGCVector3(-2000, 0, -2000), new TGCVector3(4000, 0f, 4000), TgcPlane.Orientations.XZplane, floorTexture); var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"\MeshCreator\Scenes\Deposito\Textures\box1.jpg"); //Es importante crear todos los mesh con centro en el 0,0,0 y que este coincida con el centro de masa definido caso contrario rotaria de otra forma diferente a la dada por el motor de fisica. boxMesh1 = TGCBox.fromSize(new TGCVector3(20, 20, 20), texture); texture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"\MeshCreator\Scenes\Deposito\Textures\box4.jpg"); boxMesh2 = TGCBox.fromSize(new TGCVector3(20, 20, 20), texture); texture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"\MeshCreator\Scenes\Deposito\Textures\box3.jpg"); boxMesh3 = TGCBox.fromSize(new TGCVector3(20, 20, 20), texture); texture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"\MeshCreator\Scenes\Deposito\Textures\box4.jpg"); boxMesh4 = TGCBox.fromSize(new TGCVector3(20, 20, 20), texture); texture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"\Texturas\pokeball.jpg"); //Se crea una esfera de tamaño 1 para escalarla luego (en render) sphereMesh = new TGCSphere(1, texture, TGCVector3.Empty); //Tgc no crea el vertex buffer hasta invocar a update values. sphereMesh.updateValues(); }