From af9c782c1e78a256d71e838463c68273fc0fab1c Mon Sep 17 00:00:00 2001 From: Troispoils Date: Sun, 3 Mar 2024 20:07:40 +0100 Subject: [PATCH] MAJ --- .../LandBlockExtractor/LandBlockExtrator.cs | 53 ++++++------------- Map3DRendering/Common/Camera.cs | 2 +- Map3DRendering/MapRender.cs | 3 +- 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/LandblockExtraction/LandBlockExtractor/LandBlockExtrator.cs b/LandblockExtraction/LandBlockExtractor/LandBlockExtrator.cs index 664456f..d74b6a9 100644 --- a/LandblockExtraction/LandBlockExtractor/LandBlockExtrator.cs +++ b/LandblockExtraction/LandBlockExtractor/LandBlockExtrator.cs @@ -41,18 +41,18 @@ namespace LandblockExtraction.LandBlockExtractor { var indice = y * BlockSize + x; blockStruct.verticesStruct.position[indice] = GenerateVertexPosition(landX, landY, x, y, blockData.heights[indice]); blockStruct.indices = indiceBase; - //blockStruct.verticesStruct.color[indice] = GenerateVertexColor(blockData.cellInfos[indice]); - //blockStruct.verticesStruct.farcolor[indice] = GenerateVertexFarColor(blockData.cellInfos[indice]); + blockStruct.verticesStruct.color[indice] = GenerateVertexColor(blockData.cellInfos[indice]); + blockStruct.verticesStruct.farcolor[indice] = GenerateVertexFarColor(blockData.cellInfos[indice]); blockStruct.verticesStruct.terraintype[indice] = GenerateVertexTerrainType(blockData.cellInfos[indice]); } } - GenerateBasicNormalandRighTexture(blockStruct); + GenerateBasicNormal(blockStruct); DoubleEdgeVertices(blockStruct); return blockStruct; } - private void GenerateBasicNormalandRighTexture(BlockStruct blockStruct) { + private void GenerateBasicNormal(BlockStruct blockStruct) { for (int i = 0; i < blockStruct.indices.Length; i += 6) { int index1 = blockStruct.indices[i]; int index2 = blockStruct.indices[i + 1]; @@ -66,25 +66,12 @@ namespace LandblockExtraction.LandBlockExtractor { var normal = MathOperations.CalculateQuadNormal(vertex1, vertex2, vertex3, vertex4); - var sub1 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index1].X].DetermineSubTerrain(1 - normal.Y); - var sub2 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index2].X].DetermineSubTerrain(1 - normal.Y); - var sub3 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index3].X].DetermineSubTerrain(1 - normal.Y); - var sub4 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index4].X].DetermineSubTerrain(1 - normal.Y); - - InitColorFarColorTerrain(index1, sub1, blockStruct); - InitColorFarColorTerrain(index2, sub2, blockStruct); - InitColorFarColorTerrain(index3, sub3, blockStruct); - InitColorFarColorTerrain(index4, sub4, blockStruct); + blockStruct.verticesStruct.normal[index1] = normal; + blockStruct.verticesStruct.normal[index2] = normal; + blockStruct.verticesStruct.normal[index3] = normal; + blockStruct.verticesStruct.normal[index4] = normal; } } - - private void InitColorFarColorTerrain(int index, SubTerrain terrain, BlockStruct blockStruct) { - blockStruct.verticesStruct.terraintype[index].X = terrain.terrainIndex; - blockStruct.verticesStruct.color[index] = terrain.Color; - blockStruct.verticesStruct.farcolor[index] = terrain.farColor; - } - - private int[] GenerateBasicIndices() { List indices = new List(); @@ -170,48 +157,42 @@ namespace LandblockExtraction.LandBlockExtractor { var one = blockStruct.indices[i + 0]; var two = blockStruct.indices[i + 1]; var three = blockStruct.indices[i + 2]; - var foor = blockStruct.indices[i + 5]; + var four = blockStruct.indices[i + 5]; Vector4 terrainType = new Vector4(blockStruct.verticesStruct.terraintype[one].X, blockStruct.verticesStruct.terraintype[two].X, blockStruct.verticesStruct.terraintype[three].X, - blockStruct.verticesStruct.terraintype[foor].X); + blockStruct.verticesStruct.terraintype[four].X); newPositions.Add(blockStruct.verticesStruct.position[one]); newColors.Add(blockStruct.verticesStruct.color[one]); newFarColors.Add(blockStruct.verticesStruct.farcolor[one]); + newNormals.Add(blockStruct.verticesStruct.normal[one]); newTerrainTypes.Add(terrainType); newPositions.Add(blockStruct.verticesStruct.position[two]); newColors.Add(blockStruct.verticesStruct.color[two]); newFarColors.Add(blockStruct.verticesStruct.farcolor[two]); + newNormals.Add(blockStruct.verticesStruct.normal[two]); newTerrainTypes.Add(terrainType); newPositions.Add(blockStruct.verticesStruct.position[three]); newColors.Add(blockStruct.verticesStruct.color[three]); newFarColors.Add(blockStruct.verticesStruct.farcolor[three]); + newNormals.Add(blockStruct.verticesStruct.normal[three]); newTerrainTypes.Add(terrainType); - newPositions.Add(blockStruct.verticesStruct.position[foor]); - newColors.Add(blockStruct.verticesStruct.color[foor]); - newFarColors.Add(blockStruct.verticesStruct.farcolor[foor]); + newPositions.Add(blockStruct.verticesStruct.position[four]); + newColors.Add(blockStruct.verticesStruct.color[four]); + newFarColors.Add(blockStruct.verticesStruct.farcolor[four]); + newNormals.Add(blockStruct.verticesStruct.normal[four]); newTerrainTypes.Add(terrainType); newTexCoord.Add(new(0, 0)); newTexCoord.Add(new(0, 1)); newTexCoord.Add(new(1, 0)); newTexCoord.Add(new(1, 1)); - - var normal = MathOperations.CalculateQuadNormal(blockStruct.verticesStruct.position[one], - blockStruct.verticesStruct.position[two], - blockStruct.verticesStruct.position[three], - blockStruct.verticesStruct.position[foor]); - - newNormals.Add(normal); - newNormals.Add(normal); - newNormals.Add(normal); - newNormals.Add(normal); } // Ajouter les nouveaux sommets à la structure BlockStruct (étape 2) diff --git a/Map3DRendering/Common/Camera.cs b/Map3DRendering/Common/Camera.cs index 8ab50aa..6084f37 100644 --- a/Map3DRendering/Common/Camera.cs +++ b/Map3DRendering/Common/Camera.cs @@ -83,7 +83,7 @@ namespace Map3DRendering.Common { // Get the projection matrix using the same method we have used up until this point public Matrix4 GetProjectionMatrix() { - return Matrix4.CreatePerspectiveFieldOfView(_fov, AspectRatio, 0.01f, 1000f); + return Matrix4.CreatePerspectiveFieldOfView(_fov, AspectRatio, 0.01f, 5000f); } // This function is going to update the direction vertices using some of the math learned in the web tutorials. diff --git a/Map3DRendering/MapRender.cs b/Map3DRendering/MapRender.cs index 1434eaf..b991212 100644 --- a/Map3DRendering/MapRender.cs +++ b/Map3DRendering/MapRender.cs @@ -15,7 +15,7 @@ namespace Map3DRendering { private readonly int BlockSize = 17; private readonly int allBlocks = 255 * 17 * 255 * 17; private readonly int cellSize = 8; - private readonly int radius = 0x5; // Rayon du voisinage + private readonly int radius = 0x10; // Rayon du voisinage public int[,] _vertexArrayObject; public int[,] _vertexBufferObject; @@ -44,7 +44,6 @@ namespace Map3DRendering { CalculeRadius(currentLandBlockX, currentLandBlockY); } - public int GetIndiceLenght() { return (17 - 1) * (17 - 1) * 6; //Always that. }