示例#1
0
        public override void Init()
        {
            terrain = new TgcSimpleTerrain();
            var position = TGCVector3.Empty;

            terrain.loadHeightmap(MediaDir + "Heighmaps\\" + "TerrainTexture2.jpg", 20, 0.5f, position);
            terrain.loadTexture(MediaDir + "Heighmaps\\" + "grass.jpg");

            physicsExample = new TriangleSpherePhysics();
            physicsExample.SetTriangleDataVB(terrain.getData());
            physicsExample.Init(MediaDir);

            Camara = new TgcRotationalCamera(new TGCVector3(0, 20, 0), 1000, Input);
        }
示例#2
0
        public void Init(TgcSimpleTerrain terrain)
        {
            collisionConfiguration = new DefaultCollisionConfiguration();
            dispatcher             = new CollisionDispatcher(collisionConfiguration);
            GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
            constraintSolver      = new SequentialImpulseConstraintSolver();
            broadphaseInterface   = new DbvtBroadphase();
            dynamicsWorld         = new DiscreteDynamicsWorld(dispatcher, broadphaseInterface, constraintSolver, collisionConfiguration);
            dynamicsWorld.Gravity = gravity;

            var ballShape     = new SphereShape(50);
            var ballTransform = TGCMatrix.Identity;

            ballTransform.Origin = initialPosition;
            var ballMotionState = new DefaultMotionState(ballTransform.ToBsMatrix);
            var ballInertia     = ballShape.CalculateLocalInertia(1f);
            var ballInfo        = new RigidBodyConstructionInfo(1, ballMotionState, ballShape, ballInertia);

            RigidCamera = new RigidBody(ballInfo);
            RigidCamera.SetDamping(0.9f, 0.9f);

            //esto es para que no le afecte la gravedad al inicio de la partida
            //RigidCamera.ActivationState = ActivationState.IslandSleeping;
            dynamicsWorld.AddRigidBody(RigidCamera);

            var heighmapRigid = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(terrain.getData());

            dynamicsWorld.AddRigidBody(heighmapRigid);
        }
示例#3
0
        public void Init(string MediaDir)
        {
            #region Configuracion Basica de World

            //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, -100f, 0).ToBulletVector3();

            #endregion Configuracion Basica de World

            strength = 5.8f;
            angle    = 0.5f;

            foreach (var mesh in meshes)
            {
                var childTriangleMesh = construirTriangleMeshShape(mesh);
                var buildingbody      = construirRigidBodyDeChildTriangleMeshShape(childTriangleMesh, mesh.Position, mesh.Scale);


                //buildingbody.Translate(mesh.Position.ToBulletVector3());
                dynamicsWorld.AddRigidBody(buildingbody);
            }

            //Se crea un plano ya que esta escena tiene problemas
            //con la definición de triangulos para el suelo
            var floorShape = new StaticPlaneShape(TGCVector3.Up.ToBulletVector3(), 10);
            floorShape.LocalScaling = new TGCVector3().ToBulletVector3();
            var floorMotionState = new DefaultMotionState();
            var floorInfo        = new RigidBodyConstructionInfo(0, floorMotionState, floorShape);
            floorBody                 = new RigidBody(floorInfo);
            floorBody.Friction        = 0.5f;
            floorBody.RollingFriction = 1;
            floorBody.Restitution     = 1f;
            floorBody.UserObject      = "floorBody";
            dynamicsWorld.AddRigidBody(floorBody);

            var meshRigidBody = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(terreno.getData());
            dynamicsWorld.AddRigidBody(meshRigidBody);

            var loader = new TgcSceneLoader();

            //Se crea el cuerpo rígido de la caja, en la definicio de CreateBox el ultimo parametro representa si se quiere o no
            //calcular el momento de inercia del cuerpo. No calcularlo lo que va a hacer es que la caja que representa el personaje
            //no rote cuando colicione contra el mundo.
            personajeBody = BulletRigidBodyFactory.Instance.CreateCapsule(10, 10, personaje.Position, 2.55f, false);

            personajeBody.Gravity = new TGCVector3(0, -100, 0).ToBulletVector3();
            personajeBody.SetDamping(0.3f, 0f);
            personajeBody.Restitution     = 0.1f;
            personajeBody.Friction        = 1;
            personajeBody.ActivationState = ActivationState.IslandSleeping;

            dynamicsWorld.AddRigidBody(personajeBody);

            director = new TGCVector3(-1, 0, 0);
        }