public override void Render() { Device d3dDevice = D3DDevice.Instance.Device; time += ElapsedTime; TGCVector3 lightDir = lightDirModifier.Value; effect.SetValue("g_LightDir", TGCVector3.TGCVector3ToFloat3Array(lightDir)); effect.SetValue("min_cant_samples", minSampleModifier.Value); effect.SetValue("max_cant_samples", maxSampleModifier.Value); effect.SetValue("fHeightMapScale", heightMapScaleModifier.Value); effect.SetValue("fvEyePosition", TGCVector3.TGCVector3ToFloat3Array(Camera.Position)); effect.SetValue("time", time); effect.SetValue("aux_Tex", g_pBaseTexture); effect.SetValue("height_map", g_pHeightmap); effect.SetValue("phong_lighting", true); d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); d3dDevice.BeginScene(); foreach (TgcMesh mesh in scene.Meshes) { bool va = true; int nro_textura = 0; mesh.Effect = effect; if (mesh.Name.Contains("Floor")) { effect.SetValue("g_normal", TGCVector3.TGCVector3ToFloat3Array(TGCVector3.Down)); effect.SetValue("g_tangent", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(1, 0, 0))); effect.SetValue("g_binormal", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(0, 0, 1))); nro_textura = 0; } else if (mesh.Name.Contains("Roof")) { effect.SetValue("g_normal", TGCVector3.TGCVector3ToFloat3Array(TGCVector3.Up)); effect.SetValue("g_tangent", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(1, 0, 0))); effect.SetValue("g_binormal", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(0, 0, 1))); nro_textura = 0; va = false; } else if (mesh.Name.Contains("East")) { effect.SetValue("g_normal", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(1, 0, 0))); effect.SetValue("g_tangent", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(0, 0, 1))); effect.SetValue("g_binormal", TGCVector3.TGCVector3ToFloat3Array(TGCVector3.Up)); nro_textura = 1; } else if (mesh.Name.Contains("West")) { effect.SetValue("g_normal", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(-1, 0, 0))); effect.SetValue("g_tangent", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(0, 0, 1))); effect.SetValue("g_binormal", TGCVector3.TGCVector3ToFloat3Array(TGCVector3.Up)); nro_textura = 1; } else if (mesh.Name.Contains("North")) { effect.SetValue("g_normal", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(0, 0, -1))); effect.SetValue("g_tangent", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(1, 0, 0))); effect.SetValue("g_binormal", TGCVector3.TGCVector3ToFloat3Array(TGCVector3.Up)); nro_textura = 1; } else if (mesh.Name.Contains("South")) { effect.SetValue("g_normal", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(0, 0, 1))); effect.SetValue("g_tangent", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(1, 0, 0))); effect.SetValue("g_binormal", TGCVector3.TGCVector3ToFloat3Array(TGCVector3.Up)); nro_textura = 1; } switch (nro_textura) { case 0: default: effect.SetValue("aux_Tex", g_pBaseTexture); effect.SetValue("height_map", g_pHeightmap); break; case 1: effect.SetValue("aux_Tex", g_pBaseTexture2); effect.SetValue("height_map", g_pHeightmap2); break; case 2: effect.SetValue("aux_Tex", g_pBaseTexture3); effect.SetValue("height_map", g_pHeightmap3); break; case 3: effect.SetValue("aux_Tex", g_pBaseTexture4); effect.SetValue("height_map", g_pHeightmap4); break; } if (va) { mesh.Technique = "ParallaxOcclusion2"; mesh.Render(); } } //Render personames enemigos foreach (TgcSkeletalMesh m in enemigos) { m.Render(); } // Render hud renderHUD(); gui.trapezoidal_style = false; //radar de proximidad float max_dist = 80; foreach (TgcSkeletalMesh m in enemigos) { TGCVector3 pos_personaje = Camera.Position; TGCVector3 pos_enemigo = m.Position * 1; float dist = (pos_personaje - pos_enemigo).Length(); if (dist < max_dist) { pos_enemigo.Y = m.BoundingBox.PMax.Y * 0.75f + m.BoundingBox.PMin.Y * 0.25f; pos_enemigo.Project(d3dDevice.Viewport, TGCMatrix.FromMatrix(d3dDevice.Transform.Projection), TGCMatrix.FromMatrix(d3dDevice.Transform.View), TGCMatrix.FromMatrix(d3dDevice.Transform.World)); if (pos_enemigo.Z > 0 && pos_enemigo.Z < 1) { float an = (max_dist - dist) / max_dist * 3.1415f * 2.0f; int d = (int)dist; gui.DrawArc(new TGCVector2(pos_enemigo.X + 20, pos_enemigo.Y), 40, 0, an, 10, dist < 30 ? Color.Tomato : Color.WhiteSmoke); gui.DrawLine(pos_enemigo.X, pos_enemigo.Y, pos_enemigo.X + 20, pos_enemigo.Y, 3, Color.PowderBlue); gui.DrawLine(pos_enemigo.X + 20, pos_enemigo.Y, pos_enemigo.X + 40, pos_enemigo.Y - 20, 3, Color.PowderBlue); gui.TextOut((int)pos_enemigo.X + 50, (int)pos_enemigo.Y - 20, "Proximidad " + d, Color.PowderBlue); } } } gui.trapezoidal_style = true; PostRender(); }
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); effect.SetValue("aux_Tex", g_pBaseTexture); effect.SetValue("height_map", g_pHeightmap); effect.SetValue("phong_lighting", true); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); device.BeginScene(); foreach (TgcMesh mesh in scene.Meshes) { bool va = true; int nro_textura = 0; mesh.Effect = effect; if (mesh.Name.Contains("Floor")) { effect.SetValue("g_normal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, -1, 0))); effect.SetValue("g_tangent", TgcParserUtils.vector3ToFloat3Array(new Vector3(1, 0, 0))); effect.SetValue("g_binormal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 0, 1))); nro_textura = 0; } else if (mesh.Name.Contains("Roof")) { effect.SetValue("g_normal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 1, 0))); effect.SetValue("g_tangent", TgcParserUtils.vector3ToFloat3Array(new Vector3(1, 0, 0))); effect.SetValue("g_binormal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 0, 1))); nro_textura = 0; va = false; } else if (mesh.Name.Contains("East")) { effect.SetValue("g_normal", TgcParserUtils.vector3ToFloat3Array(new Vector3(1, 0, 0))); effect.SetValue("g_tangent", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 0, 1))); effect.SetValue("g_binormal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 1, 0))); nro_textura = 1; } else if (mesh.Name.Contains("West")) { effect.SetValue("g_normal", TgcParserUtils.vector3ToFloat3Array(new Vector3(-1, 0, 0))); effect.SetValue("g_tangent", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 0, 1))); effect.SetValue("g_binormal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 1, 0))); nro_textura = 1; } else if (mesh.Name.Contains("North")) { effect.SetValue("g_normal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 0, -1))); effect.SetValue("g_tangent", TgcParserUtils.vector3ToFloat3Array(new Vector3(1, 0, 0))); effect.SetValue("g_binormal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 1, 0))); nro_textura = 1; } else if (mesh.Name.Contains("South")) { effect.SetValue("g_normal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 0, 1))); effect.SetValue("g_tangent", TgcParserUtils.vector3ToFloat3Array(new Vector3(1, 0, 0))); effect.SetValue("g_binormal", TgcParserUtils.vector3ToFloat3Array(new Vector3(0, 1, 0))); nro_textura = 1; } switch (nro_textura) { case 0: default: effect.SetValue("aux_Tex", g_pBaseTexture); effect.SetValue("height_map", g_pHeightmap); break; case 1: effect.SetValue("aux_Tex", g_pBaseTexture2); effect.SetValue("height_map", g_pHeightmap2); break; case 2: effect.SetValue("aux_Tex", g_pBaseTexture3); effect.SetValue("height_map", g_pHeightmap3); break; case 3: effect.SetValue("aux_Tex", g_pBaseTexture4); effect.SetValue("height_map", g_pHeightmap4); break; } if (va) { mesh.Technique = "ParallaxOcclusion2"; mesh.render(); } } //Render personames enemigos foreach (TgcSkeletalMesh m in enemigos) { m.render(); } // Render hud renderHUD(); gui.trapezoidal_style = false; //radar de proximidad float max_dist = 80; foreach (TgcSkeletalMesh m in enemigos) { Vector3 pos_personaje = GuiController.Instance.FpsCamera.getPosition(); Vector3 pos_enemigo = m.Position * 1; float dist = (pos_personaje - pos_enemigo).Length(); if (dist < max_dist) { pos_enemigo.Y = m.BoundingBox.PMax.Y * 0.75f + m.BoundingBox.PMin.Y * 0.25f; pos_enemigo.Project(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World); if (pos_enemigo.Z > 0 && pos_enemigo.Z < 1) { float an = (max_dist - dist) / max_dist * 3.1415f * 2.0f; int d = (int)dist; gui.DrawArc(new Vector2(pos_enemigo.X + 20, pos_enemigo.Y), 40, 0, an, 10, dist < 30 ? Color.Tomato : Color.WhiteSmoke); gui.DrawLine(pos_enemigo.X, pos_enemigo.Y, pos_enemigo.X + 20, pos_enemigo.Y, 3, Color.PowderBlue); gui.DrawLine(pos_enemigo.X + 20, pos_enemigo.Y, pos_enemigo.X + 40, pos_enemigo.Y - 20, 3, Color.PowderBlue); gui.TextOut((int)pos_enemigo.X + 50, (int)pos_enemigo.Y - 20, "Proximidad " + d, Color.PowderBlue); } } } gui.trapezoidal_style = true; device.EndScene(); }