Beispiel #1
0
        public override void Init()
        {
            //FPS Camara
            Camara = new TgcFpsCamera(new Vector3(-140f, 40f, -50f), 200f, 200f);

            //Cargar escena desde archivo ZIP
            var loader = new TgcSceneLoader();

            tgcScene = loader.loadSceneFromZipFile("4toPiso-TgcScene.xml", MediaDir + "4toPiso\\4toPiso.zip",
                                                   MediaDir + "4toPiso\\Extract\\");

            /*
             * //Version para cargar escena desde carpeta descomprimida
             * TgcSceneLoader loader = new TgcSceneLoader();
             * tgcScene = loader.loadSceneFromFile(
             *  this.MediaDir + "4toPiso\\Extract\\4toPiso-TgcScene.xml",
             *  this.MediaDir + "4toPiso\\Extract\\");
             */

            //Modifier para habilitar o deshabilitar FrustumCulling
            Modifiers.addBoolean("culling", "Frustum culling", true);

            //UserVar para contar la cantidad de meshes que se renderizan
            UserVars.addVar("Meshes renderizadas");
        }
Beispiel #2
0
        public override void Init()
        {
            //Cargar 25 cajas formando una matriz
            var loader = new TgcSceneLoader();

            boxes = new List <TgcBox>();
            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device,
                                                   MediaDir + "Texturas\\granito.jpg");
            var boxSize = new Vector3(30, 30, 30);

            for (var i = 0; i < 5; i++)
            {
                for (var j = 0; j < 5; j++)
                {
                    var center = new Vector3((boxSize.X + boxSize.X / 2) * i, (boxSize.Y + boxSize.Y / 2) * j, 0);
                    var box    = TgcBox.fromSize(center, boxSize, texture);
                    boxes.Add(box);
                }
            }

            //Iniciarlizar PickingRay
            pickingRay = new TgcPickingRay();

            Camara = new TgcRotationalCamera(new Vector3(100f, 100f, -250f), 600f);
            //FIXME esta camara deberi ser estatica y no rotacional, ya que sino trae problemas con el picking.

            //Crear caja para marcar en que lugar hubo colision
            collisionPointMesh = TgcBox.fromSize(new Vector3(3, 3, 3), Color.Red);
            selected           = false;

            //UserVars para mostrar en que punto hubo colision
            UserVars.addVar("CollP-X:");
            UserVars.addVar("CollP-Y:");
            UserVars.addVar("CollP-Z:");
        }
Beispiel #3
0
        public override void Init()
        {
            //Path de Heightmap default del terreno y Modifier para cambiarla
            currentHeightmap  = MediaDir + "Heighmaps\\" + "Heightmap3.jpg";
            heightmapModifier = AddTexture("heightmap", currentHeightmap);

            //Modifiers para variar escala del mapa
            currentScaleXZ  = 50f;
            scaleXZModifier = AddFloat("scaleXZ", 0.1f, 100f, currentScaleXZ);
            currentScaleY   = 1.5f;
            scaleYModifier  = AddFloat("scaleY", 0.1f, 10f, currentScaleY);
            createHeightMapMesh(D3DDevice.Instance.Device, currentHeightmap, currentScaleXZ, currentScaleY);

            //Path de Textura default del terreno y Modifier para cambiarla
            currentTexture  = MediaDir + "Heighmaps\\" + "TerrainTexture3.jpg";
            textureModifier = AddTexture("texture", currentTexture);
            loadTerrainTexture(D3DDevice.Instance.Device, currentTexture);

            //Configurar FPS Camara
            Camara = new TgcFpsCamera(new TGCVector3(3200f, 450f, 1500f), Input);

            //UserVars para cantidad de vertices
            UserVars.addVar("Vertices", totalVertices);
            UserVars.addVar("Triangles", totalVertices / 3);
        }
Beispiel #4
0
        public override void Init()
        {
            //Crear esfera
            sphere = new TGCSphere();
            //No recomendamos utilizar AutoTransformEnable, con juegos complejos se pierde el control.
            sphere.AutoTransform = true;
            currentTexture       = null;

            //Modifiers para vararis sus parametros
            baseModifier          = AddEnum("base", typeof(TGCSphere.eBasePoly), TGCSphere.eBasePoly.ICOSAHEDRON);
            inflateModifier       = AddBoolean("inflate", "yes", true);
            levelOfDetailModifier = AddInterval("level of detail", new object[] { 0, 1, 2, 3, 4 }, 2);
            edgesModifier         = AddBoolean("edges", "show", false);
            radiusModifier        = AddFloat("radius", 0, 100, 10);
            positionModifier      = AddVertex3f("position", new TGCVector3(-100, -100, -100), new TGCVector3(100, 100, 100), TGCVector3.Empty);
            rotationModifier      = AddVertex3f("rotation", new TGCVector3(-180, -180, -180), new TGCVector3(180, 180, 180), TGCVector3.Empty);
            useTextureModifier    = AddBoolean("Use texture", "yes", true);
            textureModifier       = AddTexture("texture", MediaDir + "\\Texturas\\madera.jpg");
            offsetModifier        = AddVertex2f("offset", new TGCVector2(-0.5f, -0.5f), new TGCVector2(0.9f, 0.9f), TGCVector2.Zero);
            tilingModifier        = AddVertex2f("tiling", new TGCVector2(0.1f, 0.1f), new TGCVector2(4, 4), TGCVector2.One);

            colorModifier          = AddColor("color", Color.White);
            boundingsphereModifier = AddBoolean("boundingsphere", "show", false);

            UserVars.addVar("Vertices");
            UserVars.addVar("Triangulos");

            Camara = new TgcRotationalCamera(TGCVector3.Empty, 50f, Input);
        }
        public override void Init()
        {
            //Malla default
            var initialMeshFile = MediaDir + "MeshCreator\\Meshes\\Vehiculos\\CamionDeAgua\\CamionDeAgua-TgcScene.xml";

            //Modifiers
            currentScene = null;
            currentPath  = null;
            Modifiers.addFile("Mesh", initialMeshFile, "-TgcScene.xml |*-TgcScene.xml");

            Modifiers.addButton("Reload", "Reload", Reload_ButtonClick);

            currentColor = Color.White;
            Modifiers.addColor("Color", currentColor);

            Modifiers.addBoolean("BoundingBox", "BoundingBox", false);

            currentAlphaBlending = false;
            Modifiers.addBoolean("AlphaBlending", "AlphaBlending", currentAlphaBlending);

            //UserVars
            UserVars.addVar("Name");
            UserVars.addVar("Meshes");
            UserVars.addVar("Textures");
            UserVars.addVar("Triangles");
            UserVars.addVar("Vertices");
            UserVars.addVar("SizeX");
            UserVars.addVar("SizeY");
            UserVars.addVar("SizeZ");
        }
        public override void Init()
        {
            //Crear esfera
            sphere         = new TgcSphere();
            currentTexture = null;

            //Modifiers para vararis sus parametros
            Modifiers.addEnum("base", typeof(TgcSphere.eBasePoly), TgcSphere.eBasePoly.ICOSAHEDRON);
            Modifiers.addBoolean("inflate", "yes", true);
            Modifiers.addInterval("level of detail", new object[] { 0, 1, 2, 3, 4 }, 2);
            Modifiers.addBoolean("edges", "show", false);
            Modifiers.addFloat("radius", 0, 100, 10);
            Modifiers.addVertex3f("position", new Vector3(-100, -100, -100), new Vector3(100, 100, 100),
                                  new Vector3(0, 0, 0));
            Modifiers.addVertex3f("rotation", new Vector3(-180, -180, -180), new Vector3(180, 180, 180),
                                  new Vector3(0, 0, 0));
            Modifiers.addBoolean("Use texture", "yes", true);
            Modifiers.addTexture("texture", MediaDir + "\\Texturas\\madera.jpg");
            Modifiers.addVertex2f("offset", new Vector2(-0.5f, -0.5f), new Vector2(0.9f, 0.9f), new Vector2(0, 0));
            Modifiers.addVertex2f("tiling", new Vector2(0.1f, 0.1f), new Vector2(4, 4), new Vector2(1, 1));

            Modifiers.addColor("color", Color.White);
            Modifiers.addBoolean("boundingsphere", "show", false);

            UserVars.addVar("Vertices");
            UserVars.addVar("Triangulos");

            Camara = new TgcRotationalCamera(new Vector3(), 50f);
        }
Beispiel #7
0
        //mansion spencer 2.0.xml

        public override void Init()
        {
            var loader = new TgcSceneLoader();

            scene = loader.loadSceneFromFile(MediaDir + "Desktop\\mansion spencer 2.0.xml");

            //Descactivar inicialmente a todos los modelos
            scene.setMeshesEnabled(false);

            //Camara = new TgcFpsCamera(new Vector3(0, 0, 0), 800f, 600f, Input);
            // Camara = new TgcCamera();

            var cameraPosition = new Vector3(0, 0, 125);
            var lookAt         = Vector3.Empty;

            Camara.SetCamera(cameraPosition, lookAt);


            //Modifiers
            Modifiers.addBoolean("portalRendering", "PortalRendering", true);
            Modifiers.addBoolean("WireFrame", "WireFrame", false);
            Modifiers.addBoolean("showPortals", "Show Portals", false);

            //throw new NotImplementedException();
            UserVars.addVar("MeshCount");
        }
        public override void Init()
        {
            //Path de Heightmap default del terreno y Modifier para cambiarla
            currentHeightmap = MediaDir + "Heighmaps\\" + "Heightmap1.jpg";
            Modifiers.addTexture("heightmap", currentHeightmap);

            //Modifiers para variar escala del mapa
            currentScaleXZ = 20f;
            Modifiers.addFloat("scaleXZ", 0.1f, 100f, currentScaleXZ);
            currentScaleY = 1.3f;
            Modifiers.addFloat("scaleY", 0.1f, 10f, currentScaleY);
            createHeightMapMesh(D3DDevice.Instance.Device, currentHeightmap, currentScaleXZ, currentScaleY);

            //Path de Textura default del terreno y Modifier para cambiarla
            currentTexture = MediaDir + "Heighmaps\\" + "TerrainTexture1-256x256.jpg";
            Modifiers.addTexture("texture", currentTexture);
            loadTerrainTexture(D3DDevice.Instance.Device, currentTexture);

            //Configurar FPS Camara
            Camara = new TgcFpsCamera(new Vector3(-24.9069f, 386.3114f, 673.7542f), 100f, 100f);

            //UserVars para cantidad de vertices
            UserVars.addVar("Vertices", totalVertices);
            UserVars.addVar("Triangles", totalVertices / 3);
        }
Beispiel #9
0
        public override void Init()
        {
            //Cargar 25 cajas formando una matriz
            var loader = new TgcSceneLoader();

            boxes = new List <TGCBox>();
            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device,
                                                   MediaDir + "Texturas\\granito.jpg");
            var boxSize = new TGCVector3(30, 30, 30);

            for (var i = 0; i < 5; i++)
            {
                for (var j = 0; j < 5; j++)
                {
                    var center = new TGCVector3((boxSize.X + boxSize.X / 2) * i, (boxSize.Y + boxSize.Y / 2) * j, 0);
                    var box    = TGCBox.fromSize(center, boxSize, texture);
                    box.Transform = TGCMatrix.Translation(box.Position);
                    boxes.Add(box);
                }
            }

            //Iniciarlizar PickingRay
            pickingRay = new TgcPickingRay(Input);

            Camara.SetCamera(new TGCVector3(100f, 100f, -500f), new TGCVector3(100f, 100f, -250f));

            //Crear caja para marcar en que lugar hubo colision
            collisionPointMesh = TGCBox.fromSize(new TGCVector3(3, 3, 3), Color.Red);
            selected           = false;

            //UserVars para mostrar en que punto hubo colision
            UserVars.addVar("CollP-X:");
            UserVars.addVar("CollP-Y:");
            UserVars.addVar("CollP-Z:");
        }
        public override void Init()
        {
            //Triangulo 1.
            //Definir array de vertices para el triangulo, del tipo Coordendas (X,Y,Z) + Color
            simpleTriangleData = new CustomVertex.PositionColored[3];

            //Cargar informacion de vertices. Nesitamos 3 vertices para crear un triangulo
            simpleTriangleData[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb());
            simpleTriangleData[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb());
            simpleTriangleData[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb());

            //Cargar variables de usuario con alguna informacion util para ver en pantalla
            UserVars.addVar("Triangle 1 vertices", simpleTriangleData.Length);

            //Triangulo 2.
            //Current texture
            currentTexurePah = MediaDir + "Texturas\\baldosaFacultad.jpg";
            texture          = TextureLoader.FromFile(D3DDevice.Instance.Device, currentTexurePah);

            //Modifiers
            vertex1Modifier   = AddVertex3f("vertex1", new TGCVector3(-3, -3, -3), new TGCVector3(3, 3, 3), new TGCVector3(-1, 0, 0));
            texCoord1Modifier = AddVertex2f("texCoord1", TGCVector2.Zero, TGCVector2.One, new TGCVector2(1, 0));
            color1Modifier    = AddColor("color1", Color.White);

            vertex2Modifier   = AddVertex3f("vertex2", new TGCVector3(-3, -3, -3), new TGCVector3(3, 3, 3), new TGCVector3(1, 0, 0));
            texCoord2Modifier = AddVertex2f("texCoord2", TGCVector2.Zero, TGCVector2.One, new TGCVector2(0, 1));
            color2Modifier    = AddColor("color2", Color.White);

            vertex3Modifier   = AddVertex3f("vertex3", new TGCVector3(-3, -3, -3), new TGCVector3(3, 3, 3), TGCVector3.Up);
            texCoord3Modifier = AddVertex2f("texCoord3", TGCVector2.Zero, TGCVector2.One, TGCVector2.One);
            color3Modifier    = AddColor("color3", Color.White);

            rotationModifier      = AddFloat("rotation", -2, 2f, 0f);
            textureEnableModifier = AddBoolean("TextureEnable", "Con textura", true);
            textureImageModifier  = AddTexture("Texture image", currentTexurePah);

            //Triangulo 3.
            //Crear vertexBuffer
            vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, D3DDevice.Instance.Device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);

            //Cargar informacion de vertices: (X,Y,Z) + Color
            var data = new CustomVertex.PositionColored[3];

            data[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb());
            data[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb());
            data[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb());

            //Almacenar informacion en VertexBuffer
            vertexBuffer.SetData(data, 0, LockFlags.None);

            //User Vars
            UserVars.addVar("Triangle 3 vertices");
            UserVars.setValue("Triangle 3 vertices", data.Length);

            //Configurar camara en rotacion
            Camara = new TgcRotationalCamera(new TGCVector3(0, 0.5f, 0), 7.5f, Input);
        }
Beispiel #11
0
        public override void Init()
        {
            physicsExample = new HelloWorldBullet2();
            physicsExample.Init(this);

            UserVars.addVar("MeshCount");

            Camara = new TgcRotationalCamera(new TGCVector3(0, 20, 0), 100, Input);
        }
Beispiel #12
0
        public override void Init()
        {
            currentMeshFile = MediaDir + "ModelosX" + "\\" + "shampoo.x";

            //cargar mesh
            loadMesh(currentMeshFile);

            //User Vars
            UserVars.addVar("Vertices", mesh.NumberVertices);
            UserVars.addVar("Triangles", mesh.NumberFaces);

            //Modifiers
            Modifiers.addFile("Mesh", currentMeshFile, ".X files|*.x");
        }
        public override void Init()
        {
            //Definir array de vertices para el triangulo, del tipo Coordendas (X,Y,Z) + Color
            data = new CustomVertex.PositionColored[3];

            //Cargar información de vertices. Nesitamos 3 vertices para crear un triángulo
            data[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb());
            data[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb());
            data[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb());

            //Configurar camara en rotacion
            Camara = new TgcRotationalCamera(new Vector3(0, 0.5f, 0), 3f);

            //Cargar variables de usuario con alguna informacion util para ver en pantalla
            UserVars.addVar("Cantida de Vertices", data.Length);
        }
Beispiel #14
0
        public override void Init()
        {
            //En este ejemplo primero cargamos una escena 3D entera.
            var loader = new TgcSceneLoader();

            scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Scenes\\Ciudad\\Ciudad-TgcScene.xml");
            //scene = loader.loadSceneFromFile(MediaDir + "4toPiso\\Extract\\4toPiso-TgcScene.xml");

            /* C:\Users\llain2\Documents\TGC\Viewer\Media\4toPiso\Extract
             * //Luego cargamos otro modelo aparte que va a hacer el objeto que controlamos con el teclado
             * var scene2 =
             *  loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\Hummer\\Hummer-TgcScene.xml");
             *
             * //Solo nos interesa el primer modelo de esta escena (tiene solo uno)
             * mainMesh = scene2.Meshes[0];
             * <<<<<<< HEAD
             * =======
             * mainMesh.AutoTransformEnable = true;
             * >>>>>>> master
             * //Movemos el mesh un poco para arriba. Porque sino choca con el piso todo el tiempo y no se puede mover.
             * mainMesh.Position = new TGCVector3(0, 50, 0);
             * mainMesh.UpdateMeshTransform();*/

            physicsExample = new CubePhysic();
            //physicsExample.setHummer(mainMesh);
            scene.Meshes[0].Position = TGCVector3.Empty;
            physicsExample.setBuildings(scene.Meshes);
            physicsExample.Init(MediaDir);

            //Vamos a utilizar la camara en 3ra persona para que siga al objeto principal a medida que se mueve
            camaraInterna = new TgcThirdPersonCamera(physicsExample.getPositionHummer(), 250, 375);
            Camara        = camaraInterna;

            UserVars.addVar("HummerPositionX");
            UserVars.addVar("HummerPositionY");
            UserVars.addVar("HummerPositionZ");
            UserVars.addVar("HummerBodyPositionX");
            UserVars.addVar("HummerBodyPositionY");
            UserVars.addVar("HummerBodyPositionZ");
        }
Beispiel #15
0
        public override void Init()
        {
            //Crear vertexBuffer
            vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, D3DDevice.Instance.Device,
                                            Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);

            //Cargar informacion de vertices: (X,Y,Z) + Color
            var data = new CustomVertex.PositionColored[3];

            data[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb());
            data[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb());
            data[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb());

            //Almacenar información en VertexBuffer
            vertexBuffer.SetData(data, 0, LockFlags.None);

            //Configurar camara en rotacion
            Camara = new TgcRotationalCamera(new Vector3(0, 0.5f, 0), 3f);

            //User Vars
            UserVars.addVar("Vertices");
            UserVars.setValue("Vertices", data.Length);
        }
Beispiel #16
0
        public override void Init()
        {
            //Cargar escenario con informacion especial exportada de PortalRendering
            var loader = new TgcSceneLoader();

            scene = loader.loadSceneFromFile(MediaDir + "EscenarioPortal\\EscenarioPortal-TgcScene.xml");

            //Descactivar inicialmente a todos los modelos
            scene.setMeshesEnabled(false);

            //Camara en 1ra persona
            Camara = new TgcFpsCamera(TGCVector3.Empty, 800f, 600f, Input);

            //Modifiers
            portalRenderingModifier = AddBoolean("portalRendering", "PortalRendering", true);
            wireFrameModifier       = AddBoolean("WireFrame", "WireFrame", false);
            showPortalsModifier     = AddBoolean("showPortals", "Show Portals", false);

            //UserVars
            UserVars.addVar("MeshCount");

            //Crear portales debug
            scene.PortalRendering.createDebugPortals(Color.Purple);
        }
Beispiel #17
0
        public override void Init()
        {
            //En este ejemplo primero cargamos una escena 3D entera.
            var loader = new TgcSceneLoader();

            scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Scenes\\Ciudad\\Ciudad-TgcScene.xml");

            physicsExample = new CubePhysic();
            //physicsExample.setHummer(mainMesh);
            scene.Meshes[0].Position = TGCVector3.Empty;
            physicsExample.setBuildings(scene.Meshes);
            physicsExample.Init(MediaDir);

            //Vamos a utilizar la camara en 3ra persona para que siga al objeto principal a medida que se mueve
            camaraInterna = new TgcThirdPersonCamera(physicsExample.getPositionHummer(), 250, 375);
            Camara        = camaraInterna;

            UserVars.addVar("HummerPositionX");
            UserVars.addVar("HummerPositionY");
            UserVars.addVar("HummerPositionZ");
            UserVars.addVar("HummerBodyPositionX");
            UserVars.addVar("HummerBodyPositionY");
            UserVars.addVar("HummerBodyPositionZ");
        }
        public override void Init()
        {
            //Crear VertexBuffer
            vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, D3DDevice.Instance.Device,
                                            Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);

            //Cargar informacion de vertices: (X,Y,Z) + Color
            data    = new CustomVertex.PositionColored[3];
            data[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb());
            data[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb());
            data[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb());

            //FPS Camara
            Camara = new TgcFpsCamera(new Vector3(0.5f, 0, -3));

            //User Vars
            UserVars.addVar("Vertices", 0);
            UserVars.addVar("Triangles", 0);

            //Modifiers
            Modifiers.addFloat("translateX", -5, 5f, 0f);
            Modifiers.addFloat("rotationZ", 0, (float)(2.0f * Math.PI), 0f);
            Modifiers.addFloat("ScaleXYZ", 0, 3, 1f);
        }
Beispiel #19
0
        public override void Init()
        {
            //Ideas para generar el terreno para Bullet
            //We are getting a llitle bit crazy xD https://es.wikipedia.org/wiki/Paraboloide
            //Paraboloide Hiperbolico
            // definicion matematica
            //(x / a) ^ 2 - ( y / b) ^ 2 - z = 0.
            //
            //DirectX
            //(x / a) ^ 2 - ( z / b) ^ 2 - y = 0.

            //Paraboloide Circular
            //definicion matematica
            //(x / a) ^ 2 + ( y / b) ^ 2 - z = 0 ; a=b.
            //
            //DirectX
            //(x / a) ^ 2 + ( z / a) ^ 2 - y = 0.

            //Crear vertexBuffer
            int width  = 1200;
            int length = 1200;

            totalVertices = 2 * 3 * (width - 1) * (length - 1);
            vertexBuffer  = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices, D3DDevice.Instance.Device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
            //Almacenar informacion en VertexBuffer

            //Cargar vertices
            var dataIdx = 0;
            var data    = new CustomVertex.PositionTextured[totalVertices];

            TGCVector3 center = TGCVector3.Empty;

            center.X = center.X - width / 2;
            center.Z = center.Z - length / 2;

            int a         = 64;
            int size      = 80;
            int n         = 0;
            int triangles = 0;
            int vertexes  = 0;

            for (var i = 0; i < width - 1; i = i + size)
            {
                for (var j = 0; j < length - 1; j = j + size)
                {
                    //Vertices
                    var v1 = new TGCVector3(center.X + i, center.Y + (FastMath.Pow2((center.X + i) / a) + FastMath.Pow2((center.Z + j) / a)), center.Z + j);
                    var v2 = new TGCVector3(center.X + i, center.Y + (FastMath.Pow2((center.X + i) / a) + FastMath.Pow2((center.Z + j + size) / a)), center.Z + (j + size));
                    var v3 = new TGCVector3(center.X + (i + size), center.Y + (FastMath.Pow2((center.X + i + size) / a) + FastMath.Pow2((center.Z + j) / a)), center.Z + j);
                    var v4 = new TGCVector3(center.X + (i + size), center.Y + (FastMath.Pow2((center.X + i + size) / a) + FastMath.Pow2((center.Z + j + size) / a)), center.Z + (j + size));
                    vertexes = +vertexes + 4;

                    //Coordendas de textura
                    var t1 = TGCVector2.Zero;
                    var t2 = new TGCVector2(0, 1);
                    var t3 = new TGCVector2(1, 0);
                    var t4 = TGCVector2.One;

                    //Cargar triangulo 1
                    data[dataIdx]     = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                    data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                    triangles++;

                    //Cargar triangulo 2
                    data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                    data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);
                    triangles++;

                    dataIdx += 6;
                    n++;
                }
            }

            vertexBuffer.SetData(data, 0, LockFlags.None);

            //Rotar e invertir textura
            var b = (Bitmap)Image.FromFile(MediaDir + "Texturas/pasto.jpg");

            b.RotateFlip(RotateFlipType.Rotate90FlipX);
            terrainTexture = Texture.FromBitmap(D3DDevice.Instance.Device, b, Usage.AutoGenerateMipMap, Pool.Managed);

            //Shader
            effect    = TGCShaders.Instance.VariosShader;
            technique = TGCShaders.T_POSITION_TEXTURED;

            physicsExample = new TrianglePhysics();
            physicsExample.SetTriangleDataVB(data);
            physicsExample.Init(MediaDir);

            UserVars.addVar("Tgccito_Position");

            Camera = new TgcRotationalCamera(new TGCVector3(0, 200, 0), 800, Input);
        }
Beispiel #20
0
        public override void Init()
        {
            //Cargar escenario específico para este ejemplo. Este escenario tiene dos layers: objetos normales y objetos con colisión a nivel de triángulo.
            //La colisión a nivel de triángulos es costosa. Solo debe utilizarse para objetos puntuales (como el piso). Y es recomendable dividirlo en varios
            //meshes (y no hacer un único piso que ocupe todo el escenario)
            var loader = new TgcSceneLoader();

            escenario = loader.loadSceneFromFile(MediaDir + "\\MeshCreator\\Scenes\\Mountains\\Mountains-TgcScene.xml");

            //Cargar personaje con animaciones
            var skeletalLoader = new TgcSkeletalLoader();

            personaje =
                skeletalLoader.loadMeshAndAnimationsFromFile(
                    MediaDir + "SkeletalAnimations\\BasicHuman\\BasicHuman-TgcSkeletalMesh.xml",
                    new[]
            {
                MediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\Walk-TgcSkeletalAnim.xml",
                MediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\StandBy-TgcSkeletalAnim.xml",
                MediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\Jump-TgcSkeletalAnim.xml"
            });

            //Configurar animacion inicial
            personaje.playAnimation("StandBy", true);
            //Escalarlo porque es muy grande
            personaje.Position = new Vector3(0, 1000, -150);
            //Rotarlo 180° porque esta mirando para el otro lado
            personaje.rotateY(Geometry.DegreeToRadian(180f));

            //BoundingSphere que va a usar el personaje
            personaje.AutoUpdateBoundingBox = false;
            characterElipsoid = new TgcElipsoid(personaje.BoundingBox.calculateBoxCenter() + new Vector3(0, 0, 0),
                                                new Vector3(12, 28, 12));
            jumping = false;

            //Almacenar volumenes de colision del escenario
            objetosColisionables.Clear();
            foreach (var mesh in escenario.Meshes)
            {
                //Los objetos del layer "TriangleCollision" son colisiones a nivel de triangulo
                if (mesh.Layer == "TriangleCollision")
                {
                    objetosColisionables.Add(TriangleMeshCollider.fromMesh(mesh));
                }
                //El resto de los objetos son colisiones de BoundingBox. Las colisiones a nivel de triangulo son muy costosas asi que deben utilizarse solo
                //donde es extremadamente necesario (por ejemplo en el piso). El resto se simplifica con un BoundingBox
                else
                {
                    objetosColisionables.Add(BoundingBoxCollider.fromBoundingBox(mesh.BoundingBox));
                }
            }

            //Crear manejador de colisiones
            collisionManager = new ElipsoidCollisionManager();
            collisionManager.GravityEnabled = true;

            //Crear linea para mostrar la direccion del movimiento del personaje
            directionArrow           = new TgcArrow();
            directionArrow.BodyColor = Color.Red;
            directionArrow.HeadColor = Color.Green;
            directionArrow.Thickness = 0.4f;
            directionArrow.HeadSize  = new Vector2(5, 10);

            //Linea para normal de colision
            collisionNormalArrow           = new TgcArrow();
            collisionNormalArrow.BodyColor = Color.Blue;
            collisionNormalArrow.HeadColor = Color.Yellow;
            collisionNormalArrow.Thickness = 0.4f;
            collisionNormalArrow.HeadSize  = new Vector2(2, 5);

            //Caja para marcar punto de colision
            collisionPoint = TgcBox.fromSize(new Vector3(4, 4, 4), Color.Red);

            //Configurar camara en Tercer Persona
            camaraInterna = new TgcThirdPersonCamera(personaje.Position, new Vector3(0, 45, 0), 20, -120);
            Camara        = camaraInterna;

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(10000, 10000, 10000);
            var texturesPath = MediaDir + "Texturas\\Quake\\SkyBox3\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "Up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "Down.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "Left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "Right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "Back.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "Front.jpg");
            skyBox.InitSkyBox();

            //Modifier para ver BoundingBox
            Modifiers.addBoolean("Collisions", "Collisions", true);
            Modifiers.addBoolean("showBoundingBox", "Bouding Box", true);

            //Modifiers para desplazamiento del personaje
            Modifiers.addFloat("VelocidadCaminar", 0, 20, 2);
            Modifiers.addFloat("VelocidadRotacion", 1f, 360f, 150f);
            Modifiers.addBoolean("HabilitarGravedad", "Habilitar Gravedad", true);
            Modifiers.addVertex3f("Gravedad", new Vector3(-50, -50, -50), new Vector3(50, 50, 50),
                                  new Vector3(0, -4, 0));
            Modifiers.addFloat("SlideFactor", 0f, 2f, 1f);
            Modifiers.addFloat("Pendiente", 0f, 1f, 0.72f);
            Modifiers.addFloat("VelocidadSalto", 0f, 50f, 10f);
            Modifiers.addFloat("TiempoSalto", 0f, 2f, 0.5f);

            UserVars.addVar("Movement");
        }
        public override void Init()
        {
            //Cargar escenario específico para este ejemplo
            var loader = new TgcSceneLoader();

            escenario = loader.loadSceneFromFile(MediaDir + "PatioDeJuegos\\PatioDeJuegos-TgcScene.xml");

            //Cargar personaje con animaciones
            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);
            //Escalarlo porque es muy grande
            personaje.Position = new TGCVector3(0, 500, -100);
            //Rotarlo 180° porque esta mirando para el otro lado
            personaje.RotateY(Geometry.DegreeToRadian(180f));
            //Escalamos el personaje ya que sino la escalera es demaciado grande.
            personaje.Scale = new TGCVector3(1.5f, 1.5f, 1.5f);

            characterSphere = new TgcBoundingSphere(personaje.BoundingBox.calculateBoxCenter(), personaje.BoundingBox.calculateBoxRadius());

            //Almacenar volumenes de colision del escenario
            objetosColisionables.Clear();
            foreach (var mesh in escenario.Meshes)
            {
                objetosColisionables.Add(mesh.BoundingBox);
            }

            //Crear linea para mostrar la direccion del movimiento del personaje
            directionArrow           = new TgcArrow();
            directionArrow.BodyColor = Color.Red;
            directionArrow.HeadColor = Color.Green;
            directionArrow.Thickness = 1;
            directionArrow.HeadSize  = new TGCVector2(10, 20);

            //Crear manejador de colisiones
            collisionManager = new SphereCollisionManager();
            collisionManager.GravityEnabled = true;

            //Configurar camara en Tercer Persona
            camaraInterna = new TgcThirdPersonCamera(personaje.Position, new TGCVector3(0, 100, 0), 100, -400);
            Camara        = camaraInterna;

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = TGCVector3.Empty;
            skyBox.Size   = new TGCVector3(10000, 10000, 10000);
            var texturesPath = MediaDir + "Texturas\\Quake\\SkyBox3\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "Up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "Down.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "Left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "Right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "Back.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "Front.jpg");
            skyBox.Init();

            //Modifier para ver BoundingBox
            showBoundingBoxModifier = AddBoolean("showBoundingBox", "Bouding Box", true);

            //Modifiers para desplazamiento del personaje
            velocidadCaminarModifier  = AddFloat("VelocidadCaminar", 0, 20, 10);
            velocidadRotacionModifier = AddFloat("VelocidadRotacion", 1f, 360f, 150f);
            habilitarGravedadModifier = AddBoolean("HabilitarGravedad", "Habilitar Gravedad", true);
            gravedadModifier          = AddVertex3f("Gravedad", new TGCVector3(-50, -50, -50), new TGCVector3(50, 50, 50), new TGCVector3(0, -10, 0));
            slideFactorModifier       = AddFloat("SlideFactor", 1f, 2f, 1.3f);

            UserVars.addVar("Movement");
        }
        public override void Init()
        {
            //Cargar escenario específico para este ejemplo
            var loader = new TgcSceneLoader();

            escenario = loader.loadSceneFromFile(MediaDir + "\\MeshCreator\\Scenes\\Mountains\\Mountains-TgcScene.xml");

            //Cargar personaje con animaciones
            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")
            });

            //Se utiliza autotransform, aunque este es un claro ejemplo de que no se debe usar autotransform,
            //hay muchas operaciones y la mayoria las maneja el manager de colisiones, con lo cual se esta
            //perdiendo el control de las transformaciones del personaje.
            personaje.AutoTransformEnable = true;
            //Configurar animacion inicial
            personaje.playAnimation("Parado", true);
            //Escalarlo porque es muy grande
            personaje.Position = new Vector3(0, 2500, -150);
            //Rotarlo 180° porque esta mirando para el otro lado
            personaje.rotateY(Geometry.DegreeToRadian(180f));
            //escalamos el personaje porque es muy grande.
            personaje.Scale = new Vector3(0.5f, 0.5f, 0.5f);

            //BoundingSphere que va a usar el personaje
            personaje.AutoUpdateBoundingBox = false;
            characterSphere = new TgcBoundingSphere(personaje.BoundingBox.calculateBoxCenter(),
                                                    personaje.BoundingBox.calculateBoxRadius());
            jumping = false;

            //Almacenar volumenes de colision del escenario
            objetosColisionables.Clear();
            foreach (var mesh in escenario.Meshes)
            {
                //Los objetos del layer "TriangleCollision" son colisiones a nivel de triangulo
                if (mesh.Layer == "TriangleCollision")
                {
                    objetosColisionables.Add(TriangleMeshCollider.fromMesh(mesh));
                }
                //El resto de los objetos son colisiones de BoundingBox
                else
                {
                    objetosColisionables.Add(BoundingBoxCollider.fromBoundingBox(mesh.BoundingBox));
                }
            }

            //Crear linea para mostrar la direccion del movimiento del personaje
            directionArrow           = new TgcArrow();
            directionArrow.BodyColor = Color.Red;
            directionArrow.HeadColor = Color.Green;
            directionArrow.Thickness = 0.4f;
            directionArrow.HeadSize  = new Vector2(5, 10);

            //Linea para normal de colision
            collisionNormalArrow           = new TgcArrow();
            collisionNormalArrow.BodyColor = Color.Blue;
            collisionNormalArrow.HeadColor = Color.Yellow;
            collisionNormalArrow.Thickness = 0.4f;
            collisionNormalArrow.HeadSize  = new Vector2(2, 5);

            //Caja para marcar punto de colision
            collisionPoint = TgcBox.fromSize(new Vector3(4, 4, 4), Color.Red);
            collisionPoint.AutoTransformEnable = true;

            //Crear manejador de colisiones
            collisionManager = new SphereTriangleCollisionManager();
            collisionManager.GravityEnabled = true;

            //Configurar camara en Tercer Persona
            camaraInterna = new TgcThirdPersonCamera(personaje.Position, new Vector3(0, 45, 0), 35, -150);
            Camara        = camaraInterna;

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(10000, 10000, 10000);
            var texturesPath = MediaDir + "Texturas\\Quake\\SkyBox3\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "Up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "Down.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "Left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "Right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "Back.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "Front.jpg");
            skyBox.Init();

            //Modifier para ver BoundingBox
            Modifiers.addBoolean("Collisions", "Collisions", true);
            Modifiers.addBoolean("showBoundingBox", "Bouding Box", true);

            //Modifiers para desplazamiento del personaje
            Modifiers.addFloat("VelocidadCaminar", 0, 10, 2);
            Modifiers.addFloat("VelocidadRotacion", 1f, 360f, 150f);
            Modifiers.addBoolean("HabilitarGravedad", "Habilitar Gravedad", true);
            Modifiers.addVertex3f("Gravedad", new Vector3(-5, -10, -5), new Vector3(5, 5, 5),
                                  new Vector3(0, -6, 0));
            Modifiers.addFloat("SlideFactor", 0f, 2f, 1f);
            Modifiers.addFloat("Pendiente", 0f, 1f, 0.7f);
            Modifiers.addFloat("VelocidadSalto", 0f, 10f, 2f);
            Modifiers.addFloat("TiempoSalto", 0f, 2f, 0.5f);

            UserVars.addVar("Movement");
            UserVars.addVar("ySign");
        }