public virtual void Init(BulletExampleBasic ctx) { Ctx2 = 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).ToBulletVector3(); }
public override void Init(BulletExampleBasic 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); var boxBody = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(10, 10, 10), 1f, new TGCVector3(10f, 100f, 10f), MathUtil.SIMD_HALF_PI, MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_2_PI, 0, true); boxBodys.Add(boxBody); dynamicsWorld.AddRigidBody(boxBody); var ballBody = BulletRigidBodyFactory.Instance.CreateBall(10f, 1f, new TGCVector3(0f, 50f, 0f)); ballBodys.Add(ballBody); dynamicsWorld.AddRigidBody(ballBody); //Cargamos objetos de render del framework. var floorTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx2.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, Ctx2.MediaDir + @"MeshCreator\Scenes\Deposito\Textures\boxMetal.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); texture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx2.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(); }