private PositionTexture Midpoint(PositionTexture positionNormalTextured, PositionTexture positionNormalTextured_2) { var a1 = Vector3d.Lerp(positionNormalTextured.Position, positionNormalTextured_2.Position, .5f); var a1uv = Vector2d.Lerp(new Vector2d(positionNormalTextured.Tu, positionNormalTextured.Tv), new Vector2d(positionNormalTextured_2.Tu, positionNormalTextured_2.Tv), .5f); a1.Normalize(); return new PositionTexture(a1, a1uv.X, a1uv.Y); }
internal PositionNormalTexturedX2 GetMappedVertex(PositionTexture vert) { var vertOut = new PositionNormalTexturedX2(); var latLng = Coordinates.CartesianToSpherical2(vert.Position); // latLng.Lng += 90; if (latLng.Lng < -180) { latLng.Lng += 360; } if (latLng.Lng > 180) { latLng.Lng -= 360; } //if (false) //{ //// System.Diagnostics.Debug.WriteLine(String.Format("{0},{1}", (int)(vert.Tu * 16 + .5), (int)(vert.Tv * 16 + .5))); //} if (level > 1) { var arrayX = (byte)(int)(vert.Tu * 16 + .5); var arrayY = (byte)(int)(vert.Tv * 16 + .5); demArray[arrayX + arrayY * 17] = DemData[demIndex]; if (backslash) { if (tempBackslashYIndex != null) { tempBackslashXIndex[demIndex] = arrayX; tempBackslashYIndex[demIndex] = arrayY; } } else { if (tempSlashYIndex != null) { tempSlashXIndex[demIndex] = arrayX; tempSlashYIndex[demIndex] = arrayY; } } } var pos = GeoTo3dWithAltitude(latLng.Lat, latLng.Lng, false); vertOut.Tu = (float) vert.Tu; vertOut.Tv = (float) vert.Tv; vertOut.Lat = latLng.Lat; vertOut.Lng = latLng.Lng; vertOut.Normal = pos; pos = pos - localCenter; vertOut.Position = pos; return vertOut; }
private void InitializeGrids() { vertexList = BufferPool11.GetPositionTextureList(); for (var i = 0; i < 4; i++) { if (childTriangleList[i] != null) { childTriangleList[i].Clear(); } else { childTriangleList[i] = BufferPool11.GetTriagleList(); } } bounds = new PositionTexture[3, 3]; if (level > 0) { var parent = Parent as ToastTile; if (parent == null) { return; } var xIndex = x % 2; var yIndex = y % 2; if (level > 1) { backslash = parent.backslash; } else { backslash = xIndex == 1 ^ yIndex == 1; } bounds[0, 0] = parent.bounds[xIndex, yIndex]; bounds[1, 0] = Midpoint(parent.bounds[xIndex, yIndex], parent.bounds[xIndex + 1, yIndex]); bounds[2, 0] = parent.bounds[xIndex + 1, yIndex]; bounds[0, 1] = Midpoint(parent.bounds[xIndex, yIndex], parent.bounds[xIndex, yIndex + 1]); if (backslash) { bounds[1, 1] = Midpoint(parent.bounds[xIndex, yIndex], parent.bounds[xIndex + 1, yIndex + 1]); } else { bounds[1, 1] = Midpoint(parent.bounds[xIndex + 1, yIndex], parent.bounds[xIndex, yIndex + 1]); } bounds[2, 1] = Midpoint(parent.bounds[xIndex + 1, yIndex], parent.bounds[xIndex + 1, yIndex + 1]); bounds[0, 2] = parent.bounds[xIndex, yIndex + 1]; bounds[1, 2] = Midpoint(parent.bounds[xIndex, yIndex + 1], parent.bounds[xIndex + 1, yIndex + 1]); bounds[2, 2] = parent.bounds[xIndex + 1, yIndex + 1]; if (Properties.Settings.Default.ShowElevationModel) { bounds[0, 0].Tu = 0 ; bounds[0, 0].Tv = 0 ; bounds[1, 0].Tu = .5f; bounds[1, 0].Tv = 0; bounds[2, 0].Tu = 1; bounds[2, 0].Tv = 0; bounds[0, 1].Tu = 0 ; bounds[0, 1].Tv = .5f; bounds[1, 1].Tu = .5f; bounds[1, 1].Tv = .5f; bounds[2, 1].Tu = 1 ; bounds[2, 1].Tv = .5f; bounds[0, 2].Tu = 0 ; bounds[0, 2].Tv = 1 ; bounds[1, 2].Tu = .5f ; bounds[1, 2].Tv = 1; bounds[2, 2].Tu = 1; bounds[2, 2].Tv = 1; } else { bounds[0, 0].Tu = 0 + .002f; bounds[0, 0].Tv = 0 + .002f; bounds[1, 0].Tu = .5f + .002f; bounds[1, 0].Tv = 0 + .002f; bounds[2, 0].Tu = 1 + .002f; bounds[2, 0].Tv = 0 + .002f; bounds[0, 1].Tu = 0 + .002f; bounds[0, 1].Tv = .5f + .002f; bounds[1, 1].Tu = .5f + .002f; bounds[1, 1].Tv = .5f + .002f; bounds[2, 1].Tu = 1 + .002f; bounds[2, 1].Tv = .5f + .002f; bounds[0, 2].Tu = 0 + .002f; bounds[0, 2].Tv = 1 + .002f; bounds[1, 2].Tu = .5f + .002f; bounds[1, 2].Tv = 1 + .002f; bounds[2, 2].Tu = 1 + .002f; bounds[2, 2].Tv = 1 + .002f; } vertexList.Add(bounds[0, 0]); vertexList.Add(bounds[1, 0]); vertexList.Add(bounds[2, 0]); vertexList.Add(bounds[0, 1]); vertexList.Add(bounds[1, 1]); vertexList.Add(bounds[2, 1]); vertexList.Add(bounds[0, 2]); vertexList.Add(bounds[1, 2]); vertexList.Add(bounds[2, 2]); if (backslash) { childTriangleList[0].Add(new Triangle(4, 1, 0)); childTriangleList[0].Add(new Triangle(3, 4, 0)); childTriangleList[1].Add(new Triangle(5, 2, 1)); childTriangleList[1].Add(new Triangle(4, 5, 1)); childTriangleList[2].Add(new Triangle(7, 4, 3)); childTriangleList[2].Add(new Triangle(6, 7, 3)); childTriangleList[3].Add(new Triangle(8, 5, 4)); childTriangleList[3].Add(new Triangle(7, 8, 4)); } else { childTriangleList[0].Add(new Triangle(3, 1, 0)); childTriangleList[0].Add(new Triangle(4, 1, 3)); childTriangleList[1].Add(new Triangle(4, 2, 1)); childTriangleList[1].Add(new Triangle(5, 2, 4)); childTriangleList[2].Add(new Triangle(6, 4, 3)); childTriangleList[2].Add(new Triangle(7, 4, 6)); childTriangleList[3].Add(new Triangle(7, 5, 4)); childTriangleList[3].Add(new Triangle(8, 5, 7)); } } else { if (Properties.Settings.Default.ShowElevationModel) { bounds[0, 0] = new PositionTexture(0, -1, 0, 0, 0); bounds[1, 0] = new PositionTexture(0, 0, -1, .5f, 0); bounds[2, 0] = new PositionTexture(0, -1, 0, 1, 0); bounds[0, 1] = new PositionTexture(1, 0, 0, 0, .5f); bounds[1, 1] = new PositionTexture(0, 1, 0, .5f, .5f); bounds[2, 1] = new PositionTexture(-1, 0, 0, 1, .5f); bounds[0, 2] = new PositionTexture(0, -1, 0, 0, 1); bounds[1, 2] = new PositionTexture(0, 0, 1, .5f, 1); bounds[2, 2] = new PositionTexture(0, -1, 0, 1, 1); } else { bounds[0, 0] = new PositionTexture(0, -1, 0, 0 + .002f, 0 + .002f); bounds[1, 0] = new PositionTexture(0, 0, -1, .5f + .002f, 0 + .002f); bounds[2, 0] = new PositionTexture(0, -1, 0, 1 + .002f, 0 + .002f); bounds[0, 1] = new PositionTexture(1, 0, 0, 0 + .002f, .5f + .002f); bounds[1, 1] = new PositionTexture(0, 1, 0, .5f + .002f, .5f + .002f); bounds[2, 1] = new PositionTexture(-1, 0, 0, 1 + .002f, .5f + .002f); bounds[0, 2] = new PositionTexture(0, -1, 0, 0 + .002f, 1 + .002f); bounds[1, 2] = new PositionTexture(0, 0, 1, .5f + .002f, 1 + .002f); bounds[2, 2] = new PositionTexture(0, -1, 0, 1 + .002f, 1 + .002f); } vertexList.Add(bounds[0, 0]); vertexList.Add(bounds[1, 0]); vertexList.Add(bounds[2, 0]); vertexList.Add(bounds[0, 1]); vertexList.Add(bounds[1, 1]); vertexList.Add(bounds[2, 1]); vertexList.Add(bounds[0, 2]); vertexList.Add(bounds[1, 2]); vertexList.Add(bounds[2, 2]); childTriangleList[0].Add(new Triangle(3, 1, 0)); childTriangleList[0].Add(new Triangle(4, 1, 3)); childTriangleList[1].Add(new Triangle(5, 2, 1)); childTriangleList[1].Add(new Triangle(4, 5, 1)); childTriangleList[2].Add(new Triangle(7, 4, 3)); childTriangleList[2].Add(new Triangle(6, 7, 3)); childTriangleList[3].Add(new Triangle(7, 5, 4)); childTriangleList[3].Add(new Triangle(8, 5, 7)); // Setup default matrix of points. } VertexCount = (int)Math.Pow(4, subDivisionLevel) * 2 + 1; }
private void InitializeGrids() { bounds = new PositionTexture[3, 3]; if (Level > 0) { if (Parent == null) { return; } int xIndex = X % 2; int yIndex = Y % 2; if (Level > 1) { backslash = Parent.backslash; } else { backslash = xIndex == 1 ^ yIndex == 1; } bounds[0, 0] = Parent.bounds[xIndex, yIndex]; bounds[1, 0] = Midpoint(Parent.bounds[xIndex, yIndex], Parent.bounds[xIndex + 1, yIndex]); bounds[2, 0] = Parent.bounds[xIndex + 1, yIndex]; bounds[0, 1] = Midpoint(Parent.bounds[xIndex, yIndex], Parent.bounds[xIndex, yIndex + 1]); if (backslash) { bounds[1, 1] = Midpoint(Parent.bounds[xIndex, yIndex], Parent.bounds[xIndex + 1, yIndex + 1]); } else { bounds[1, 1] = Midpoint(Parent.bounds[xIndex + 1, yIndex], Parent.bounds[xIndex, yIndex + 1]); } bounds[2, 1] = Midpoint(Parent.bounds[xIndex + 1, yIndex], Parent.bounds[xIndex + 1, yIndex + 1]); bounds[0, 2] = Parent.bounds[xIndex, yIndex + 1]; bounds[1, 2] = Midpoint(Parent.bounds[xIndex, yIndex + 1], Parent.bounds[xIndex + 1, yIndex + 1]); bounds[2, 2] = Parent.bounds[xIndex + 1, yIndex + 1]; if (Properties.Settings.Default.ShowElevationModel) { bounds[0, 0].Tu = 0; bounds[0, 0].Tv = 0; bounds[1, 0].Tu = .5f; bounds[1, 0].Tv = 0; bounds[2, 0].Tu = 1; bounds[2, 0].Tv = 0; bounds[0, 1].Tu = 0; bounds[0, 1].Tv = .5f; bounds[1, 1].Tu = .5f; bounds[1, 1].Tv = .5f; bounds[2, 1].Tu = 1; bounds[2, 1].Tv = .5f; bounds[0, 2].Tu = 0; bounds[0, 2].Tv = 1; bounds[1, 2].Tu = .5f; bounds[1, 2].Tv = 1; bounds[2, 2].Tu = 1; bounds[2, 2].Tv = 1; } else { bounds[0, 0].Tu = 0 + .002f; bounds[0, 0].Tv = 0 + .002f; bounds[1, 0].Tu = .5f + .002f; bounds[1, 0].Tv = 0 + .002f; bounds[2, 0].Tu = 1 + .002f; bounds[2, 0].Tv = 0 + .002f; bounds[0, 1].Tu = 0 + .002f; bounds[0, 1].Tv = .5f + .002f; bounds[1, 1].Tu = .5f + .002f; bounds[1, 1].Tv = .5f + .002f; bounds[2, 1].Tu = 1 + .002f; bounds[2, 1].Tv = .5f + .002f; bounds[0, 2].Tu = 0 + .002f; bounds[0, 2].Tv = 1 + .002f; bounds[1, 2].Tu = .5f + .002f; bounds[1, 2].Tv = 1 + .002f; bounds[2, 2].Tu = 1 + .002f; bounds[2, 2].Tv = 1 + .002f; } } else { if (Properties.Settings.Default.ShowElevationModel) { bounds[0, 0] = new PositionTexture(0, -1, 0, 0, 0); bounds[1, 0] = new PositionTexture(0, 0, -1, .5f, 0); bounds[2, 0] = new PositionTexture(0, -1, 0, 1, 0); bounds[0, 1] = new PositionTexture(1, 0, 0, 0, .5f); bounds[1, 1] = new PositionTexture(0, 1, 0, .5f, .5f); bounds[2, 1] = new PositionTexture(-1, 0, 0, 1, .5f); bounds[0, 2] = new PositionTexture(0, -1, 0, 0, 1); bounds[1, 2] = new PositionTexture(0, 0, 1, .5f, 1); bounds[2, 2] = new PositionTexture(0, -1, 0, 1, 1); } else { bounds[0, 0] = new PositionTexture(0, -1, 0, 0 + .002f, 0 + .002f); bounds[1, 0] = new PositionTexture(0, 0, -1, .5f + .002f, 0 + .002f); bounds[2, 0] = new PositionTexture(0, -1, 0, 1 + .002f, 0 + .002f); bounds[0, 1] = new PositionTexture(1, 0, 0, 0 + .002f, .5f + .002f); bounds[1, 1] = new PositionTexture(0, 1, 0, .5f + .002f, .5f + .002f); bounds[2, 1] = new PositionTexture(-1, 0, 0, 1 + .002f, .5f + .002f); bounds[0, 2] = new PositionTexture(0, -1, 0, 0 + .002f, 1 + .002f); bounds[1, 2] = new PositionTexture(0, 0, 1, .5f + .002f, 1 + .002f); bounds[2, 2] = new PositionTexture(0, -1, 0, 1 + .002f, 1 + .002f); } } }