示例#1
0
        public void update(float elapsedTime)
        {
            GuiController.Instance.FpsCamera.Enable = false;
            // Actualizo la direccion
            if (GuiController.Instance.D3dInput.keyDown(Microsoft.DirectX.DirectInput.Key.A))
            {
                dir_an += 1f * elapsedTime;
            }
            if (GuiController.Instance.D3dInput.keyDown(Microsoft.DirectX.DirectInput.Key.D))
            {
                dir_an -= 1f * elapsedTime;
            }

            // calculo la velocidad
            Vector2 vel = new Vector2((float)Math.Sin(dir_an), (float)Math.Cos(dir_an));

            // actualizo la posicion
            pos += vel * kvel * elapsedTime;

            // actualizo los parametros de la camara
            float   dH       = 1.0f; // altura del personaje
            float   H        = terrain.CalcularAltura(pos.X, pos.Y);
            Vector2 pos_s    = pos + vel * 2;
            Vector3 lookFrom = new Vector3(pos.X, H + dH, pos.Y);
            Vector3 lookAt   = new Vector3(pos_s.X, H, pos_s.Y);

            GuiController.Instance.D3dDevice.Transform.View = Matrix.LookAtLH(lookFrom, lookAt, new Vector3(0, 1, 0));
            effect.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(lookFrom));
        }
        public void setValues(TgcMesh mesh, Vector3 posicionCamara)
        {
            Effect currentShader;


            currentShader = TgcShaders.Instance.TgcMeshSpotLightShader;
            mesh.Effect   = currentShader;
            var direccionLuz = lightDir;

            mesh.Technique = "DIFFUSE_MAP";//TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType);
            mesh.Effect    = TgcShaders.Instance.TgcMeshSpotLightShader;
            //El Technique depende del tipo RenderType del mesh
            mesh.Technique = TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType);
            mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.Violet));
            mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
            mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(posicionCamara));
            mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat3Array(direccionLuz));
            mesh.Effect.SetValue("lightIntensity", lightIntensity);
            mesh.Effect.SetValue("lightAttenuation", 0.3f);
            mesh.Effect.SetValue("spotLightAngleCos", FastMath.ToRad(45f));
            mesh.Effect.SetValue("spotLightExponent", 20f);
            mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Gray));
            mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialSpecularExp", 10f);
        }
示例#3
0
        public override void Render(float elapsedTime)
        {
            if (muzzle.TIME_RENDER > 0)
            {
                muzzle.renderFlash();
                mesh.Effect = currentShader;
                //El Technique depende del tipo RenderType del mesh
                mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(mesh.RenderType);

                mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(muzzle.getPosicion()));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(CustomFpsCamera.Instance.getPosition()));
                mesh.Effect.SetValue("lightIntensity", 2000);
                mesh.Effect.SetValue("lightAttenuation", 0.3f);

                //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.Khaki));
                mesh.Effect.SetValue("materialSpecularExp", 9);
            }
            mesh.render();
            mesh.Effect = GuiController.Instance.Shaders.TgcMeshShader;
        }
示例#4
0
        public override void render(float elapsedTime)
        {
            update(elapsedTime);

            Device  device      = GuiController.Instance.D3dDevice;
            Control panel3d     = GuiController.Instance.Panel3d;
            float   aspectRatio = (float)panel3d.Width / (float)panel3d.Height;

            time += elapsedTime;


            Vector3 lightDir = (Vector3)GuiController.Instance.Modifiers["LightDir"];

            effect.SetValue("g_LightDir", TgcParserUtils.vector3ToFloat3Array(lightDir));
            effect.SetValue("min_cant_samples", (float)GuiController.Instance.Modifiers["minSample"]);
            effect.SetValue("max_cant_samples", (float)GuiController.Instance.Modifiers["maxSample"]);
            effect.SetValue("fHeightMapScale", (float)GuiController.Instance.Modifiers["HeightMapScale"]);
            //effect.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(GuiController.Instance.FpsCamera.getPosition()));
            effect.SetValue("time", time);
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            device.BeginScene();

            //Renderizar terreno con POM
            effect.Technique = "ParallaxOcclusion";
            terrain.executeRender(effect);
            device.EndScene();
        }
        /// <summary>
        /// Levanta la informacion de una animacion a partir del XML
        /// </summary>
        /// <param name="xmlString">Contenido que el XML</param>
        /// <returns>Información parseada</returns>
        public TgcSkeletalAnimationData parseAnimationFromString(string xmlString)
        {
            XmlDocument dom = new XmlDocument();

            dom.LoadXml(xmlString);
            XmlElement root = dom.DocumentElement;

            TgcSkeletalAnimationData animation = new TgcSkeletalAnimationData();

            //Parsear informacion general de animation
            XmlElement animationNode = (XmlElement)root.GetElementsByTagName("animation")[0];

            animation.name        = animationNode.Attributes["name"].InnerText;
            animation.bonesCount  = int.Parse(animationNode.Attributes["bonesCount"].InnerText);
            animation.framesCount = int.Parse(animationNode.Attributes["framesCount"].InnerText);
            animation.frameRate   = int.Parse(animationNode.Attributes["frameRate"].InnerText);
            animation.startFrame  = int.Parse(animationNode.Attributes["startFrame"].InnerText);
            animation.endFrame    = int.Parse(animationNode.Attributes["endFrame"].InnerText);

            //Parsear boundingBox, si esta
            XmlNodeList boundingBoxNodes = animationNode.GetElementsByTagName("boundingBox");

            if (boundingBoxNodes != null && boundingBoxNodes.Count == 1)
            {
                XmlNode boundingBoxNode = boundingBoxNodes[0];
                animation.pMin = TgcParserUtils.parseFloat3Array(boundingBoxNode.Attributes["min"].InnerText);
                animation.pMax = TgcParserUtils.parseFloat3Array(boundingBoxNode.Attributes["max"].InnerText);
            }

            //Parsear bones
            XmlNodeList boneNodes = animationNode.GetElementsByTagName("bone");

            animation.bonesFrames = new TgcSkeletalAnimationBoneData[boneNodes.Count];
            int boneIdx = 0;

            foreach (XmlElement boneNode in boneNodes)
            {
                TgcSkeletalAnimationBoneData boneData = new TgcSkeletalAnimationBoneData();
                boneData.id             = (int)TgcParserUtils.parseInt(boneNode.Attributes["id"].InnerText);
                boneData.keyFramesCount = (int)TgcParserUtils.parseInt(boneNode.Attributes["keyFramesCount"].InnerText);
                boneData.keyFrames      = new TgcSkeletalAnimationBoneFrameData[boneData.keyFramesCount];

                //Parsear frames
                int frames = 0;
                foreach (XmlElement frameNode in boneNode.ChildNodes)
                {
                    TgcSkeletalAnimationBoneFrameData frameData = new TgcSkeletalAnimationBoneFrameData();
                    frameData.frame    = TgcParserUtils.parseInt(frameNode.Attributes["n"].InnerText);
                    frameData.position = TgcParserUtils.parseFloat3Array(frameNode.Attributes["pos"].InnerText);
                    frameData.rotation = TgcParserUtils.parseFloat4Array(frameNode.Attributes["rotQuat"].InnerText);

                    boneData.keyFrames[frames++] = frameData;
                }

                animation.bonesFrames[boneIdx++] = boneData;
            }


            return(animation);
        }
示例#6
0
        /// <summary>
        /// Hacer blur de bright-pass para generar efecto de bloom
        /// </summary>
        /// <param name="d3dDevice"></param>
        private void bloomPass(Device d3dDevice)
        {
            d3dDevice.BeginScene();

            //Gaussian blur horizontal
            Vector2[] texCoordOffsets;
            float[]   colorWeights;
            Surface   bloomTempS = bloomTempRT.GetSurfaceLevel(0);

            TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(bloomTempS.Description.Width, 1, 1, true, out texCoordOffsets, out colorWeights);
            effect.Technique = "BloomPass";
            effect.SetValue("texBloomRT", brightPassRT);
            d3dDevice.SetRenderTarget(0, bloomTempS);
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            screenQuad.render(effect);

            //Gaussian blur vertical
            TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(bloomTempS.Description.Height, 1, 1, false, out texCoordOffsets, out colorWeights);
            effect.Technique = "BloomPass";
            effect.SetValue("texBloomRT", bloomTempRT);
            effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
            effect.SetValue("gauss_weights", colorWeights);
            Surface bloomS = bloomRT.GetSurfaceLevel(0);

            d3dDevice.SetRenderTarget(0, bloomS);
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            screenQuad.render(effect);

            bloomTempS.Dispose();
            bloomS.Dispose();
            d3dDevice.EndScene();
        }
        public override void Render(float elapsedTime)
        {
            //skeletalMesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(this.getPosicionActual() + this.vectorDireccion * 100));
            skeletalMesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(CustomFpsCamera.Instance.getPosition()));

            //setBaseEffectValues(elapsedTime);
            //renderizamos el skeletalmesh
            if (muerto)
            {
                skeletalMesh.render();
            }
            else
            {
                skeletalMesh.animateAndRender();
            }

            //se puede habilitar el renderizado de los boundingbox
            if (GameManager.Instance.drawBoundingBoxes)
            {
                this.mesh.BoundingBox.render();
                this.HEADSHOT_BOUNDINGBOX.render();
                this.CHEST_BOUNDINGBOX.render();
                this.LEGS_BOUNDINGBOX.render();
            }
        }
        public void update()
        {
            float luz = calculateLight() + 0.1f;

            time += ElapsedTime;

            if (time < 0)
            {
                time = 0;
            }

            mainEffect.SetValue("time", time);
            mainEffect.SetValue("luz", luz);

            grassEffect.SetValue("time", time);
            grassEffect.SetValue("luz", luz);
            grassEffect.SetValue("wind", TgcParserUtils.vector2ToFloat2Array(MyWorld.Wind));

            treeEffect.SetValue("time", time);
            treeEffect.SetValue("luz", luz);
            treeEffect.SetValue("wind", TgcParserUtils.vector2ToFloat2Array(MyWorld.Wind));

            foreach (TgcMesh mesh in MyWorld.SkyBox.Faces)
            {
                mesh.Effect.SetValue("time", (float)time);
                mesh.Effect.SetValue("luz", luz);
            }
        }
示例#9
0
        //OBB
        private List <TgcObb> cargarObbObjetos()
        {
            string        filePath  = GuiController.Instance.AlumnoEjemplosMediaDir + "TheC#\\Auto\\\\pistaObbs-TgcScene.xml";
            string        mediaPath = filePath.Substring(0, filePath.LastIndexOf('\\') + 1);
            string        xmlString = File.ReadAllText(filePath);
            List <TgcObb> objetos   = new List <TgcObb>();

            XmlDocument dom = new XmlDocument();

            dom.LoadXml(xmlString);
            XmlElement root = dom.DocumentElement;

            //Parsear obbs
            XmlNodeList obbNodes = root.GetElementsByTagName("obbs")[0].ChildNodes;

            foreach (XmlElement obbNode in obbNodes)
            {
                Vector3 center       = TgcParserUtils.float3ArrayToVector3(TgcParserUtils.parseFloat3Array(obbNode.Attributes["center"].InnerText));
                Vector3 extents      = TgcParserUtils.float3ArrayToVector3(TgcParserUtils.parseFloat3Array(obbNode.Attributes["extents"].InnerText));
                Vector3 orientation0 = TgcParserUtils.float3ArrayToVector3(TgcParserUtils.parseFloat3Array(obbNode.Attributes["orientation0"].InnerText));
                Vector3 orientation1 = TgcParserUtils.float3ArrayToVector3(TgcParserUtils.parseFloat3Array(obbNode.Attributes["orientation1"].InnerText));
                Vector3 orientation2 = TgcParserUtils.float3ArrayToVector3(TgcParserUtils.parseFloat3Array(obbNode.Attributes["orientation2"].InnerText));

                Vector3[] orientation = new Vector3[] { orientation0, orientation1, orientation2 };
                TgcObb    minObb      = new TgcObb();

                minObb.Center      = center;
                minObb.Extents     = extents;
                minObb.Orientation = orientation;

                objetos.Add(minObb);
            }

            return(objetos);
        }
示例#10
0
        private void SetValuesToMesh()
        {
            Vector3 eyePosition = GuiController.Instance.FpsCamera.getPosition();

            //Cargar variables shader de la luz
            try
            {
                meshDeAuto.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White));
                meshDeAuto.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(new Vector3(-10000, 700, 11880)));
                meshDeAuto.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                meshDeAuto.Effect.SetValue("lightIntensity", (float)4500);
                meshDeAuto.Effect.SetValue("lightAttenuation", (float)0.9f);
                meshDeAuto.Effect.SetValue("bumpiness", (float)1f);

                meshDeAuto.Effect.SetValue("materialSpecularExp", 9f);
                meshDeAuto.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Gray));
                meshDeAuto.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                meshDeAuto.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                meshDeAuto.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
            }
            catch (Exception e)
            {
                //No tiro ninguna excepción específica
            }
        }
示例#11
0
        public void setShadersValues()
        {
            Vector3 lightPosition = new Vector3(-100, 140, 3000);// (Vector3)GuiController.Instance.Modifiers["LightPosition"];

            efectoOlas.SetValue("llueve", (Boolean)GuiController.Instance.Modifiers["lluvia"]);
            efectoOlas.SetValue("time", (float)GuiController.Instance.UserVars.getValue("time"));
            efectoOlas.SetValue("fvLightPosition", TgcParserUtils.vector3ToFloat3Array(lightPosition));
            efectoOlas.SetValue("k_la", (float)GuiController.Instance.Modifiers["Ambient"]);
            efectoOlas.SetValue("fSpecularPower", 20.0f);//(float)GuiController.Instance.Modifiers["SpecularPower"]);            efectoOlas.SetValue("blendAmount", (float)GuiController.Instance.Modifiers["blending"]);
            efectoOlas.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(GuiController.Instance.CurrentCamera.getPosition()));
            efectoOlas.SetValue("fogColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["fog color"]));
            efectoOlas.SetValue("fogStart", (float)GuiController.Instance.Modifiers["fog start"]);
            efectoOlas.SetValue("blendStart", (float)GuiController.Instance.Modifiers["blend start"]);

            efectoOlas.SetValue("camara3p", (Boolean)GuiController.Instance.Modifiers["camaraEnBarco"]);
            efectoOlas.SetValue("rayo", rayo);
            efectoOlas.SetValue("delta", 150.0f);//(float)GuiController.Instance.Modifiers["delta"]);            efectoOlas.SetValue("reflection", (float)GuiController.Instance.Modifiers["reflection"]);
            //CubeMap
            efectoOlas.SetValue("texCubeMap", cubeMap);

            efectoCascada.SetValue("time", (float)GuiController.Instance.UserVars.getValue("time"));
            efectoCascada.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(GuiController.Instance.CurrentCamera.getPosition()));
            efectoCascada.SetValue("fvLightPosition", TgcParserUtils.vector3ToFloat3Array(lightPosition));
            efectoCascada.SetValue("camara3p", (Boolean)GuiController.Instance.Modifiers["camaraEnBarco"]);
            efectoCascada.SetValue("texCubeMap", cubeMap);
            efectoCascada.SetValue("reflection", (float)GuiController.Instance.Modifiers["reflection"]);
            efectoCascada.SetValue("blendAmount", (float)GuiController.Instance.Modifiers["blending"]);
            efectoCascada.SetValue("k_la", (float)GuiController.Instance.Modifiers["Ambient"]);
        }
示例#12
0
        public override void render(float elapsedTime)
        {
            Device device = GuiController.Instance.D3dDevice;

            Vector3 lightPosition = (Vector3)GuiController.Instance.Modifiers["LightPosition"];

            //Cargar variables de shader globales a todos los objetos
            mesh.Effect.SetValue("fvLightPosition", TgcParserUtils.vector3ToFloat3Array(lightPosition));
            mesh.Effect.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(GuiController.Instance.RotCamera.getPosition()));
            mesh.Effect.SetValue("fvAmbient", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["AmbientColor"]));
            mesh.Effect.SetValue("fvDiffuse", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["DiffuseColor"]));
            mesh.Effect.SetValue("fvSpecular", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["SpecularColor"]));
            mesh.Effect.SetValue("fSpecularPower", (float)GuiController.Instance.Modifiers["SpecularPower"]);

            //Mover mesh que representa la luz
            lightBox.Position = lightPosition;

            //Mover mesh
            Vector3 meshPos = (Vector3)GuiController.Instance.Modifiers["MeshPos"];

            mesh.Position = meshPos;

            mesh.render();
            lightBox.render();
        }
示例#13
0
        public override void Render()
        {
            //BackgroundColor
            D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            D3DDevice.Instance.Device.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",
                                 TgcParserUtils.vector3ToFloat4Array(Camara.Position));

            mesh.rotateY(-ElapsedTime / 2);
            mesh.render();

            textHelp.render();

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

            PostRender();
        }
示例#14
0
        public void ProcesarLuces()
        {
            if (camara == null)
            {
                return;
            }
            var lightDir = new Vector3(20, 0, 0);

            lightDir.Normalize();
            foreach (var mesh in lstMeshes)
            {
                Vector3 posicionCamara = camara.Position;
                Vector3 posicionLuz    = new Vector3(0, 30, 0);
                mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color.White)));
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToVector4(posicionLuz));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(posicionCamara));
                mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat3Array(lightDir));
                mesh.Effect.SetValue("lightIntensity", 200f);
                mesh.Effect.SetValue("lightAttenuation", 0.1f);
                mesh.Effect.SetValue("spotLightAngleCos", 55);
                mesh.Effect.SetValue("spotLightExponent", 7f);

                //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color.Gray)));
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color.White)));
                mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color.White)));
                mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color.White)));
                mesh.Effect.SetValue("materialSpecularExp", 1f);
                mesh.render();
            }
        }
 public override string ToString()
 {
     return("Min[" + TgcParserUtils.printFloat(pMin.X) + ", " + TgcParserUtils.printFloat(pMin.Y) + ", " +
            TgcParserUtils.printFloat(pMin.Z) + "]" +
            " Max[" + TgcParserUtils.printFloat(pMax.X) + ", " + TgcParserUtils.printFloat(pMax.Y) + ", " +
            TgcParserUtils.printFloat(pMax.Z) + "]");
 }
示例#16
0
        /// <summary>
        ///     Carga un Modelo a partir de un objeto TgcKeyFrameMeshData ya parseado
        /// </summary>
        /// <param name="meshData">Objeto con datos ya parseados</param>
        /// <param name="mediaPath">Path a partir del cual hay que buscar las Texturas</param>
        /// <returns>Modelo cargado</returns>
        public TgcKeyFrameMesh loadMesh(TgcKeyFrameMeshData meshData, string mediaPath)
        {
            //Cargar Texturas
            var materialsArray = new TgcKeyFrameLoaderMaterialAux[meshData.materialsData.Length];

            for (var i = 0; i < meshData.materialsData.Length; i++)
            {
                var materialData = meshData.materialsData[i];
                var texturesPath = mediaPath + meshData.texturesDir + "\\";

                //Crear StandardMaterial
                if (materialData.type.Equals(TgcMaterialData.StandardMaterial))
                {
                    materialsArray[i] = createTextureAndMaterial(materialData, texturesPath);
                }

                //Crear MultiMaterial
                else if (materialData.type.Equals(TgcMaterialData.MultiMaterial))
                {
                    var matAux = new TgcKeyFrameLoaderMaterialAux();
                    materialsArray[i]   = matAux;
                    matAux.subMaterials = new TgcKeyFrameLoaderMaterialAux[materialData.subMaterials.Length];
                    for (var j = 0; j < materialData.subMaterials.Length; j++)
                    {
                        matAux.subMaterials[j] = createTextureAndMaterial(materialData.subMaterials[j], texturesPath);
                    }
                }
            }

            //Crear Mesh
            TgcKeyFrameMesh tgcMesh = null;

            //Crear mesh que no tiene Material, con un color simple
            if (meshData.materialId == -1)
            {
                tgcMesh = crearMeshSoloColor(meshData);
            }

            //Crear mesh con DiffuseMap
            else
            {
                tgcMesh = crearMeshDiffuseMap(materialsArray, meshData);
            }

            //Crear BoundingBox, aprovechar lo que viene del XML o crear uno por nuestra cuenta
            if (meshData.pMin != null && meshData.pMax != null)
            {
                tgcMesh.BoundingBox = new TgcBoundingAxisAlignBox(
                    TgcParserUtils.float3ArrayToVector3(meshData.pMin),
                    TgcParserUtils.float3ArrayToVector3(meshData.pMax)
                    );
            }
            else
            {
                tgcMesh.createBoundingBox();
            }

            tgcMesh.Enabled = true;
            return(tgcMesh);
        }
示例#17
0
 public override string ToString()
 {
     return("Origin[" + TgcParserUtils.printFloat(Origin.X) + ", " + TgcParserUtils.printFloat(Origin.Y) + ", " +
            TgcParserUtils.printFloat(Origin.Z) + "]" +
            " Direction[" + TgcParserUtils.printFloat(direction.X) + ", " +
            TgcParserUtils.printFloat(direction.Y) + ", " + TgcParserUtils.printFloat(direction.Z) + "]");
 }
示例#18
0
        /// <summary>
        /// Se toma todo lo dibujado antes, que se guardo en una textura, y se le aplica un shader para borronear la imagen
        /// </summary>
        private void drawPostProcess(Device d3dDevice)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Ver si el efecto de oscurecer esta activado, configurar Technique del shader segun corresponda
            bool activar_efecto = (bool)GuiController.Instance.Modifiers["activar_efecto"];

            //Hacer blur
            if (activar_efecto)
            {
                float   deviation = (float)GuiController.Instance.Modifiers["deviation"];
                Surface blurTempS = blurTempRT.GetSurfaceLevel(0);

                //Gaussian blur horizontal
                Vector2[] texCoordOffsets;
                float[]   colorWeights;
                TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(blurTempS.Description.Width, deviation, 1, true, out texCoordOffsets, out colorWeights);
                effect.Technique = "GaussianBlurPass";
                effect.SetValue("texSceneRT", sceneRT);
                effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
                effect.SetValue("gauss_weights", colorWeights);
                d3dDevice.SetRenderTarget(0, blurTempS);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);

                //Gaussian blur vertical
                TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(blurTempS.Description.Height, deviation, 1, false, out texCoordOffsets, out colorWeights);
                effect.Technique = "GaussianBlurPass";
                effect.SetValue("texSceneRT", blurTempRT);
                effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
                effect.SetValue("gauss_weights", colorWeights);
                d3dDevice.SetRenderTarget(0, pOldRT);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);

                blurTempS.Dispose();
            }
            //No hacer blur
            else
            {
                effect.Technique = "DefaultTechnique";
                effect.SetValue("texSceneRT", sceneRT);
                d3dDevice.SetRenderTarget(0, pOldRT);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);
            }


            //Como estamos en modo CustomRenderEnabled, tenemos que dibujar todo nosotros, incluso el contador de FPS
            GuiController.Instance.Text3d.drawText("FPS: " + HighResolutionTimer.Instance.FramesPerSecond, 0, 0, Color.Yellow);

            //Tambien hay que dibujar el indicador de los ejes cartesianos
            GuiController.Instance.AxisLines.render();


            //Terminamos el renderizado de la escena
            d3dDevice.EndScene();
        }
 private void ConfigurarDirectX(Vector3 camaraPosition)
 {
     effect.SetValue("ColorFog", fog.Color.ToArgb());
     effect.SetValue("CameraPos", TgcParserUtils.vector3ToFloat4Array(camaraPosition));
     effect.SetValue("StartFogDistance", fog.StartDistance);
     effect.SetValue("EndFogDistance", fog.EndDistance);
     effect.SetValue("Density", fog.Density);
 }
示例#20
0
        public override void render(float elapsedTime)
        {
            Device device = GuiController.Instance.D3dDevice;

            //Actualzar posición de la luz
            Vector3 lightPos = (Vector3)GuiController.Instance.Modifiers["lightPos"];

            lightMesh.Position = lightPos;
            Vector3 eyePosition = GuiController.Instance.FpsCamera.getPosition();

            //Renderizar meshes
            foreach (TgcMeshBumpMapping mesh in meshes)
            {
                //Cargar variables shader de la luz
                mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["lightColor"]));
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                mesh.Effect.SetValue("lightIntensity", (float)GuiController.Instance.Modifiers["lightIntensity"]);
                mesh.Effect.SetValue("lightAttenuation", (float)GuiController.Instance.Modifiers["lightAttenuation"]);
                mesh.Effect.SetValue("bumpiness", (float)GuiController.Instance.Modifiers["bumpiness"]);

                //Material
                mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"]));
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mAmbient"]));
                mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"]));
                mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mSpecular"]));
                mesh.Effect.SetValue("materialSpecularExp", (float)GuiController.Instance.Modifiers["specularEx"]);

                //Renderizar modelo
                mesh.render();
            }


            //Renderizar mesh de luz
            lightMesh.render();


            //Dibujar flechas de debug
            bool showNormals   = (bool)GuiController.Instance.Modifiers["showNormals"];
            bool showTangents  = (bool)GuiController.Instance.Modifiers["showTangents"];
            bool showBinormals = (bool)GuiController.Instance.Modifiers["showBinormals"];

            for (int i = 0; i < normals.Count; i++)
            {
                if (showNormals)
                {
                    normals[i].render();
                }
                if (showTangents)
                {
                    tangents[i].render();
                }
                if (showBinormals)
                {
                    binormals[i].render();
                }
            }
        }
示例#21
0
        public override void Init()
        {
            //Cargar escenario, pero inicialmente solo hacemos el parser, para separar los objetos que son solo luces y no meshes
            var scenePath = MediaDir + "Escenario\\EscenarioLuces-TgcScene.xml";
            var mediaPath = MediaDir + "Escenario\\";
            var parser    = new TgcSceneParser();
            var sceneData = parser.parseSceneFromString(File.ReadAllText(scenePath));

            //Separar modelos reales de las luces, segun layer "Lights"
            lights = new List <LightData>();
            var realMeshData = new List <TgcMeshData>();

            for (var i = 0; i < sceneData.meshesData.Length; i++)
            {
                var meshData = sceneData.meshesData[i];

                //Es una luz, no cargar mesh, solo importan sus datos
                if (meshData.layerName == "Lights")
                {
                    //Guardar datos de luz
                    var light = new LightData();
                    light.color = Color.FromArgb((int)meshData.color[0], (int)meshData.color[1],
                                                 (int)meshData.color[2]);
                    light.aabb = new TgcBoundingAxisAlignBox(TgcParserUtils.float3ArrayToVector3(meshData.pMin),
                                                             TgcParserUtils.float3ArrayToVector3(meshData.pMax));
                    light.pos = light.aabb.calculateBoxCenter();
                    lights.Add(light);
                }
                //Es un mesh real, agregar a array definitivo
                else
                {
                    realMeshData.Add(meshData);
                }
            }

            //Reemplazar array original de meshData de sceneData por el definitivo
            sceneData.meshesData = realMeshData.ToArray();

            //Ahora si cargar meshes reales
            var loader = new TgcSceneLoader();

            scene = loader.loadScene(sceneData, mediaPath);

            //Camara en 1ra persona
            Camara = new TgcFpsCamera(new Vector3(-20, 80, 450), 400f, 300f, Input);

            //Modifiers para variables de luz
            Modifiers.addBoolean("lightEnable", "lightEnable", true);
            Modifiers.addFloat("lightIntensity", 0, 150, 20);
            Modifiers.addFloat("lightAttenuation", 0.1f, 2, 0.3f);
            Modifiers.addFloat("specularEx", 0, 20, 9f);

            //Modifiers para material
            Modifiers.addColor("mEmissive", Color.Black);
            Modifiers.addColor("mAmbient", Color.White);
            Modifiers.addColor("mDiffuse", Color.White);
            Modifiers.addColor("mSpecular", Color.White);
        }
        public override void Render()
        {
            PreRender();

            sceneRecover.renderAll();
            DrawText.drawText("Camera pos: " + TgcParserUtils.printVector3(Camara.Position), 5, 20, Color.Red);
            DrawText.drawText("Camera LookAt: " + TgcParserUtils.printVector3(Camara.LookAt), 5, 40, Color.Red);
            PostRender();
        }
示例#23
0
        public override void Render()
        {
            PreRender();
            DrawText.drawText("Camera pos: " + TgcParserUtils.printVector3(Camara.Position), 5, 20, Color.Red);
            //Renderizar SkyBox
            skyBox.render();

            PostRender();
        }
示例#24
0
        private void DibujarDebug()
        {
            DrawText.drawText("GodMode = ON", 600, 40, Color.OrangeRed);
            DrawText.drawText("F = bounding box.", 0, 20, Color.OrangeRed);
            DrawText.drawText("posicion camara: " + TgcParserUtils.printVector3(Camara.Position), 0, 30, Color.OrangeRed);
            DrawText.drawText("GodMode = OFF", 0, 40, Color.White);
            DrawText.drawText("v=", 0, 50, Color.Orange);
            DrawText.drawText(AutoJugador.Velocidad.ToString(), 20, 50, Color.Orange);
            //DrawText.drawText("ruedas=", 0, 60, Color.Green);
            //DrawText.drawText(AutoJugador.DireccionRuedas.ToString(), 50, 60, Color.Green);

            DrawText.drawText("angOrientacionMesh=", 0, 70, Color.White);
            DrawText.drawText((AutoJugador.angOrientacionMesh * 180 / (float)Math.PI).ToString(), 160, 70, Color.White);

            DrawText.drawText("MeshPosition=", 0, 80, Color.White);
            DrawText.drawText(AutoJugador.Mesh.Position.ToString(), 100, 80, Color.White);



            DrawText.drawText("scale mesh = ", 0, 160, Color.White);
            DrawText.drawText(AutoJugador.Mesh.Scale.ToString(), 100, 160, Color.White);

            DrawText.drawText("obb center = ", 0, 220, Color.White);
            DrawText.drawText(AutoJugador.obb.Center.ToString(), 100, 220, Color.White);

            DrawText.drawText("bounding position = ", 0, 280, Color.White);
            DrawText.drawText(AutoJugador.Mesh.BoundingBox.ToString(), 150, 280, Color.White);

            //DrawText.drawText("collisionFound = ", 0, 340, Color.White);
            //DrawText.drawText(AutoJugador.collisionFound.ToString(), 150, 340, Color.White);

            DrawText.drawText("direccionRuedas = ", 0, 400, Color.White);
            DrawText.drawText(AutoJugador.DireccionRuedas.ToString(), 150, 400, Color.White);

            DrawText.drawText("posicion luz ", 0, 420, Color.White);
            DrawText.drawText(pointLuz.lighthPos.ToString(), 150, 420, Color.White);

            DrawText.drawText("choco adelante ", 0, 480, Color.White);
            DrawText.drawText(AutoJugador.chocoAdelante.ToString(), 150, 480, Color.White);

            DrawText.drawText("t= ", 230, 520, Color.White);
            DrawText.drawText(autoOponente.tiempoEspera.ToString(), 250, 580, Color.Orange);

            /*
             * DrawText.drawText("time ", 0, 500, Color.White);
             *
             *
             * DrawText.drawText(minString+":"+ segString, 150, 500, Color.White);*/

            if (BoundingBox)
            {
                //Box.BoundingBox.render();
                // Mesh.BoundingBox.render();
                AutoJugador.Mesh.BoundingBox.render();
                MapScene.BoundingBox.render();
            }
        }
示例#25
0
        /// <summary>
        /// String de codigo para setear la camara desde GuiController, con la posicion actual y direccion de la camara
        /// </summary>
        internal string getPositionCode()
        {
            //TODO ver de donde carajo sacar el LookAt de esta camara
            Vector3 lookAt = this.LookAt;

            return("GuiController.Instance.setCamera(new Vector3(" +
                   TgcParserUtils.printFloat(eye.X) + "f, " + TgcParserUtils.printFloat(eye.Y) + "f, " + TgcParserUtils.printFloat(eye.Z) + "f), new Vector3(" +
                   TgcParserUtils.printFloat(lookAt.X) + "f, " + TgcParserUtils.printFloat(lookAt.Y) + "f, " + TgcParserUtils.printFloat(lookAt.Z) + "f));");
        }
        /// <summary>
        ///     Se toma todo lo dibujado antes, que se guardo en una textura, y se le aplica un shader para borronear la imagen
        /// </summary>
        private void drawPostProcess(Device d3dDevice)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Ver si el efecto de oscurecer esta activado, configurar Technique del shader segun corresponda
            var activar_efecto = (bool)Modifiers["activar_efecto"];

            //Hacer blur
            if (activar_efecto)
            {
                var deviation = (float)Modifiers["deviation"];
                var blurTempS = blurTempRT.GetSurfaceLevel(0);

                //Gaussian blur horizontal
                Vector2[] texCoordOffsets;
                float[]   colorWeights;
                TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(blurTempS.Description.Width, deviation, 1,
                                                                          true, out texCoordOffsets, out colorWeights);
                effect.Technique = "GaussianBlurPass";
                effect.SetValue("texSceneRT", sceneRT);
                effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
                effect.SetValue("gauss_weights", colorWeights);
                d3dDevice.SetRenderTarget(0, blurTempS);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);

                //Gaussian blur vertical
                TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(blurTempS.Description.Height, deviation, 1,
                                                                          false, out texCoordOffsets, out colorWeights);
                effect.Technique = "GaussianBlurPass";
                effect.SetValue("texSceneRT", blurTempRT);
                effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
                effect.SetValue("gauss_weights", colorWeights);
                d3dDevice.SetRenderTarget(0, pOldRT);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);

                blurTempS.Dispose();
            }
            //No hacer blur
            else
            {
                effect.Technique = "DefaultTechnique";
                effect.SetValue("texSceneRT", sceneRT);
                d3dDevice.SetRenderTarget(0, pOldRT);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);
            }

            //Terminamos el renderizado de la escena
            RenderFPS();
            RenderAxis();
            d3dDevice.EndScene();
            d3dDevice.Present();
        }
示例#27
0
        public override void Render(float elapsedTime)
        {
            // mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(this.getPosicionActual() + this.vectorDireccion * 100));
            mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(CustomFpsCamera.Instance.getPosition()));

            if (!muerto)
            {
                base.Render(elapsedTime);
            }
        }
示例#28
0
        /// <summary>
        /// Configura la posicion de la cámara
        /// </summary>
        /// <param name="pos">Posición de la cámara</param>
        /// <param name="lookAt">Punto hacia el cuál se quiere ver</param>
        public void setCamera(Vector3 pos, Vector3 lookAt)
        {
            tgcD3dDevice.D3dDevice.Transform.View = Matrix.LookAtLH(pos, lookAt, new Vector3(0, 1, 0));

            //Imprimir posicion
            string statusPos = "Position: [" + TgcParserUtils.printFloat(pos.X) + ", " + TgcParserUtils.printFloat(pos.Y) + ", " + TgcParserUtils.printFloat(pos.Z) + "] " +
                               "- LookAt: [" + TgcParserUtils.printFloat(lookAt.X) + ", " + TgcParserUtils.printFloat(lookAt.Y) + ", " + TgcParserUtils.printFloat(lookAt.Z) + "]";

            mainForm.setStatusPosition(statusPos);
        }
示例#29
0
        public override void render(float elapsedTime)
        {
            Device device = GuiController.Instance.D3dDevice;


            //Habilitar luz
            bool   lightEnable = (bool)GuiController.Instance.Modifiers["lightEnable"];
            Effect currentShader;

            if (lightEnable)
            {
                //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PointLight para Skeletal Mesh
                currentShader = GuiController.Instance.Shaders.TgcSkeletalMeshPointLightShader;
            }
            else
            {
                //Sin luz: Restaurar shader default
                currentShader = GuiController.Instance.Shaders.TgcSkeletalMeshShader;
            }

            //Aplicar al mesh el shader actual
            mesh.Effect = currentShader;
            //El Technique depende del tipo RenderType del mesh
            mesh.Technique = GuiController.Instance.Shaders.getTgcSkeletalMeshTechnique(mesh.RenderType);



            //Actualzar posición de la luz
            Vector3 lightPos = (Vector3)GuiController.Instance.Modifiers["lightPos"];

            lightMesh.Position = lightPos;

            //Renderizar mesh
            if (lightEnable)
            {
                //Cargar variables shader de la luz
                mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["lightColor"]));
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.FpsCamera.getPosition()));
                mesh.Effect.SetValue("lightIntensity", (float)GuiController.Instance.Modifiers["lightIntensity"]);
                mesh.Effect.SetValue("lightAttenuation", (float)GuiController.Instance.Modifiers["lightAttenuation"]);

                //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"]));
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mAmbient"]));
                mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"]));
                mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mSpecular"]));
                mesh.Effect.SetValue("materialSpecularExp", (float)GuiController.Instance.Modifiers["specularEx"]);
            }
            mesh.animateAndRender();


            //Renderizar mesh de luz
            lightMesh.render();
        }
示例#30
0
 public void Render()
 {
     RuedaMeshDer.render();
     RuedaMeshIzq.render();
     if (SonDelanteras)
     {
         TgcText2D Drawtext = new TgcText2D();
         Drawtext.drawText("I = " + TgcParserUtils.printVector3(RuedaMeshIzq.Position), 0, 100, Color.OrangeRed);
         Drawtext.drawText("D =" + TgcParserUtils.printVector3(RuedaMeshDer.Position), 0, 120, Color.OrangeRed);
     }
 }