コード例 #1
0
        private void InitializeMeshes()
        {
            TgcTexture tiles, lava, stones, water;

            tiles  = TgcTexture.createTexture(MediaDir + "Textures/tiles.jpg");
            lava   = TgcTexture.createTexture(MediaDir + "Textures/lava.jpg");
            stones = TgcTexture.createTexture(MediaDir + "Textures/stones.bmp");
            water  = TgcTexture.createTexture(MediaDir + "Textures/water.bmp");

            TGCSphere baseSphere = new TGCSphere(1f, Color.White, TGCVector3.Empty);

            baseSphere.setTexture(lava);
            baseSphere.updateValues();
            sphereOne = baseSphere.toMesh("sphereOne");
            meshes.Add(sphereOne);
            baseSphere.setTexture(stones);
            sphereTwo = baseSphere.toMesh("sphereTwo");
            meshes.Add(sphereTwo);
            baseSphere.setTexture(water);
            sphereThree = baseSphere.toMesh("sphereThree");
            meshes.Add(sphereThree);

            TgcSceneLoader loader = new TgcSceneLoader();
            var            scene  = loader.loadSceneFromFile(MediaDir + "Robot2-TgcScene.xml");

            robot           = scene.Meshes[0];
            robot.Transform = TGCMatrix.Scaling(0.1f, 0.1f, 0.1f) * TGCMatrix.RotationY(FastMath.PI) * TGCMatrix.Translation(TGCVector3.Up * 40f);
            meshes.Add(robot);

            TgcPlane tgcPlane = new TgcPlane(TGCVector3.Empty, TGCVector3.One * 100f, TgcPlane.Orientations.XZplane, tiles, 10f, 10f);

            plane = tgcPlane.toMesh("plane");
            meshes.Add(plane);
        }
コード例 #2
0
        /// <summary>
        /// Construir caja
        /// </summary>
        public override void doCreation()
        {
            var input = Control.creator.Input;

            //Si hacen clic con el mouse, ver si hay colision con el suelo
            if (input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
            {
                //Determinar el size en XZ del box
                var collisionPoint = Control.Grid.getPicking();

                mesh.Position = initSelectionPoint;
                //Configurar BOX
                mesh.Radius = (collisionPoint - initSelectionPoint).Length();
                mesh.updateValues();
            }
            else
            {
                originalRadius = mesh.Radius;
                updateBB();
                //Dejar cargado para que se pueda crear un nuevo sphere
                Control.CurrentState      = MeshCreatorModifier.State.CreatePrimitiveSelected;
                Control.CreatingPrimitive = new SpherePrimitive(Control);

                //Agregar sphere a la lista de modelos
                Control.AddMesh(this);

                //Seleccionar Box
                Control.SelectionRectangle.clearSelection();
                Control.SelectionRectangle.selectObject(this);
                Control.UpdateModifyPanel();
            }
        }
コード例 #3
0
        public void Init(string MediaDir)
        {
            //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();

            //Creamos el terreno
            var meshRigidBody = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(triangleDataVB);

            dynamicsWorld.AddRigidBody(meshRigidBody);

            //Creamos la esfera del dragon
            dragonBall = BulletRigidBodyFactory.Instance.CreateBall(30f, 0.75f, new TGCVector3(100f, 500f, 100f));
            dragonBall.SetDamping(0.1f, 0.5f);
            dragonBall.Restitution = 1f;
            dragonBall.Friction    = 1;
            dynamicsWorld.AddRigidBody(dragonBall);
            var textureDragonBall = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\dragonball.jpg");

            sphereMesh = new TGCSphere(1, textureDragonBall, TGCVector3.Empty);
            sphereMesh.updateValues();
            director = new TGCVector3(1, 0, 0);
        }
コード例 #4
0
        private void InitializeSphere()
        {
            var transparentTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\transparent.png");

            boundingSphere = new TgcBoundingSphere(TGCVector3.Empty, radius);

            sphere = new TGCSphere(1.0f, transparentTexture, TGCVector3.Empty);
            sphere.AlphaBlendEnable = true;
            sphere.updateValues();
            sphere.Transform = TGCMatrix.Scaling(new TGCVector3(radius, radius, radius));
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        private void createSphereMesh(TgcTexture texture)
        {
            var rawSphere = new TGCSphere(1, texture, this.center);

            rawSphere.LevelOfDetail = 4;
            rawSphere.updateValues();
            this.sphere = rawSphere.toMesh("Mesh");

            this.sphere.Effect    = this.effect;
            this.sphere.Technique = this.techniques[this.technique];
        }
コード例 #7
0
        private void CreateMesh()
        {
            var lava   = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "\\Texturas\\lava.jpg");
            var sphere = new TGCSphere(1, lava, TGCVector3.Empty);

            sphere.LevelOfDetail = 4;
            sphere.updateValues();

            this.mesh = sphere.toMesh("Mesh");

            this.mesh.Effect = this.effect;
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        /// <summary>
        ///     Actualiza los parámetros de la caja en base a lo cargado por el usuario
        /// </summary>
        private void updateSphere()
        {
            var bTexture = useTextureModifier.Value;
            var color    = colorModifier.Value;

            sphere.RenderEdges = edgesModifier.Value;
            sphere.Inflate     = inflateModifier.Value;
            sphere.BasePoly    = (TGCSphere.eBasePoly)baseModifier.Value;

            if (bTexture)
            {
                //Cambiar textura
                var texturePath = textureModifier.Value;
                if (texturePath != currentTexture || !useTexture || (sphere.RenderEdges && sphere.Color != color))
                {
                    currentTexture = texturePath;
                    sphere.setColor(color);
                    sphere.setTexture(TgcTexture.createTexture(D3DDevice.Instance.Device, currentTexture));
                }
            }
            else
            {
                sphere.setColor(color);
            }

            useTexture = bTexture;

            //Radio, posición y color
            sphere.Radius        = radiusModifier.Value;
            sphere.Position      = positionModifier.Value;
            sphere.LevelOfDetail = (int)levelOfDetailModifier.Value;

            //Rotación, converitr a radianes
            var rotation = rotationModifier.Value;

            sphere.Rotation = new TGCVector3(Geometry.DegreeToRadian(rotation.X), Geometry.DegreeToRadian(rotation.Y), Geometry.DegreeToRadian(rotation.Z));

            //Offset de textura
            sphere.UVOffset = offsetModifier.Value;

            //Tiling de textura
            sphere.UVTiling = tilingModifier.Value;

            //Actualizar valores en la caja.
            sphere.updateValues();
        }
コード例 #10
0
ファイル: PBR.cs プロジェクト: Farabute/tgc-viewer
        private void InitializeSphere()
        {
            // Got to set a texture, else the translation to mesh does not map UV
            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\white.bmp");

            var sphere = new TGCSphere();

            sphere.Radius        = 40.0f;
            sphere.LevelOfDetail = 3;
            sphere.setTexture(texture);
            sphere.updateValues();

            sphereMesh             = sphere.toMesh("sphere");
            sphereMesh.Transform   = TGCMatrix.Scaling(TGCVector3.One * 30f);
            sphereMesh.Effect      = effect;
            sphereMesh.Technique   = "PBR";
            sphereMesh.DiffuseMaps = new TgcTexture[0];
            sphereMesh.RenderType  = TgcMesh.MeshRenderType.VERTEX_COLOR;
            sphere.Dispose();
        }
コード例 #11
0
        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();
        }
コード例 #12
0
        private void InitializePBRMesh()
        {
            // Got to set a texture, else the translation to mesh does not map UV
            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\white.bmp");

            var sphere = new TGCSphere();

            sphere.Radius        = 40.0f;
            sphere.LevelOfDetail = 3;
            sphere.setTexture(texture);
            sphere.updateValues();

            pbrMesh             = sphere.toMesh("sphere");
            pbrMesh.Effect      = effect;
            pbrMesh.Technique   = "PBRIBL";
            pbrMesh.DiffuseMaps = new TgcTexture[0];
            pbrMesh.RenderType  = TgcMesh.MeshRenderType.VERTEX_COLOR;
            sphere.Dispose();

            var texturePath = MediaDir + "Texturas\\";

            var scaling = TGCMatrix.Scaling(TGCVector3.One * 25f);
            var harsh   = new PBRTexturedMesh("Harsh-Metal", texturePath, scaling * TGCMatrix.Translation(0f, 100f, 100f), pbrMesh);
            var gold    = new PBRTexturedMesh("Gold", texturePath, scaling * TGCMatrix.Translation(0f, 100f, 0f), pbrMesh);
            var marble  = new PBRTexturedMesh("Marble", texturePath, scaling * TGCMatrix.Translation(0f, 100f, -100f), pbrMesh);
            var ground  = new PBRTexturedMesh("Ground", texturePath, scaling * TGCMatrix.Translation(0f, 100f, -200f), pbrMesh);
            var metal   = new PBRTexturedMesh("Metal", texturePath, scaling * TGCMatrix.Translation(0f, 100f, 200f), pbrMesh);

            pbrTexturedMeshes.AddRange(new List <PBRTexturedMesh> {
                harsh, gold, marble, ground, metal
            });

            var greenSomething = new PBRMesh(new TGCVector3(0.05f, 0.74f, 0.3f), 0.5f, 0.5f, scaling * TGCMatrix.Translation(0f, 100f, 400f), pbrMesh);
            var redRubber      = new PBRMesh(new TGCVector3(1f, 0.05f, 0.1f), 0.1f, 0.9f, scaling * TGCMatrix.Translation(0f, 100f, 300f), pbrMesh);
            var blueMetal      = new PBRMesh(new TGCVector3(0f, 0.2f, 1.0f), 0.75f, 0.3f, scaling * TGCMatrix.Translation(0f, 100f, -300f), pbrMesh);

            pbrMeshes.AddRange(new List <PBRMesh> {
                redRubber, blueMetal, greenSomething
            });
        }
コード例 #13
0
        private void Init()
        {
            Scales.Add(new TGCVector3(10, 10, 10));
            Scales.Add(new TGCVector3(25, 25, 25));
            Scales.Add(new TGCVector3(35, 35, 35));
            Scales.Add(new TGCVector3(50, 50, 50));

            var texture = TgcTexture.createTexture(MediaDir + @"\Textures\bubble.png");

            BubbleTemplate = new TGCSphere(30, texture, new TGCVector3(0, 0, 0))
            {
                AlphaBlendEnable = true
            };
            BubbleTemplate.updateValues();
            BubbleTemplate.Transform = TGCMatrix.Scaling(Scales[Random.Next(0, Scales.Count)]);

            for (int index = 1; index <= 200; index++)
            {
                Bubbles.Add(BubbleTemplate.clone());
                BubblesAux.Add(BubbleTemplate.clone());
            }
        }
コード例 #14
0
        public void init(string textura, TgcMesh planta)
        {
            var d3dDevice = D3DDevice.Instance.Device;

            #region configurarObjeto

            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, GameModel.mediaDir + "modelos\\Textures\\" + textura + ".jpg");
            esfera           = new TGCSphere(1, texture.Clone(), TGCVector3.Empty);
            efecto           = TgcShaders.loadEffect(GameModel.shadersDir + "shaderPlanta.fx");
            esfera.Effect    = efecto;
            esfera.Technique = "RenderScene";
            esfera.Scale     = new TGCVector3(30.5f, 30.5f, 30.5f);
            esfera.Position  = planta.Position;
            esfera.Rotation  = planta.Rotation;
            esfera.updateValues();

            objetos.Add(esfera);
            #endregion

            GameSound.disparar();
            PostProcess.agregarPostProcessObject(this);
        }
コード例 #15
0
        public void Init(String MediaDir)
        {
            #region world configuration
            // Create a physics world using default config
            collisionConfiguration = new DefaultCollisionConfiguration();
            dispatcher             = new CollisionDispatcher(collisionConfiguration);
            GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
            constraintSolver     = new SequentialImpulseConstraintSolver();
            overlappingPairCache = new DbvtBroadphase();
            dynamicsWorld        = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration);

            var gravity = new TGCVector3(0, -60f, 0).ToBsVector;
            dynamicsWorld.Gravity = gravity;

            if (UsingHeightmap)
            {
                var heightMap = BulletRigidBodyConstructor.CreateSurfaceFromHeighMap(triangleDataVB);
                heightMap.Restitution = 0;
                dynamicsWorld.AddRigidBody(heightMap);
            }
            #endregion
            float      radius       = 30f;
            float      mass         = 0.75f;
            var        centerOfMass = new TGCVector3(-50f, 30, -200f);
            TGCVector3 size         = TGCVector3.Empty;

            #region Stone Sphere
            ball = BulletRigidBodyConstructor.CreateBall(radius, mass, centerOfMass);
            ball.SetDamping(0.1f, 0.5f);
            ball.Restitution = 1f;
            ball.Friction    = 1;
            dynamicsWorld.AddRigidBody(ball);

            var ballTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, $"{MediaDir}\\Textures\\rockwall.jpg");
            sphereMesh = new TGCSphere(radius, ballTexture, TGCVector3.Empty);
            sphereMesh.BoundingSphere.setValues(centerOfMass, radius);
            sphereMesh.updateValues();

            director = new TGCVector3(1, 0, 0);
            #endregion

            #region BandicootRigidBody
            //Cuerpo rigido de una caja basica
            var position = new TGCVector3(0, 1, 0);
            mass = 1.5f;
            bandicootRigidBody = BulletRigidBodyConstructor.CreateCapsule(10, 5, position, mass, false);

            //Valores que podemos modificar a partir del RigidBody base
            bandicootRigidBody.SetDamping(0.1f, 0f);
            bandicootRigidBody.Restitution         = 0f;
            bandicootRigidBody.Friction            = 0.5f;
            bandicootRigidBody.InvInertiaDiagLocal = TGCVector3.Empty.ToBsVector;
            //Agregamos el RidigBody al World
            dynamicsWorld.AddRigidBody(bandicootRigidBody);
            #endregion

            #region Stairs
            mass = 0;
            size = new TGCVector3(50, 20, 30);
            var   platformTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, $"{MediaDir}\\textures\\rockwall.jpg");
            float angle           = 0.75f * FastMath.PI;

            for (float i = 0, x = size.Z, y = size.Y, z = -size.X; i < 10; i++)
            {
                staticPlatform = BulletRigidBodyConstructor.CreateBox(size, mass, centerOfMass, 0, 0, 0, 0.7f);
                staticPlatform.CenterOfMassTransform = TGCMatrix.RotationY(angle).ToBsMatrix *TGCMatrix.Translation(x, y, z).ToBsMatrix;
                dynamicsWorld.AddRigidBody(staticPlatform);

                staticPlatformMesh           = TGCBox.fromSize(2 * size, platformTexture);
                staticPlatformMesh.Transform = new TGCMatrix(staticPlatform.InterpolationWorldTransform);
                stairsMesh.Add(staticPlatformMesh);

                x     += 35;
                y     += 40;
                z     -= 25;
                angle -= 0.1f;
            }
            #endregion

            #region Dynamic Platform

            position        = new TGCVector3(0, 0, 0);
            mass            = 1f;
            size            = new TGCVector3(70, 10, 30);
            dynamicPlatform = BulletRigidBodyConstructor.CreateBox(size, mass, position, 0, 0, 0, 2f);
            dynamicPlatform.CenterOfMassTransform = TGCMatrix.Translation(-300, 60, -200).ToBsMatrix;
            dynamicPlatform.AngularFactor         = (new Vector3(0, 0, 0));
            dynamicsWorld.AddRigidBody(dynamicPlatform);

            // mesh para visualizar plataforma

            var platformtexture = TgcTexture.createTexture(D3DDevice.Instance.Device, $"{MediaDir}\\textures\\rockwall.jpg");
            dynamicPlatformMesh                     = TGCBox.fromSize(2 * size, platformtexture);
            dynamicPlatformMesh.Transform           = new TGCMatrix(dynamicPlatform.InterpolationWorldTransform);
            dynamicPlatformMesh.AutoTransformEnable = false;
            dynamicPlatformMesh.updateValues();

            #endregion
        }
コード例 #16
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

            #region Capsula

            //Cuerpo rigido de una capsula basica
            capsuleRigidBody = BulletRigidBodyFactory.Instance.CreateCapsule(10, 50, new TGCVector3(200, 500, 200), 10, false);

            //Valores que podemos modificar a partir del RigidBody base
            capsuleRigidBody.SetDamping(0.1f, 0f);
            capsuleRigidBody.Restitution = 0.1f;
            capsuleRigidBody.Friction    = 1;

            //Agregamos el RidigBody al World
            dynamicsWorld.AddRigidBody(capsuleRigidBody);

            #endregion Capsula

            #region Terreno

            //Creamos el RigidBody basico del Terreno
            var meshRigidBody = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(triangleDataVB);

            //Agregamos algo de friccion al RigidBody ya que este va a interactuar con objetos moviles
            //del World
            meshRigidBody.Friction = 0.5f;

            //Agregamos el RigidBody del terreno al World
            dynamicsWorld.AddRigidBody(meshRigidBody);

            #endregion Terreno

            #region Esfera

            //Creamos una esfera para interactuar
            pokeball = BulletRigidBodyFactory.Instance.CreateBall(10f, 0.5f, new TGCVector3(100f, 500f, 100f));
            pokeball.SetDamping(0.1f, 0.5f);
            pokeball.Restitution = 1f;
            //Agregamos la pokebola al World
            dynamicsWorld.AddRigidBody(pokeball);

            //Textura de pokebola
            var texturePokeball = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\pokeball.jpg");

            //Se crea una esfera de tamaño 1 para escalarla luego (en render)
            sphereMesh = new TGCSphere(1, texturePokeball, TGCVector3.Empty);

            //Tgc no crea el vertex buffer hasta invocar a update values.
            sphereMesh.updateValues();

            #endregion Esfera

            #region Personaje

            //Cargamos personaje
            var skeletalLoader = new TgcSkeletalLoader();
            personaje = skeletalLoader.loadMeshAndAnimationsFromFile(
                MediaDir + "SkeletalAnimations\\Robot\\Robot-TgcSkeletalMesh.xml",
                MediaDir + "SkeletalAnimations\\Robot\\",
                new[]
            {
                MediaDir + "SkeletalAnimations\\Robot\\Caminando-TgcSkeletalAnim.xml",
                MediaDir + "SkeletalAnimations\\Robot\\Parado-TgcSkeletalAnim.xml"
            });

            //Le cambiamos la textura para diferenciarlo un poco
            personaje.changeDiffuseMaps(new[]
            {
                TgcTexture.createTexture(D3DDevice.Instance.Device,
                                         MediaDir + "SkeletalAnimations\\Robot\\Textures\\uvwGreen.jpg")
            });

            //Configurar animacion inicial
            personaje.playAnimation("Parado", true);

            #endregion Personaje

            #region Cajas

            var sizeBox = 20f;

            //Textura de caja
            var textureBox = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"MeshCreator\Textures\Madera\cajaMadera2.jpg");

            box = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(sizeBox, sizeBox, sizeBox), 0, new TGCVector3(0, 12, 0), 0, 0, 0, 0.5f, true);
            dynamicsWorld.AddRigidBody(box);
            boxMesh = TGCBox.fromSize(new TGCVector3(40f, 40f, 40f), textureBox);
            boxMesh.updateValues();

            sizeBox = 40f;
            boxB    = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(sizeBox, sizeBox, sizeBox), 0, new TGCVector3(100, 40, 0), 0, 0, 0, 0.5f, true);
            dynamicsWorld.AddRigidBody(boxB);
            boxMeshB = TGCBox.fromSize(new TGCVector3(80f, 80f, 80f), textureBox);
            boxMeshB.updateValues();

            box45 = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(sizeBox, sizeBox, sizeBox), 0, new TGCVector3(200, 40, 0), BulletSharp.MathUtil.SIMD_QUARTER_PI, 0, 0, 0.5f, true);
            dynamicsWorld.AddRigidBody(box45);

            boxPush = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(sizeBox, sizeBox, sizeBox), 0.5f, new TGCVector3(-200, 60, 0), BulletSharp.MathUtil.SIMD_QUARTER_PI, 0, 0, 0.25f, true);
            dynamicsWorld.AddRigidBody(boxPush);

            boxMeshPush = TGCBox.fromSize(new TGCVector3(80f, 80f, 80f), textureBox);
            boxMeshPush.updateValues();

            #endregion Cajas

            #region Escalera

            var a             = 0;
            var textureStones = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\stones.bmp");

            //la altura de cualquier cubo que quiera subir una capsula debe ser menor a la mitad del radio
            var size = new TGCVector3(50, 4, 20);
            escalon = TGCBox.fromSize(size, textureStones);

            //Se crean 10 escalonescd d
            while (a < 10)
            {
                escalonRigidBody = BulletRigidBodyFactory.Instance.CreateBox(size, 0, new TGCVector3(200, a * 4 + 10, a * 20 + 100), 0, 0, 0, 0.1f, true);

                escalonesRigidBodies.Add(escalonRigidBody);

                dynamicsWorld.AddRigidBody(escalonRigidBody);

                a++;
            }

            #endregion Escalera

            #region Plataforma

            textureStones       = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\cobblestone_quad.jpg");
            rigidBodyPlataforma = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(50f, 15f, 50f), 0, new TGCVector3(200, 42.5f, 315), 0, 0, 0, 0.5f, true);
            dynamicsWorld.AddRigidBody(rigidBodyPlataforma);
            plataforma = TGCBox.fromSize(new TGCVector3(50f, 15f, 50f), textureStones);
            plataforma.updateValues();

            #endregion Plataforma

            #region Columna

            columnaRigidBody = BulletRigidBodyFactory.Instance.CreateCylinder(new TGCVector3(10, 50, 10), new TGCVector3(100, 50, 100), 0);
            dynamicsWorld.AddRigidBody(columnaRigidBody);
            var columnaLoader = new TgcSceneLoader();
            columnaMesh          = columnaLoader.loadSceneFromFile(MediaDir + @"MeshCreator\Meshes\Cimientos\PilarEgipcio\PilarEgipcio-TgcScene.xml", MediaDir + @"MeshCreator\Meshes\Cimientos\PilarEgipcio\").Meshes[0];
            columnaMesh.Position = new TGCVector3(100, 7.5f, 100);
            columnaMesh.UpdateMeshTransform();

            #endregion Columna

            director = new TGCVector3(0, 0, 1);
        }
コード例 #17
0
        public void Init()
        {
            #region MUNDO_FISICO //Creamos el mundo fisico por defecto.
            collisionConfiguration = new DefaultCollisionConfiguration();
            dispatcher             = new CollisionDispatcher(collisionConfiguration);

            GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
            constraintSolver     = new SequentialImpulseConstraintSolver();
            overlappingPairCache = new DbvtBroadphase();
            dynamicsWorld        = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration)
            {
                Gravity = new TGCVector3(0, -20f, 0).ToBsVector
            };
            #endregion

            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, GameModel.mediaDir + "texturas\\terrain\\NormalMapMar.png");
            //Creamos shapes y bodies.

            #region PISO
            //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);
            dynamicsWorld.AddRigidBody(floorBody);

            //Cargamos objetos de render del framework.
            var floorTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, GameModel.mediaDir + "modelos\\Textures\\Canionero.jpg");
            floorMesh = new TgcPlane(new TGCVector3(0, 500, 0), new TGCVector3(400, 0f, 400), TgcPlane.Orientations.XZplane, floorTexture);
            #endregion

            #region CAJA
            //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(0, 600, 0).ToBsVector;
            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);

            //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);

            #endregion

            #region BOLA
            //Se crea una esfera de tamaño 1 para escalarla luego (en render)
            //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, 200, 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);

            sphereMesh = new TGCSphere(1, texture.Clone(), TGCVector3.Empty);
            //Tgc no crea el vertex buffer hasta invocar a update values.
            sphereMesh.updateValues();

            #endregion

            callback = new MyContactResultCallback(dispatcher, dynamicsWorld, floorBody);// boxBody);
        }