Esempio n. 1
0
        public override void Init()
        {
            var d3dDevice = D3DDevice.Instance.Device;

            efecto = TgcShaders.loadEffect(GameModel.shadersDir + "shaderPlanta.fx");

            #region configurarObjetos
            helicoptero          = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\heliX-TgcScene.xml").Meshes[0];
            helicoptero.Scale    = new TGCVector3(10.5f, 10.5f, 10.5f);
            helicoptero.Position = new TGCVector3(5000f, 200f, 500f);
            helicoptero.RotateY(90);
            helicoptero.Effect    = efecto;
            helicoptero.Technique = "RenderScene";

            objetos.Add(helicoptero);

            helice          = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\heliceCero-TgcScene.xml").Meshes[0];
            helice.Scale    = new TGCVector3(10.5f, 10.5f, 10.5f);
            helice.Position = new TGCVector3(5000f, 200f, 420f);
            helice.RotateY(90);
            helice.Effect    = efecto;
            helice.Technique = "RenderScene";

            objetos.Add(helice);
            #endregion
        }
Esempio n. 2
0
        public void update(Core.Input.TgcD3dInput input)
        {
            var moveVector = TGCVector3.Empty;

            if (input.keyDown(Key.B))
            {
                moveVector += new TGCVector3(0, 7, 0);
                if (!volar)
                {
                    despegar();
                }
            }
            if (input.keyDown(Key.N))
            {
                moveVector += new TGCVector3(-17, 0, 0);
            }
            if (input.keyDown(Key.M))
            {
                moveVector += new TGCVector3(0, 0, -17);
            }

            helicoptero.Position = helicoptero.Position + moveVector;
            helice.Position      = helicoptero.Position + moveVector;

            if (volar)
            {
                helice.RotateY(1);
            }
        }
Esempio n. 3
0
        //TGCSphere vida;  //si uso sphere funciona, con mesh no

        public Vida( )
        {
            body = FactoryBody.crearBodyEsfericoEstatico(new TGCVector3(1300f, 360f, 1500f), radio);

            #region configurarEfecto
            efecto = TgcShaders.loadEffect(GameModel.shadersDir + "shaderPlanta.fx");
            #endregion

            #region configurarObjeto

            vida           = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\vida-TgcScene.xml").Meshes[0];
            vida.Scale     = new TGCVector3(20.5f, 10.5f, 20.5f);
            vida.Effect    = efecto;
            vida.Technique = "RenderScene";
            vida.RotateY(90);
            //vida.Transform = new TGCMatrix(body.InterpolationWorldTransform);
            //vida.UpdateMeshTransform();

            //var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, GameModel.mediaDir + "texturas\\terrain\\NormalMapMar.png");
            //vida = new TGCSphere(1, texture.Clone(), TGCVector3.Empty);
            ////Tgc no crea el vertex buffer hasta invocar a update values.
            //vida.updateValues();

            objetos.Add(vida);
            //glowObjects.Add(vida);

            #endregion
        }
        public SuperCanion(TGCVector3 posicion, GameLogic logica, Plataforma plataforma)
        {
            base.Init(logica, plataforma);

            #region configurarObjeto
            float factorEscalado = 20.0f;
            canion1          = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\CANIONERO-TgcScene.xml").Meshes[0];
            canion1.Scale    = new TGCVector3(factorEscalado, factorEscalado, factorEscalado);
            canion1.Position = new TGCVector3(posicion.X - 21, posicion.Y + 40, posicion.Z + 15);
            canion1.RotateX(14);
            canion1.RotateY(18);
            canion1.Effect    = efecto;
            canion1.Technique = "RenderScene";

            canion2          = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\CANIONERO-TgcScene.xml").Meshes[0];
            canion2.Scale    = new TGCVector3(factorEscalado, factorEscalado, factorEscalado);
            canion2.Position = new TGCVector3(posicion.X + 21, posicion.Y + 40, posicion.Z + 15);
            canion2.RotateX(-14);
            canion2.RotateY(48);
            canion2.Effect    = efecto;
            canion2.Technique = "RenderScene";


            tallo          = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\SuperCanion-TgcScene.xml").Meshes[0];
            tallo.Scale    = new TGCVector3(factorEscalado * 0.75f, factorEscalado * 0.75f, factorEscalado * 0.75f);
            tallo.Position = new TGCVector3(posicion.X, posicion.Y - 50, posicion.Z);
            tallo.RotateY(4);
            tallo.Effect    = efecto;
            tallo.Technique = "RenderScene";

            #endregion

            PostProcess.agregarPostProcessObject(this);
        }
Esempio n. 5
0
        public void RotarMesh(Personaje personaje)
        {
            if (!this.lookAt.Equals(personaje.getPosition()))
            {
                float diferenciaEnX = personaje.getPosition().X - ghost.Position.X;
                float diferenciaEnZ = personaje.getPosition().Z - ghost.Position.Z;

                float anguloRotacion = (float)Math.Atan(diferenciaEnX / diferenciaEnZ);

                if (diferenciaEnX < 0 && diferenciaEnZ < 0)
                {
                    //3er Cuadrante
                    anguloRotacion = (float)Math.PI + anguloRotacion;
                }
                else if (diferenciaEnX > 0 && diferenciaEnZ > 0)
                {
                    //1er Cuadrante
                }
                else if (diferenciaEnX > 0 && diferenciaEnZ < 0)
                {
                    //4to Cuadrante
                    anguloRotacion = 2 * (float)Math.PI - anguloRotacion;
                }
                else
                {
                    //2do Cuadrante
                    anguloRotacion = (float)Math.PI - anguloRotacion;
                }

                ghost.RotateY(anguloRotacion);

                this.lookAt = personaje.getPosition();
            }
        }
Esempio n. 6
0
        public override void Render()
        {
            //BackgroundColor
            D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            BeginScene();
            ClearTextures();

            //Cargar variables shader
            mesh.Effect.SetValue("ambientColor", ColorValue.FromColor(Color.Gray));
            mesh.Effect.SetValue("diffuseColor", ColorValue.FromColor(Color.LightBlue));
            mesh.Effect.SetValue("specularColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("specularExp", 10f);
            mesh.Effect.SetValue("lightPosition", lightPos);
            mesh.Effect.SetValue("eyePosition", TGCVector3.Vector3ToFloat4Array(Camara.Position));

            mesh.RotateY(-ElapsedTime / 2);
            mesh.Transform = TGCMatrix.Scaling(mesh.Scale)
                             * TGCMatrix.RotationYawPitchRoll(mesh.Rotation.Y, mesh.Rotation.X, mesh.Rotation.Z)
                             * TGCMatrix.Translation(mesh.Position);
            mesh.Render();

            textHelp.render();

            //Help
            if (Input.keyPressed(Key.H))
            {
                helpForm.ShowDialog();
            }

            PostRender();
        }
        public Girasol(TGCVector3 posicion, GameLogic logica, Plataforma plataforma)
        {
            base.Init(logica, plataforma);

            #region configurarObjeto

            float factorEscalado = 30.0f;
            girasol          = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\Girasol-TgcScene.xml").Meshes[0];
            girasol.Scale    = new TGCVector3(factorEscalado, factorEscalado, factorEscalado);
            girasol.Position = new TGCVector3(posicion.X - 8, posicion.Y + 35, posicion.Z - 10);
            girasol.RotateX(60);
            girasol.RotateY(90);
            girasol.RotateZ(90);
            girasol.Effect    = efecto;
            girasol.Technique = "RenderScene";

            tallo           = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\PlantaFinal-TgcScene.xml").Meshes[0];
            tallo.Scale     = new TGCVector3(factorEscalado * 0.5f, factorEscalado * 0.5f, factorEscalado * 0.5f);
            tallo.Position  = new TGCVector3(posicion.X, posicion.Y - 50, posicion.Z);  // new TGCVector3(500f, 200f, 1500f);
            tallo.Effect    = efecto;
            tallo.Technique = "RenderScene";

            #endregion

            #region manejarTiempo
            time           = new Timer(INTERVALO);
            time.Elapsed  += OnTimedEvent;
            time.AutoReset = true;
            time.Enabled   = true;
            #endregion

            PostProcess.agregarPostProcessObject(this);
        }
Esempio n. 8
0
        public override void Init()
        {
            //El framework posee la clase TgcSceneLoader que permite cargar modelos 3D.
            //Estos modelos 3D están almacenados en un archivo XML llamado TgcScene.xml.
            //Este archivo es un formato a medida hecho para el framework. Y puede ser creado desde herramientas de
            //diseño como 3Ds MAX (exportando a traves de un plugin) o con el editor MeshCreator que viene con el framework.
            //El framework viene con varios modelos 3D incluidos en la carpeta: TgcViewer\Examples\Media\MeshCreator\Meshes.
            //El formato especifica una escena, representada por la clase TgcScene. Una escena puede estar compuesta por varios
            //modelos 3D. Cada modelo se representa con la clase TgcMesh.
            //En este ejemplo vamos a cargar una escena con un único modelo.
            var loader = new TgcSceneLoader();

            //De toda la escena solo nos interesa guardarnos el primer modelo (el único que hay en este caso).
            mesh = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\Hummer\\Hummer-TgcScene.xml").Meshes[0];
            mesh.AutoTransform = true;
            mesh.RotateY(FastMath.QUARTER_PI);
            mesh.Move(new TGCVector3(100, 40, -200));
            //mesh.Transform = TGCMatrix.RotationY(FastMath.QUARTER_PI) * TGCMatrix.Translation(100,40,-200);

            //En este ejemplo no cargamos un solo modelo 3D sino una escena completa, compuesta por varios modelos.
            //El framework posee varias escenas ya hechas en la carpeta TgcViewer\Examples\Media\MeshCreator\Scenes.
            scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Scenes\\Iglesia\\Iglesia-TgcScene.xml");

            //Hacemos que la cámara esté centrada sobre el mesh.
            Camara = new TgcRotationalCamera(mesh.BoundingBox.calculateBoxCenter(),
                                             mesh.BoundingBox.calculateBoxRadius() * 2, Input);
        }
Esempio n. 9
0
 public void cargarDecorativo(TgcMesh unDecorativo, TgcScene unaEscena, TGCVector3 posicion, TGCVector3 escala, float rotacion)
 {
     unDecorativo          = unaEscena.Meshes[0];
     unDecorativo.Position = posicion;
     unDecorativo.Scale    = escala;
     unDecorativo.RotateY(rotacion);
     decorativos.Add(unDecorativo);
     aabbDeDecorativos.Add(unDecorativo.BoundingBox);
 }
Esempio n. 10
0
        public void Render(GameModel gameModel)
        {
            // Mini Viewport
            device.Viewport = view;

            var posOriginal = mesh.Position;
            var cam         = (TgcThirdPersonCamera)gameModel.Camara;

            time += gameModel.ElapsedTime;
            var asd = gameModel.Camara.LookAt - gameModel.Camara.Position;

            asd.Normalize();
            asd *= 4.85f;

            if (player1.SelectedWeapon != null)
            {
                mesh.Position = gameModel.Camara.Position + asd;
                mesh.Rotation = new TGCVector3(0, cam.RotationY, 0);
                mesh.RotateY(FastMath.Cos(time * 3) * 1.3f);
                mesh.Render();
            }

            device.Viewport = original_view;

            // Dibujar los Sprites
            drawer2D.BeginDrawSprite();
            drawer2D.DrawSprite(hudSprites);
            drawer2D.DrawSprite(healthBar);
            drawer2D.DrawSprite(specialBar);
            drawer2D.EndDrawSprite();

            // Renderizar Texto
            if (speed.Text.Contains("-"))
            {
                speed.Color = Color.IndianRed;
            }
            else
            {
                speed.Color = Color.Green;
            }

            speed.render();
            km.render();
            weaponName.render();
            ammoQuantity.render();
            reloj.render();

            if (player1.turbo)
            {
                turbo.render();
            }
        }
Esempio n. 11
0
        public Bug(String MediaDir)
        {
            meshMounstroMiniatura = new TgcSceneLoader().loadSceneFromFile(MediaDir + @"monstruo-TgcScene.xml").Meshes[0];
            mesh = new TgcSceneLoader().loadSceneFromFile(MediaDir + @"Buggy-TgcScene.xml").Meshes[0];

            piezaAsociada = new Pieza(2, "Pieza 2", MediaDir + "\\2D\\windows\\windows_2.png", null);
            pistaAsociada = new Pista(null, MediaDir + "\\2D\\pista_sudo.png", null);

            mesh.Position  = new TGCVector3(-450, 40, 2500);
            mesh.Transform = TGCMatrix.Translation(-450, 40, 2500);
            meshMounstroMiniatura.Position  = new TGCVector3(-440, 40, 2400);
            meshMounstroMiniatura.Transform = TGCMatrix.Translation(-440, 40, 2400);
            meshMounstroMiniatura.RotateY(FastMath.PI);
            meshMounstroMiniatura.Scale = new TGCVector3(0.1f, 0.1f, 0.1f);
            posicionInicial             = mesh.Position;
            posicionInicialMounstro     = meshMounstroMiniatura.Position;

            interactuable = true;
            usado         = false;
        }
        public Nuez(TGCVector3 posicion, GameLogic logica, Plataforma plataforma)
        {
            base.Init(logica, plataforma);

            #region configurarObjeto

            float factorEscalado = 160.0f;

            nuez          = new TgcSceneLoader().loadSceneFromFile(GameModel.mediaDir + "modelos\\nuez-TgcScene.xml").Meshes[0];
            nuez.Scale    = new TGCVector3(factorEscalado * 0.5f, factorEscalado * 0.5f, factorEscalado * 0.5f);
            nuez.Position = new TGCVector3(posicion.X, posicion.Y + 60, posicion.Z + 5);
            nuez.RotateZ(1.5f);
            nuez.RotateY(90);
            nuez.Effect    = efecto;
            nuez.Technique = "RenderScene";

            #endregion

            nivelResistencia = 10000;
            PostProcess.agregarPostProcessObject(this);
        }
Esempio n. 13
0
        public override void Render()
        {
            PreRender();

            //Calcular proxima posicion de personaje segun Input
            var   moveForward = 0f;
            float rotate      = 0;
            var   moving      = false;
            var   rotating    = false;

            //Adelante
            if (Input.keyDown(Key.W))
            {
                moveForward = -VELODICAD_CAMINAR;
                moving      = true;
            }

            //Atras
            if (Input.keyDown(Key.S))
            {
                moveForward = VELODICAD_CAMINAR;
                moving      = true;
            }

            //Derecha
            if (Input.keyDown(Key.D))
            {
                rotate   = VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Izquierda
            if (Input.keyDown(Key.A))
            {
                rotate   = -VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Si hubo rotacion
            if (rotating)
            {
                //Rotar personaje y la camara, hay que multiplicarlo por el tiempo transcurrido para no atarse a la velocidad el hardware
                var rotAngle = Geometry.DegreeToRadian(rotate * ElapsedTime);
                personaje.RotateY(rotAngle);
                camaraInterna.rotateY(rotAngle);
            }

            //Si hubo desplazamiento
            if (moving)
            {
                //Aplicar movimiento hacia adelante o atras segun la orientacion actual del Mesh
                var lastPos = personaje.Position;
                var moveF   = moveForward * ElapsedTime;
                var z       = (float)Math.Cos(personaje.Rotation.Y) * moveF;
                var x       = (float)Math.Sin(personaje.Rotation.Y) * moveF;

                personaje.Position += new TGCVector3(x, 0, z);

                //Detectar colisiones
                var collide = false;
                foreach (var obstaculo in obstaculos)
                {
                    var result = TgcCollisionUtils.classifyBoxBox(personaje.BoundingBox, obstaculo.BoundingBox);
                    if (result == TgcCollisionUtils.BoxBoxResult.Adentro ||
                        result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                    {
                        collide = true;
                        break;
                    }
                }

                //Si hubo colision, restaurar la posicion anterior
                if (collide)
                {
                    personaje.Position = lastPos;
                }
            }

            //Hacer que la camara siga al personaje en su nueva posicion
            camaraInterna.Target = personaje.Position;

            //Render piso
            piso.Render();

            //Render obstaculos
            foreach (var obstaculo in obstaculos)
            {
                obstaculo.Render();
            }

            //Render personaje
            personaje.Transform = TGCMatrix.Scaling(personaje.Scale)
                                  * TGCMatrix.RotationYawPitchRoll(personaje.Rotation.Y, personaje.Rotation.X, personaje.Rotation.Z)
                                  * TGCMatrix.Translation(personaje.Position);

            personaje.Render();

            PostRender();
        }
Esempio n. 14
0
        /// <summary>
        ///     Renderizar toda la parte cliente, con el manejo de input
        /// </summary>
        private void renderClient()
        {
            //Calcular proxima posicion de personaje segun Input
            var   moveForward = 0f;
            float rotate      = 0;
            var   moving      = false;
            var   rotating    = false;

            //Adelante
            if (Input.keyDown(Key.W))
            {
                moveForward = -VELODICAD_CAMINAR;
                moving      = true;
            }

            //Atras
            if (Input.keyDown(Key.S))
            {
                moveForward = VELODICAD_CAMINAR;
                moving      = true;
            }

            //Derecha
            if (Input.keyDown(Key.D))
            {
                rotate   = VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Izquierda
            if (Input.keyDown(Key.A))
            {
                rotate   = -VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Si hubo rotacion
            if (rotating)
            {
                meshPrincipal.RotateY(Geometry.DegreeToRadian(rotate * ElapsedTime));
                this.camaraInterna.rotateY(rotate);
            }

            //Si hubo desplazamiento
            if (moving)
            {
                meshPrincipal.MoveOrientedY(moveForward * ElapsedTime);
            }

            //Hacer que la camara siga al personaje en su nueva posicion
            this.camaraInterna.Target = meshPrincipal.Position;

            //Render piso
            piso.Render();

            //Renderizar meshPrincipal
            if (meshPrincipal != null)
            {
                meshPrincipal.Render();
            }

            //Renderizar otrosMeshes
            foreach (var entry in otrosMeshes)
            {
                entry.Value.Render();
            }
        }
 public override void Update(TgcD3dInput Input)
 {
     efecto.SetValue("_Time", GameModel.time);
     haloFuego.RotateY(GameModel.time);
 }
Esempio n. 16
0
        public void Update(TgcD3dInput input, TgcMesh monstruo, TgcMesh monstruoSil)
        {
            monstruoMesh    = monstruo;
            monstruoSilueta = monstruoSil;

            dynamicsWorld.StepSimulation(1 / 60f, 100);

            #region Comportamiento

            if (input.keyDown(Key.Space) && ModoCreativo)
            {
                //Activa el comportamiento de la simulacion fisica para la capsula
                personajeBody.ActivationState = ActivationState.ActiveTag;
                personajeBody.AngularVelocity = TGCVector3.Empty.ToBulletVector3();
                personajeBody.ApplyCentralImpulse(strength * 10 * (new TGCVector3(0, 1, 0)).ToBulletVector3());
            }

            if (input.keyDown(Key.W))
            {
                //Activa el comportamiento de la simulacion fisica para la capsula
                personajeBody.ActivationState = ActivationState.ActiveTag;
                personajeBody.AngularVelocity = TGCVector3.Empty.ToBulletVector3();
                personajeBody.ApplyCentralImpulse(-strength * director.ToBulletVector3());
            }
            if (input.keyUp(Key.W))
            {
                personajeBody.ActivationState = ActivationState.IslandSleeping;
            }
            if (input.keyUp(Key.S))
            {
                personajeBody.ActivationState = ActivationState.IslandSleeping;
            }

            if (input.keyDown(Key.S))
            {
                //Activa el comportamiento de la simulacion fisica para la capsula
                personajeBody.ActivationState = ActivationState.ActiveTag;
                personajeBody.AngularVelocity = TGCVector3.Empty.ToBulletVector3();
                personajeBody.ApplyCentralImpulse(strength * director.ToBulletVector3());
            }

            if (input.keyDown(Key.A))
            {
                director.TransformCoordinate(TGCMatrix.RotationY(-angle * rotationStrength));
                personaje.Transform          = TGCMatrix.Translation(TGCVector3.Empty) * TGCMatrix.RotationY(-angle * rotationStrength) * new TGCMatrix(personajeBody.InterpolationWorldTransform);
                personajeBody.WorldTransform = personaje.Transform.ToBsMatrix;
                personaje.RotateY(-angle * rotationStrength);
                personajeActual.RotarManos(-angle * rotationStrength);
                monstruo.RotateY(-angle * rotationStrength);
                monstruoSilueta.RotateY(-angle * rotationStrength);
            }

            if (input.keyDown(Key.D))
            {
                director.TransformCoordinate(TGCMatrix.RotationY(angle * rotationStrength));
                personaje.Transform          = TGCMatrix.Translation(TGCVector3.Empty) * TGCMatrix.RotationY(angle * rotationStrength) * new TGCMatrix(personajeBody.InterpolationWorldTransform);
                personajeBody.WorldTransform = personaje.Transform.ToBsMatrix;
                personaje.RotateY(angle * rotationStrength);
                personajeActual.RotarManos(angle * rotationStrength);
                monstruo.RotateY(angle * rotationStrength);
                monstruoSilueta.RotateY(angle * rotationStrength);
            }


            #endregion Comportamiento
        }