/// <summary> /// The initialize graphics. /// </summary> /// <returns>The initialize graphics.</returns> /// <remarks></remarks> public bool InitializeGraphics() { // try // { render.CreateDevice(this); pc = new PortalContainer(portals, ref render.device); BSPModel.BSPDisplayedInfo.CreateVertexBuffers(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.CreateIndexBuffers(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.LoadShaderTextures(ref render.device, ref bsp); System.Drawing.Font systemfont = new System.Drawing.Font("Arial", 12f, FontStyle.Regular); text = new Font(render.device, systemfont); cam = new Camera2(this); cam.speed = 0.05f; // cam.fixedrotation = true; return true; // } // catch (DirectXException) // { // Catch any errors and return a failure // return false; // } }
/// <summary> /// The draw. /// </summary> /// <param name="device">The device.</param> /// <param name="bsp">The bsp.</param> /// <param name="Textured">The textured.</param> /// <param name="cam">The cam.</param> /// <param name="shaderx">The shaderx.</param> /// <remarks></remarks> public static void Draw( ref Device device, ref BSPModel bsp, bool Textured, ref Camera2 cam, DXShader shaderx) { Optimization opt = new Optimization(device); int count = 0; for (int x = 0; x < bsp.BSPRawDataMetaChunks.Length; x++) { // Check if we are to render chunk if (!bsp.BSPRawDataMetaChunks[x].render) continue; int rawindex = x; // FaceCount is set to 0 when BSP sections are unselected if (bsp.BSPRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0 || bsp.BSPRawDataMetaChunks[rawindex].FaceCount == 0) { continue; } if (bsp.cameraCulling && !opt.IsInViewFrustum(bsp.BSPRawDataMetaChunks[rawindex])) continue; device.SetStreamSource(0, bsp.Display.vertexBuffer[rawindex], 0); device.VertexFormat = HaloBSPVertex.FVF; device.Indices = bsp.Display.indexBuffer[rawindex]; for (int xx = 0; xx < bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo.Length; xx++) { ResetTextureStates(ref device); int tempshade = bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].ShaderNumber; #region AlphaBlending Renderer.SetAlphaBlending(bsp.Shaders.Shader[tempshade].Alpha, ref device); #endregion #region ChooseTexture if (Textured) { if (bsp.Shaders.Shader[tempshade].MainName.IndexOf("water!") != -1) { for (int u = 0; u < bsp.Shaders.Shader[tempshade].BitmapTextures.Length; u++) { if (bsp.Shaders.Shader[tempshade].BitmapNames[u].IndexOf("reflection") != -1 || bsp.Shaders.Shader[tempshade].BitmapNames[u].IndexOf("mask") != -1) { device.SetTexture(0, bsp.Shaders.Shader[tempshade].BitmapTextures[u]); if (bsp.Shaders.Shader[tempshade].MainName.IndexOf("mip") != -1) { device.SetTexture(0, bsp.Shaders.Shader[tempshade].BitmapTextures[u]); device.SetTexture(1, bsp.Shaders.Shader[tempshade].BitmapTextures[u]); } else { device.SetTexture(1, bsp.Shaders.Shader[tempshade].MainTexture); } device.TextureState[0].ColorOperation = TextureOperation.BumpEnvironmentMap; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorArgument2 = TextureArgument.Current; float r = 0.07F; device.TextureState[0].BumpEnvironmentMaterial00 = r * (float) Math.Cos( (Environment.TickCount / 4) * 11.0F); device.TextureState[0].BumpEnvironmentMaterial01 = -r * (float) Math.Sin( (Environment.TickCount / 4) * 11.0F); device.TextureState[0].BumpEnvironmentMaterial10 = r * (float) Math.Sin( (Environment.TickCount / 4) * 11.0F); device.TextureState[0].BumpEnvironmentMaterial11 = r * (float) Math.Cos( (Environment.TickCount / 4) * 11.0F); device.TextureState[1].ColorOperation = TextureOperation.Modulate; device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[1].ColorArgument2 = TextureArgument.Current; if (bsp.LightMapTexture[x] != null && bsp.BSPRawDataMetaChunks[x].LightMapUVs.Count != 0) { // device.SetTexture(2, bsp.LightMapTexture[x]); // device.TextureState[2].ColorOperation = TextureOperation.Modulate2X; // device.TextureState[2].ColorArgument1 = TextureArgument.TextureColor; // device.TextureState[2].ColorArgument2 = TextureArgument.Current; } break; } if (u == bsp.Shaders.Shader[tempshade].BitmapTextures.Length - 1) { device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture); device.TextureState[0].ColorOperation = TextureOperation.Modulate; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorArgument2 = TextureArgument.Current; } } } else if (bsp.Shaders.Shader[tempshade].MainName.IndexOf("ground!") != -1) { if (bsp.Shaders.Shader[tempshade].MainName.IndexOf("unwrapped") != -1) { // device.SamplerState[0].AddressU = TextureAddress.Clamp; // device.SamplerState[0].AddressV = TextureAddress.Clamp; } device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture); device.TextureState[0].ColorOperation = TextureOperation.Modulate; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorArgument2 = TextureArgument.Current; device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1; device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; // device.TextureState[0].ResultArgument = TextureArgument.Current; device.TextureState[1].TextureTransform = TextureTransform.Count2; device.Transform.Texture1 = Matrix.Scaling( bsp.Shaders.Shader[tempshade].primarydetailuscale, bsp.Shaders.Shader[tempshade].primarydetailvscale, bsp.Shaders.Shader[tempshade].primarydetailwscale); // device.Transform.Texture1 = Matrix.Scaling(bsp.Shaders.Shader[tempshade].secondarydetailuscale, bsp.Shaders.Shader[tempshade].secondarydetailvscale, bsp.Shaders.Shader[tempshade].secondarydetailwscale); device.SetTexture(1, bsp.Shaders.Shader[tempshade].BitmapTextures[2]); device.TextureState[1].ColorOperation = TextureOperation.Modulate2X; device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[1].ColorArgument2 = TextureArgument.Current; device.TextureState[1].AlphaOperation = TextureOperation.Add; device.TextureState[1].AlphaArgument1 = TextureArgument.Current; device.TextureState[2].TextureTransform = TextureTransform.Count2; device.Transform.Texture2 = Matrix.Scaling( bsp.Shaders.Shader[tempshade].secondarydetailuscale, bsp.Shaders.Shader[tempshade].secondarydetailvscale, bsp.Shaders.Shader[tempshade].secondarydetailwscale); device.SetTexture(2, bsp.Shaders.Shader[tempshade].BitmapTextures[3]); device.TextureState[2].ColorOperation = TextureOperation.Modulate2X; device.TextureState[2].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[2].ColorArgument2 = TextureArgument.Current; device.TextureState[2].TextureCoordinateIndex = 3; if (bsp.LightMapTexture[x] != null && bsp.BSPRawDataMetaChunks[x].LightMapUVs.Count != 0) { device.SetTexture(3, bsp.LightMapTexture[x]); device.TextureState[3].ColorOperation = TextureOperation.Modulate2X; device.TextureState[3].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[3].ColorArgument2 = TextureArgument.Current; device.TextureState[3].TextureCoordinateIndex = 2; } } else { device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture); device.TextureState[0].ColorOperation = TextureOperation.Modulate; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorArgument2 = TextureArgument.Current; device.TextureState[0].AlphaOperation = TextureOperation.BlendTextureAlpha; device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse; /* if (bsp.Shaders.Shader[tempshade].microdetailName != null) { device.TextureState[1].TextureTransform = TextureTransform.Count2; device.Transform.Texture1 = Matrix.Scaling(bsp.Shaders.Shader[tempshade].microdetailuscale, bsp.Shaders.Shader[tempshade].microdetailvscale, bsp.Shaders.Shader[tempshade].microdetailwscale); device.SetTexture(1, bsp.Shaders.Shader[tempshade].microdetailTexture); device.TextureState[1].ColorOperation = TextureOperation.Modulate2X; device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[1].ColorArgument2 = TextureArgument.Current; device.TextureState[1].AlphaOperation = TextureOperation.BlendCurrentAlpha; device.TextureState[1].AlphaArgument1 = TextureArgument.Current; } if (bsp.Shaders.Shader[tempshade].primarydetailTexture != null) { device.TextureState[1].TextureTransform = TextureTransform.Count2; device.Transform.Texture1 = Matrix.Scaling(bsp.Shaders.Shader[tempshade].primarydetailuscale, bsp.Shaders.Shader[tempshade].primarydetailvscale, bsp.Shaders.Shader[tempshade].primarydetailwscale); device.SetTexture(1, bsp.Shaders.Shader[tempshade].primarydetailTexture); device.TextureState[1].ColorOperation = TextureOperation.Lerp; device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[1].ColorArgument2 = TextureArgument.Current; device.TextureState[1].AlphaOperation = TextureOperation.Modulate; device.TextureState[1].AlphaArgument1 = TextureArgument.TextureColor; } if (bsp.Shaders.Shader[tempshade].secondarydetailTexture != null) { device.TextureState[2].TextureTransform = TextureTransform.Count2; device.Transform.Texture2 = Matrix.Scaling(bsp.Shaders.Shader[tempshade].secondarydetailuscale, bsp.Shaders.Shader[tempshade].secondarydetailvscale, bsp.Shaders.Shader[tempshade].secondarydetailwscale); device.SetTexture(2, bsp.Shaders.Shader[tempshade].secondarydetailTexture); device.TextureState[2].ColorOperation = TextureOperation.Lerp; device.TextureState[2].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[2].ColorArgument2 = TextureArgument.Current; device.TextureState[2].TextureCoordinateIndex = 3; //device.TextureState[2].AlphaOperation = TextureOperation.BlendCurrentAlpha; //device.TextureState[1].AlphaArgument1 = TextureArgument.Current; } */ if (bsp.LightMapTexture != null) { if (bsp.LightMapTexture[x] != null && bsp.BSPRawDataMetaChunks[x].LightMapUVs.Count != 0 && bsp.RenderBSPLighting) { device.SetTexture(1, bsp.LightMapTexture[x]); device.TextureState[1].ColorOperation = TextureOperation.Modulate2X; device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[1].ColorArgument2 = TextureArgument.Current; device.TextureState[1].TextureCoordinateIndex = 2; } } } } else { // If not Textured device.SetTexture(0, null); device.SetTexture(1, null); if (bsp.LightMapTexture != null) { if (bsp.LightMapTexture[x] != null && bsp.BSPRawDataMetaChunks[x].LightMapUVs.Count != 0 && bsp.RenderBSPLighting) { device.SetTexture(0, bsp.LightMapTexture[x]); device.TextureState[0].ColorOperation = TextureOperation.Modulate2X; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorArgument2 = TextureArgument.Current; device.TextureState[0].TextureCoordinateIndex = 2; } } } #endregion PrimitiveType pt; // if (bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount != (bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount/3)*3) if (bsp.BSPRawDataMetaChunks[rawindex].FaceCount * 3 != bsp.BSPRawDataMetaChunks[rawindex].IndiceCount) { pt = PrimitiveType.TriangleStrip; device.RenderState.FillMode = FillMode.Solid; Material mm = new Material(); mm.Diffuse = Color.White; mm.Ambient = Color.White; // if (x == 1) { mm.Diffuse = System.Drawing.Color.Red; mm.Ambient = System.Drawing.Color.Red; } device.Material = mm; device.DrawIndexedPrimitives( pt, 0, 0, bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount); } else { count++; pt = PrimitiveType.TriangleList; device.RenderState.FillMode = FillMode.Solid; Material mm = new Material(); mm.Diffuse = Color.White; mm.Ambient = Color.White; // if (x == 1) { mm.Diffuse = System.Drawing.Color.Red; mm.Ambient = System.Drawing.Color.Red; } device.Material = mm; device.DrawIndexedPrimitives( pt, 0, 0, bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3); } #region RenderToScene #region WireFrame if (Textured == false) { Material m = new Material(); m.Diffuse = Color.Black; m.Ambient = Color.Black; device.Material = m; device.RenderState.FillMode = FillMode.WireFrame; device.DrawIndexedPrimitives( pt, 0, 0, bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3); } #endregion #endregion } } #region BSPPermutationMesh if (bsp.DrawBSPPermutations) { for (int x = 0; x < bsp.PermutationInfo.Length; x++) { // continue; int rawindex = bsp.PermutationInfo[x].sceneryIndex; if (bsp.BSPPermutationRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0) { continue; } device.Transform.World = bsp.PermutationInfo[x].mat; device.SetStreamSource(0, bsp.Display.permvertexBuffer[rawindex], 0); device.VertexFormat = HaloVertex.FVF; device.Indices = bsp.Display.permindexBuffer[rawindex]; for (int xx = 0; xx < bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo.Length; xx++) { ResetTextureStates(ref device); int tempshade = bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].ShaderNumber; #region AlphaBlending if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaBlend) { device.RenderState.AlphaBlendEnable = true; device.RenderState.AlphaTestEnable = false; } else if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaTest) { device.RenderState.AlphaBlendEnable = false; device.RenderState.AlphaTestEnable = true; } else { device.RenderState.AlphaBlendEnable = false; device.RenderState.AlphaTestEnable = false; } #endregion #region ChooseTexture device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture); device.TextureState[0].ColorOperation = TextureOperation.Modulate; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorArgument2 = TextureArgument.Current; // device.SetTexture(1, bsp.Shaders.Shader[tempshade].BumpMapTexture); // device.TextureState[1].ColorOperation = TextureOperation.BumpEnvironmentMap; // device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor; // device.TextureState[1].ColorArgument2 = TextureArgument.Current; if (bsp.SceneryLightMapTexture != null) { if (bsp.SceneryLightMapTexture[x] != null && bsp.BSPPermutationRawDataMetaChunks[rawindex].LightMapUVs.Count != 0) { device.SetTexture(1, bsp.SceneryLightMapTexture[x]); device.TextureState[1].ColorOperation = TextureOperation.Modulate; device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[1].ColorArgument2 = TextureArgument.Current; device.TextureState[1].TextureCoordinateIndex = 2; } else { // device.TextureState[0].ColorOperation = TextureOperation.Disable; device.TextureState[0].ColorOperation = TextureOperation.Modulate2X; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorArgument2 = TextureArgument.Current; } } #endregion #region RenderToScene PrimitiveType pt; pt = PrimitiveType.TriangleList; device.RenderState.FillMode = FillMode.Solid; Material mm = new Material(); mm.Diffuse = Color.White; mm.Ambient = Color.White; device.Material = mm; device.DrawIndexedPrimitives( pt, 0, 0, bsp.BSPPermutationRawDataMetaChunks[rawindex].VerticeCount, bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3); #region WireFrame if (Textured == false) { Material m = new Material(); m.Diffuse = Color.Red; m.Ambient = Color.Red; device.Material = m; device.RenderState.FillMode = FillMode.WireFrame; device.DrawIndexedPrimitives( pt, 0, 0, bsp.BSPPermutationRawDataMetaChunks[rawindex].VerticeCount, bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, bsp.BSPPermutationRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3); } #endregion #endregion } } } #endregion ResetTextureStates(ref device); }
/// <summary> /// The draw cluster. /// </summary> /// <param name="rawindex">The rawindex.</param> /// <param name="outlinecolor">The outlinecolor.</param> /// <param name="device">The device.</param> /// <param name="bsp">The bsp.</param> /// <param name="Textured">The textured.</param> /// <param name="WireFrame">The wire frame.</param> /// <param name="cam">The cam.</param> /// <remarks></remarks> public static void DrawCluster( int rawindex, Color outlinecolor, ref Device device, ref BSPModel bsp, bool Textured, bool WireFrame, ref Camera2 cam) { if (bsp.BSPRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0) { return; } // Vector3 tempv = new Vector3(); // tempv.X = bsp.Spawns.Spawn[x].X; // tempv.Y = bsp.Spawns.Spawn[x].Y; // tempv.Z = bsp.Spawns.Spawn[x].Z; // if (!cam.SphereInFrustum(tempv, 10f)) { continue; } device.SetStreamSource(0, bsp.Display.vertexBuffer[rawindex], 0); device.VertexFormat = CustomVertex.PositionNormalTextured.Format; device.Indices = bsp.Display.indexBuffer[rawindex]; for (int xx = 0; xx < bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo.Length; xx++) { int tempshade = bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].ShaderNumber; #region AlphaBlending if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaBlend) { // MessageBox.Show("test"); device.RenderState.AlphaBlendEnable = true; device.RenderState.AlphaTestEnable = false; } else if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaTest) { // MessageBox.Show("test2"); device.RenderState.AlphaBlendEnable = false; device.RenderState.AlphaTestEnable = true; } else { device.RenderState.AlphaBlendEnable = false; device.RenderState.AlphaTestEnable = false; } #endregion #region ChooseTexture if (Textured) { // device.TextureState[0] = device.TextureState[2]; device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture); } else { device.SetTexture(0, null); } #endregion #region RenderToScene PrimitiveType pt; pt = PrimitiveType.TriangleList; device.RenderState.FillMode = FillMode.Solid; Material mm = new Material(); mm.Diffuse = Color.Black; mm.Ambient = Color.Black; device.Material = mm; device.DrawIndexedPrimitives( pt, 0, 0, bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3); #region WireFrame if (WireFrame) { Material m = new Material(); m.Diffuse = outlinecolor; m.Ambient = outlinecolor; device.Material = m; device.RenderState.FillMode = FillMode.WireFrame; device.DrawIndexedPrimitives( pt, 0, 0, bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3); } #endregion #endregion } }
/// <summary> /// The main entry point for the application. /// </summary> /// <remarks></remarks> public void Main() { using (CollisionViewer frm = this) { if (!frm.InitializeGraphics()) { // Initialize Direct3D MessageBox.Show("Could not initialize Direct3D. This tutorial will exit."); return; } frm.Show(); frm.Focus(); cam = new Camera2(this); // Camera(device); cam.speed = 0.30f; // While the form is still valid, render and process messages while (frm.Created) { frm.Render(); frm.checkKeys(); Application.DoEvents(); } } }
/// <summary> /// The main entry point for the application. /// </summary> /// <remarks></remarks> public void Main() { using (BSPViewer frm = this) { if (!frm.InitializeGraphics()) { // Initialize Direct3D MessageBox.Show("Could not initialize Direct3D. This tutorial will exit."); return; } frm.Show(); frm.Focus(); cam = new Camera2(this); // Camera(device); // Position the camera at the center of the map setCameraPosition( (bsp.maxBoundries.X - bsp.minBoundries.X) / 2 + bsp.minBoundries.X, (bsp.maxBoundries.Y - bsp.minBoundries.Y) / 2 + bsp.minBoundries.Y, (bsp.maxBoundries.Z - bsp.minBoundries.Z) / 2 + bsp.minBoundries.Z, false); //cam.AimCamera(new Vector3(cam.x, cam.y - 15f, cam.z + 0.25f)); //cam.ComputePosition(); aspect = this.Width / (float)this.Height; this.speedBar_Update(); // While the form is still valid, render and process messages while (frm.Created) { if (NoCulling.Checked) { render.device.RenderState.CullMode = Cull.None; } else { render.device.RenderState.CullMode = Cull.Clockwise; } frm.Render(); Application.DoEvents(); GC.Collect(0); GC.WaitForPendingFinalizers(); GC.Collect(0); // System.Threading.Thread.Sleep(100); } } }
/// <summary> /// The initialize graphics. /// </summary> /// <returns>The initialize graphics.</returns> /// <remarks></remarks> public bool InitializeGraphics() { // try // { render.CreateDevice(this); ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref render.device, ref pm); cam = new Camera2(this); cam.speed = 0.005f; cam.Position.X = 0.5741551f; cam.Position.Y = 0.01331316f; cam.Position.Z = 0.4271703f; cam.radianv = 6.161014f; cam.radianh = 3.14159f; cam.x = 0.5741551f; cam.y = 0.01331316f; cam.z = 0.4271703f; cam.ComputePosition(); m1 = new Material(); m1.Diffuse = Color.White; m1.Ambient = Color.White; m1.Specular = Color.White; return true; // } // catch (DirectXException) // { // Catch any errors and return a failure // return false; // } }
/// <summary> /// The main entry point for the application. /// </summary> /// <remarks></remarks> public void Main() { using (BSPCollisionViewer frm = this) { if (!frm.InitializeGraphics()) { // Initialize Direct3D MessageBox.Show("Could not initialize Direct3D. This tutorial will exit."); return; } TranslationMatrix = new Matrix[coll.Vertices.Length]; for (int i = 0; i < coll.Vertices.Length; i++) { Matrix m = Matrix.Identity; m.Multiply(Matrix.Translation(coll.Vertices[i].X, coll.Vertices[i].Y, coll.Vertices[i].Z)); TranslationMatrix[i] = m; } frm.Show(); frm.Focus(); cam = new Camera2(this); // Camera(device); // While the form is still valid, render and process messages while (frm.Created) { frm.Render(); Application.DoEvents(); } } }
/// <summary> /// The initialize graphics. /// </summary> /// <returns>The initialize graphics.</returns> /// <remarks></remarks> public bool InitializeGraphics() { // try // { render.CreateDevice(this); //pc = new LightmapContainer(null, ref render.device); BSPModel.BSPDisplayedInfo.CreateVertexBuffers(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.CreateIndexBuffers(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.LoadShaderTextures(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.LoadLightmapTextures(ref render.device, ref bsp); System.Drawing.Font systemfont = new System.Drawing.Font("Arial", 12f, FontStyle.Regular); text = new Font(render.device, systemfont); cam = new Camera2(this); cam.speed = 0.30f; // cam.fixedrotation = true; bspMeshes = new Mesh[bsp.BSPPermutationRawDataMetaChunks.Length]; //GraphicsStream vertexData; for (int x = 0; x < bsp.BSPPermutationRawDataMetaChunks.Length; x++) { BSPModel.BSPPermutationRawDataMetaChunk tempChunk = bsp.BSPPermutationRawDataMetaChunks[x]; // Compute the bounding box for a mesh. // VertexBufferDescription description = bsp.Display.vertexBuffer[x].Description; // vertexData = bsp.Display.vertexBuffer[x].Lock(0, 0, LockFlags.ReadOnly); /* Geometry.ComputeBoundingBox(vertexData, meshes[i].NumberVertices, description.VertexFormat, out meshBoundingBoxMinValues[i], out meshBoundingBoxMaxValues[i]); bsp.Display.vertexBuffer[x].Unlock(); bspMeshes[x] = new Mesh(tempChunk.FaceCount, tempChunk.VerticeCount, MeshFlags.Dynamic, bsp.Display.vertexBuffer[x], render.device); // bspMeshes[x] = Mesh.Box(render.device, .BoundingBox.MaxX - bsp.BSPPermutationRawDataMetaChunks[x].BoundingBox.MinX, // bsp.BSPPermutationRawDataMetaChunks[x].BoundingBox.MaxY - bsp.BSPPermutationRawDataMetaChunks[x].BoundingBox.MinY, // bsp.BSPPermutationRawDataMetaChunks[x].BoundingBox.MaxZ - bsp.BSPPermutationRawDataMetaChunks[x].BoundingBox.MinZ); */ } return true; // } // catch (DirectXException) // { // Catch any errors and return a failure // return false; // } }