public override void init() { Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice; //Cargar escenario específico para este ejemplo TgcSceneLoader loader = new TgcSceneLoader(); escenario = loader.loadSceneFromFile(GuiController.Instance.ExamplesDir + "\\Collision\\SphereCollision\\PatioDeJuegos\\PatioDeJuegos-TgcScene.xml"); //Cargar personaje con animaciones TgcSkeletalLoader skeletalLoader = new TgcSkeletalLoader(); personaje = skeletalLoader.loadMeshAndAnimationsFromFile( GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Robot-TgcSkeletalMesh.xml", GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\", new string[] { GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Caminando-TgcSkeletalAnim.xml", GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Parado-TgcSkeletalAnim.xml", }); //Le cambiamos la textura para diferenciarlo un poco personaje.changeDiffuseMaps(new TgcTexture[] { TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\Textures\\" + "uvwGreen.jpg") }); //Configurar animacion inicial personaje.playAnimation("Parado", true); //Escalarlo porque es muy grande personaje.Position = new Vector3(0,500,-100); //Rotarlo 180° porque esta mirando para el otro lado personaje.rotateY(Geometry.DegreeToRadian(180f)); //BoundingSphere que va a usar el personaje personaje.AutoUpdateBoundingBox = false; characterSphere = new TgcBoundingSphere(personaje.BoundingBox.calculateBoxCenter(), personaje.BoundingBox.calculateBoxRadius()); //Almacenar volumenes de colision del escenario objetosColisionables.Clear(); foreach (TgcMesh 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 Vector2(10, 20); //Crear manejador de colisiones collisionManager = new SphereCollisionManager(); collisionManager.GravityEnabled = true; //Configurar camara en Tercer Persona GuiController.Instance.ThirdPersonCamera.Enable = true; GuiController.Instance.ThirdPersonCamera.setCamera(personaje.Position, 100, -400); GuiController.Instance.ThirdPersonCamera.TargetDisplacement = new Vector3(0, 100, 0); //Crear SkyBox skyBox = new TgcSkyBox(); skyBox.Center = new Vector3(0, 0, 0); skyBox.Size = new Vector3(10000, 10000, 10000); string texturesPath = GuiController.Instance.ExamplesMediaDir + "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.updateValues(); //Modifier para ver BoundingBox GuiController.Instance.Modifiers.addBoolean("showBoundingBox", "Bouding Box", true); //Modifiers para desplazamiento del personaje GuiController.Instance.Modifiers.addFloat("VelocidadCaminar", 0, 100, 16); GuiController.Instance.Modifiers.addFloat("VelocidadRotacion", 1f, 360f, 150f); GuiController.Instance.Modifiers.addBoolean("HabilitarGravedad", "Habilitar Gravedad", true); GuiController.Instance.Modifiers.addVertex3f("Gravedad", new Vector3(-50, -50, -50), new Vector3(50, 50, 50), new Vector3(0, -10, 0)); GuiController.Instance.Modifiers.addFloat("SlideFactor", 1f, 2f, 1.3f); GuiController.Instance.UserVars.addVar("Movement"); }
public override void init() { Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice; //Crear piso TgcTexture pisoTexture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\tierra.jpg"); piso = TgcBox.fromSize(new Vector3(0,-60,0), new Vector3(1000, 5, 1000), pisoTexture); //Cargar obstaculos y posicionarlos. Los obstáculos se crean con TgcBox en lugar de cargar un modelo. obstaculos = new List<TgcBox>(); TgcBox obstaculo; //Obstaculo 1 obstaculo = TgcBox.fromSize( new Vector3(-100, 0, 0), new Vector3(80, 150, 80), TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\baldosaFacultad.jpg")); obstaculos.Add(obstaculo); //Obstaculo 2 obstaculo = TgcBox.fromSize( new Vector3(50, 0, 200), new Vector3(80, 300, 80), TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\madera.jpg")); obstaculos.Add(obstaculo); //Obstaculo 3 obstaculo = TgcBox.fromSize( new Vector3(300, 0, 100), new Vector3(80, 100, 150), TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\granito.jpg")); obstaculos.Add(obstaculo); //Cargar personaje con animaciones TgcSkeletalLoader skeletalLoader = new TgcSkeletalLoader(); personaje = skeletalLoader.loadMeshAndAnimationsFromFile( GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Robot-TgcSkeletalMesh.xml", GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\", new string[] { GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Caminando-TgcSkeletalAnim.xml", GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Parado-TgcSkeletalAnim.xml", }); //Le cambiamos la textura para diferenciarlo un poco personaje.changeDiffuseMaps(new TgcTexture[] { TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\Textures\\" + "uvwGreen.jpg") }); //Configurar animacion inicial personaje.playAnimation("Parado", true); //Escalarlo porque es muy grande personaje.Position = new Vector3(0,-45,0); personaje.Scale = new Vector3(0.75f, 0.75f, 0.75f); //Rotarlo 180° porque esta mirando para el otro lado personaje.rotateY(Geometry.DegreeToRadian(180f)); //Configurar camara en Tercer Persona GuiController.Instance.ThirdPersonCamera.Enable = true; GuiController.Instance.ThirdPersonCamera.setCamera(personaje.Position, 200, -300); //Modifier para ver BoundingBox GuiController.Instance.Modifiers.addBoolean("showBoundingBox", "Bouding Box", false); //Modifiers para desplazamiento del personaje GuiController.Instance.Modifiers.addFloat("VelocidadCaminar", 1f, 400f, 250f); GuiController.Instance.Modifiers.addFloat("VelocidadRotacion", 1f, 360f, 120f); }