public override void OnCreateVertexBuffer(VertexBuffer11 vb) { ComputeMatrix(); double latMin = 0 + (ScaleY * (Height - PixelCenterY)); double latMax = 0 - (ScaleY * PixelCenterY); double lngMin = 0 + (ScaleX * PixelCenterX); double lngMax = 0 - (ScaleX * (Width - PixelCenterX)); Vector3d TopLeft = GeoTo3d(latMin, lngMin); Vector3d BottomRight = GeoTo3d(latMax, lngMax); Vector3d TopRight = GeoTo3d(latMin, lngMax); Vector3d BottomLeft = GeoTo3d(latMax, lngMin); // Create a vertex buffer PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) verts[0].Position = TopLeft; verts[0].Normal = TopLeft; verts[0].Tu = 0; verts[0].Tv = 0; verts[1].Position = TopRight; verts[1].Normal = TopRight; verts[1].Tu = 1; verts[1].Tv = 0; verts[2].Position = BottomRight; verts[2].Normal = BottomRight; verts[2].Tu = 1; verts[2].Tv = 1; verts[3].Position = BottomLeft; verts[3].Normal = BottomLeft; verts[3].Tu = 0; verts[3].Tv = 1; vb.Unlock(); short[] indexArray = (short[])indexBuffer.Lock(); indexArray[0] = 3; indexArray[1] = 1; indexArray[2] = 0; indexArray[3] = 1; indexArray[4] = 3; indexArray[5] = 2; indexBuffer.Unlock(); }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { var sb = new StringBuilder(); try { double lat, lng; var index = 0; var tileDegrees = 360 / (Math.Pow(2, level)); latMin = AbsoluteMetersToLatAtZoom(y * 256, level); latMax = AbsoluteMetersToLatAtZoom((y + 1) * 256, level); lngMin = ((x * tileDegrees) - 180.0); lngMax = (((x + 1) * tileDegrees) - 180.0); var latCenter = AbsoluteMetersToLatAtZoom(((y * 2) + 1) * 256, level + 1); var lngCenter = (lngMin / lngMax) / 2; demIndex = 0; tileDegrees = lngMax - lngMin; // Create a vertex buffer var verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) var dGrid = (tileDegrees / SubDivisions); int x1, y1; double textureStep = 1.0f / SubDivisions; var latDegrees = latMax - latCenter; demIndex = 0; for (y1 = 0; y1 < SubDivisions / 2; y1++) { if (y1 != SubDivisions / 2) { //lat = latMax - (2 * textureStep * latDegrees * (double)y1); lat = AbsoluteMetersToLatAtZoom(((y + 1) * 256) - y1 * 8, level); } else { lat = latCenter; } for (x1 = 0; x1 <= SubDivisions; x1++) { if (x1 != SubDivisions) { lng = lngMin + (textureStep * tileDegrees * x1); } else { lng = lngMax; } index = y1 * (SubDivisions + 1) + x1; verts[index].Position = GeoTo3dWithAltitude(lat, lng, true);// Add Altitude mapping here verts[index].Normal = GeoTo3dWithAltitude(lat, lng, false); verts[index].Tu = (float)(x1 * textureStep) + .002f; verts[index].Lat = lat; verts[index].Lng = lng; // For top levels the geometry is vastly out of scale for v so we adjust with real Lat calculation, otherwise // simple linear interpolation will do verts[index].Tv = (float)((AbsoluteLatToMetersAtZoom(lat, level) - (y * 256)) / 256f) + .002f; sb.Append(verts[index].Tv + ", " + verts[index].Tu + "\n"); demIndex++; } } latDegrees = latMin - latCenter; for (y1 = SubDivisions / 2; y1 <= SubDivisions; y1++) { if (y1 != SubDivisions) { //lat = latCenter + (2 * textureStep * latDegrees * (double)(y1 - (SubDivisions / 2))); lat = AbsoluteMetersToLatAtZoom(((y + 1) * 256) - y1 * 8, level); } else { lat = latMin; } for (x1 = 0; x1 <= SubDivisions; x1++) { if (x1 != SubDivisions) { lng = lngMin + (textureStep * tileDegrees * x1); } else { lng = lngMax; } index = y1 * (SubDivisions + 1) + x1; verts[index].Position = GeoTo3dWithAltitude(lat, lng, true);// Add Altitude mapping here verts[index].Normal = GeoTo3dWithAltitude(lat, lng, false); verts[index].Tu = (float)(x1 * textureStep) + .002f; verts[index].Lat = lat; verts[index].Lng = lng; // For top levels the geometry is vastly out of scale for v so we adjust with real Lat calculation, otherwise // simple linear interpolation will do verts[index].Tv = (float)((AbsoluteLatToMetersAtZoom(lat, level) - (y * 256)) / 256f) + .002f; sb.Append(verts[index].Tv + ", " + verts[index].Tu + "\n"); demIndex++; } } if (Y == 0) { // Send the tops to the pole to fill in the Bing Hole y1 = SubDivisions; for (x1 = 0; x1 <= SubDivisions; x1++) { index = y1 * (SubDivisions + 1) + x1; verts[index].Position = new Vector3d(0, 1, 0);// Add Altitude mapping here verts[index].Normal = new Vector3d(0, 1, 0); } } if (Y == Math.Pow(2, level)-1) { // Send the tops to the pole to fill in the Bing Hole y1 = 0; for (x1 = 0; x1 <= SubDivisions; x1++) { index = y1 * (SubDivisions + 1) + x1; verts[index].Position = new Vector3d(0, -1, 0);// Add Altitude mapping here verts[index].Normal = new Vector3d(0, -1, 0); } } vb.Unlock(); #region createIndex TriangleCount = (SubDivisions) * (SubDivisions) * 2; //bool flipFlop = false; //int quarterDivisions = SubDivisions / 2; //int part = 0; //for (int y2 = 0; y2 < 2; y2++) //{ // for (int x2 = 0; x2 < 2; x2++) // { // short[] indexArray = (short[])this.indexBuffer[part].Lock(0, LockFlags.None); // index = 0; // for (y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++) // { // for (x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++) // { // if (flipFlop) // { // //index = ((y1 * quarterDivisions * 6) + 6 * x1); // // First triangle in quad // indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); // indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + x1); // indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // // Second triangle in quad // indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1); // indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); // index += 6; // } // else // { // //index = ((y1 * quarterDivisions * 6) + 6 * x1); // // First triangle in quad // indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); // indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); // indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // // Second triangle in quad // indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 )); // indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1); // indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); // index += 6; // } // flipFlop = !flipFlop; // } // flipFlop = !flipFlop; // } // this.indexBuffer[part].Unlock(); // part++; // } //} #endregion var data = sb.ToString(); // LoadMeshFile(); } catch { } }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { indexBuffer[0] = new IndexBuffer11(typeof(short), subDivisionsX * subDivisionsY * 6, RenderContext11.PrepDevice); double lat, lng; int index = 0; // double tileDegrees = 360; double latMin = 90; double latMax = -90; double lngMin = -180; double lngMax = 180; // Create a vertex buffer PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) int x1, y1; double latDegrees = latMax - latMin; double lngDegrees = lngMax - lngMin; double textureStepX = 1.0f / subDivisionsX; double textureStepY = 1.0f / subDivisionsY; for (y1 = 0; y1 <= subDivisionsY; y1++) { if (y1 != subDivisionsY) { lat = latMax - (textureStepY * latDegrees * (double)y1); } else { lat = latMin; } for (x1 = 0; x1 <= subDivisionsX; x1++) { if (x1 != subDivisionsX) { lng = lngMin + (textureStepX * lngDegrees * (double)x1); } else { lng = lngMax; } index = y1 * (subDivisionsX + 1) + x1; verts[index].Position = GeoTo3d(lat, lng, false);// Add Altitude mapping here verts[index].Normal = verts[index].Position; if (domeMaster) { double dist = (90-lat) / 180; verts[index].Tu = (float)(.5 +Math.Sin((lng+180)/180*Math.PI)*dist); verts[index].Tv = (float)(.5 + Math.Cos((lng+180) / 180 * Math.PI) * dist); } else { verts[index].Tu = (float)(x1 * textureStepX); verts[index].Tv = (float)(1f - (y1 * textureStepY)); } } } vb.Unlock(); TriangleCount = (subDivisionsX) * (subDivisionsY) * 2; short[] indexArray = (short[])this.indexBuffer[0].Lock(); for (y1 = 0; y1 < subDivisionsY; y1++) { if (!(domeMaster && y1 < subDivisionsY / 2)) { for (x1 = 0; x1 < subDivisionsX; x1++) { index = (y1 * subDivisionsX * 6) + 6 * x1; // First triangle in quad indexArray[index] = (short)(y1 * (subDivisionsX + 1) + x1); indexArray[index + 2] = (short)((y1 + 1) * (subDivisionsX + 1) + x1); indexArray[index + 1] = (short)(y1 * (subDivisionsX + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (short)(y1 * (subDivisionsX + 1) + (x1 + 1)); indexArray[index + 5] = (short)((y1 + 1) * (subDivisionsX + 1) + x1); indexArray[index + 4] = (short)((y1 + 1) * (subDivisionsX + 1) + (x1 + 1)); } } } this.indexBuffer[0].Unlock(); }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { for (var i = 0; i < 4; i++) { indexBuffer[i] = new IndexBuffer11(typeof(short), ((SubDivisions / 2) * (SubDivisions / 2) * 6), RenderContext11.PrepDevice); } try { if (!topDown) { OnCreateVertexBufferBottomsUp(vb); return; } int index; var tileDegrees = dataset.BaseTileDegrees / (Math.Pow(2, level)); var latMin = (90 - (this.y * tileDegrees)); var latMax = (90 - ((this.y + 1) * tileDegrees)); var lngMin = ((this.x * tileDegrees) - 180.0); var lngMax = (((this.x + 1) * tileDegrees) - 180.0); var tileDegreesX = lngMax - lngMin; var tileDegreesY = latMax - latMin; //bugbug altitude broken TopLeft = GeoTo3dWithAltitude(latMin, lngMin, false); BottomRight = GeoTo3dWithAltitude(latMax, lngMax, false); TopRight = GeoTo3dWithAltitude(latMin, lngMax, false); BottomLeft = GeoTo3dWithAltitude(latMax, lngMin, false); // Create a vertex buffer var verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) int x, y; var textureStep = 1.0f / SubDivisions; for (y = 0; y <= SubDivisions; y++) { double lat; if (y != SubDivisions) { lat = latMin + (textureStep * tileDegreesY * y); } else { lat = latMax; } for (x = 0; x <= SubDivisions; x++) { double lng; if (x != SubDivisions) { lng = lngMin + (textureStep * tileDegreesX * x); } else { lng = lngMax; } index = y * (SubDivisions + 1) + x; verts[index].Position = GeoTo3dWithAltitude(lat, lng, true);// Add Altitude mapping here verts[index].Normal = GeoTo3d(lat, lng, false); verts[index].Tu = x * textureStep; verts[index].Tv = y * textureStep; verts[index].Lat = lat; verts[index].Lng = lng; } } vb.Unlock(); TriangleCount = (SubDivisions) * (SubDivisions) * 2; var quarterDivisions = SubDivisions / 2; var part = 0; for (var y2 = 0; y2 < 2; y2++) { for (var x2 = 0; x2 < 2; x2++) { var indexArray = (short[])indexBuffer[part].Lock(); index = 0; for (var y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++) { for (var x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++) { //index = ((y1 * quarterDivisions * 6) + 6 * x1); // First triangle in quad indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); indexArray[index + 1] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 2] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); index += 6; } } indexBuffer[part].Unlock(); part++; } } } catch { } }
public void OnCreateVertexBufferBottomsUp(VertexBuffer11 vb) { double lat, lng; var index = 0; var tileDegrees = dataset.BaseTileDegrees / (Math.Pow(2, level)); var latMin = (-90 + ((this.y + 1) * tileDegrees)); var latMax = (-90 + (this.y * tileDegrees)); var lngMin = ((this.x * tileDegrees) - 180.0); var lngMax = (((this.x + 1) * tileDegrees) - 180.0); var tileDegreesX = lngMax - lngMin; var tileDegreesY = latMax - latMin; // Create a vertex buffer var verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) int x, y; var textureStep = 1.0f / SubDivisions; for (y = 0; y <= SubDivisions; y++) { if (y != SubDivisions) { lat = latMin + (textureStep * tileDegreesY * y); } else { lat = latMax; } for (x = 0; x <= SubDivisions; x++) { if (x != SubDivisions) { lng = lngMin + (textureStep * tileDegreesX * x); } else { lng = lngMax; } index = y * (SubDivisions + 1) + x; verts[index].Position = GeoTo3d(lat, lng, true);// Add Altitude mapping here verts[index].Normal = GeoTo3d(lat, lng, false); verts[index].Tu = x * textureStep; verts[index].Tv = y * textureStep; verts[index].Lat = lat; verts[index].Lng = lng; } } vb.Unlock(); TriangleCount = (SubDivisions) * (SubDivisions) * 2; var quarterDivisions = SubDivisions / 2; var part = 0; for (var y2 = 0; y2 < 2; y2++) { for (var x2 = 0; x2 < 2; x2++) { var indexArray = (short[])indexBuffer[part].Lock(); index = 0; for (var y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++) { for (var x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++) { //index = ((y1 * quarterDivisions * 6) + 6 * x1); // First triangle in quad indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); indexArray[index + 1] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 2] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); index += 6; } } indexBuffer[part].Unlock(); part++; } } }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { var dem = DemEnabled; if (!subDivided) { if (vertexList == null) { InitializeGrids(); } for (var i = 0; i < 4; i++) { var count = subDivisionLevel; while (count-- > 1) { var newList = BufferPool11.GetTriagleList(); foreach (var tri in childTriangleList[i]) { tri.SubDivide(newList, vertexList); } BufferPool11.ReturnTriangleList(childTriangleList[i]); childTriangleList[i] = newList; } } subDivided = true; } //for (int i = 0; i < 4; i++) //{ // indexBuffer[i] = BufferPool11.GetShortIndexBuffer(childTriangleList[i].Count * 3); //} var indexCount = childTriangleList[0].Count * 3; demIndex = 0; try { // Create a vertex buffer var verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) var index = 0; if (dem && level > 1) { demArray = new double[17 * 17]; if (backslash) { if (backslashYIndex == null) { tempBackslashYIndex = new byte[demSize]; tempBackslashXIndex = new byte[demSize]; } } else { if (slashYIndex == null) { tempSlashYIndex = new byte[demSize]; tempSlashXIndex = new byte[demSize]; } } } foreach (var vert in vertexList) { if (dem) { // todo map this with backslash as well verts[index++] = GetMappedVertex(vert); } else { verts[index++] = vert.PositionNormalTextured(localCenter, backslash ); } demIndex++; } vb.Unlock(); TriangleCount = childTriangleList[0].Count*4; var quarterDivisions = SubDivisions / 2; var part = 0; foreach (var triList in childTriangleList) { if (GetIndexBuffer(part, 0) == null) { var indexArray = new short[indexCount]; var indexer = 0; //dumpMutex.WaitOne(); //System.Diagnostics.Debug.WriteLine("start Index dump:" + part.ToString() + ";" + (backslash ? "Backslash" : "Slash")); foreach (var tri in triList) { indexArray[indexer++] = (short)tri.A; indexArray[indexer++] = (short)tri.B; indexArray[indexer++] = (short)tri.C; //WriteDebugVertex(tri.A); //WriteDebugVertex(tri.B); //WriteDebugVertex(tri.C); } //System.Diagnostics.Debug.WriteLine("End Index dump"); //dumpMutex.ReleaseMutex(); ProcessIndexBuffer(indexArray, part); } part++; } if (backslash) { if (tempBackslashXIndex != null) { backslashXIndex = tempBackslashXIndex; backslashYIndex = tempBackslashYIndex; tempBackslashXIndex = null; tempBackslashYIndex = null; } } else { if (tempSlashYIndex != null) { slashXIndex = tempSlashXIndex; slashYIndex = tempSlashYIndex; tempSlashYIndex = null; tempSlashXIndex = null; } } } catch { } ReturnBuffers(); }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { for (int i = 0; i < 4; i++) { indexBuffer[i] = new IndexBuffer11(typeof(short), ((SubDivisions / 2) * (SubDivisions / 2) * 6), RenderContext11.PrepDevice); } try { if (!topDown) { OnCreateVertexBufferBottomsUp(vb); return; } double lat, lng; int index = 0; double tileDegrees = this.dataset.BaseTileDegrees / (Math.Pow(2, this.level)); double latMin = (90 - (((double)this.y) * tileDegrees)); double latMax = (90 - (((double)(this.y + 1)) * tileDegrees)); double lngMin = (((double)this.x * tileDegrees) - 180.0); double lngMax = ((((double)(this.x + 1)) * tileDegrees) - 180.0); double tileDegreesX = lngMax - lngMin; double tileDegreesY = latMax - latMin; //bugbug altitude broken TopLeft = GeoTo3dWithAltitude(latMin, lngMin, false); BottomRight = GeoTo3dWithAltitude(latMax, lngMax, false); TopRight = GeoTo3dWithAltitude(latMin, lngMax, false); BottomLeft = GeoTo3dWithAltitude(latMax, lngMin, false); // Create a vertex buffer PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) int x, y; float textureStep = 1.0f / SubDivisions; for (y = 0; y <= SubDivisions; y++) { if (y != SubDivisions) { lat = latMin + (textureStep * tileDegreesY * y); } else { lat = latMax; } for (x = 0; x <= SubDivisions; x++) { if (x != SubDivisions) { lng = lngMin + (textureStep * tileDegreesX * x); } else { lng = lngMax; } index = y * (SubDivisions + 1) + x; verts[index].Position = GeoTo3dWithAltitude(lat, lng, true);// Add Altitude mapping here verts[index].Normal = GeoTo3d(lat, lng, false); verts[index].Tu = x * textureStep; verts[index].Tv = y * textureStep; verts[index].Lat = lat; verts[index].Lng = lng; } } vb.Unlock(); TriangleCount = (SubDivisions) * (SubDivisions) * 2; int quarterDivisions = SubDivisions / 2; int part = 0; for (int y2 = 0; y2 < 2; y2++) { for (int x2 = 0; x2 < 2; x2++) { short[] indexArray = (short[])this.indexBuffer[part].Lock(); index = 0; for (int y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++) { for (int x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++) { //index = ((y1 * quarterDivisions * 6) + 6 * x1); // First triangle in quad indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); indexArray[index + 1] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 2] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); index += 6; } } this.indexBuffer[part].Unlock(); part++; } } } catch { } }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { ComputeMatrix(); var latMin = 0 + (ScaleY * (Height - PixelCenterY)); var latMax = 0 - (ScaleY * PixelCenterY); var lngMin = 0 + (ScaleX * PixelCenterX); var lngMax = 0 - (ScaleX * (Width - PixelCenterX)); var TopLeft = GeoTo3d(latMin, lngMin); var BottomRight = GeoTo3d(latMax, lngMax); var TopRight = GeoTo3d(latMin, lngMax); var BottomLeft = GeoTo3d(latMax, lngMin); // Create a vertex buffer var verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) verts[0].Position = TopLeft; verts[0].Normal = TopLeft; verts[0].Tu = 0; verts[0].Tv = 0; verts[1].Position = TopRight; verts[1].Normal = TopRight; verts[1].Tu = 1; verts[1].Tv = 0; verts[2].Position = BottomRight; verts[2].Normal = BottomRight; verts[2].Tu = 1; verts[2].Tv = 1; verts[3].Position = BottomLeft; verts[3].Normal = BottomLeft; verts[3].Tu = 0; verts[3].Tv = 1; vb.Unlock(); var indexArray = (short[])indexBuffer.Lock(); indexArray[0] = 3; indexArray[1] = 1; indexArray[2] = 0; indexArray[3] = 1; indexArray[4] = 3; indexArray[5] = 2; indexBuffer.Unlock(); }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { for (int i = 0; i < 4; i++) { indexBuffer[i] = new IndexBuffer11(typeof(short), ((SubDivisions / 2) * (SubDivisions / 2) * 6), RenderContext11.PrepDevice); } try { if (!topDown) { OnCreateVertexBufferBottomsUp(vb); return; } double lat, lng; int index = 0; float tileDegrees = (float)this.dataset.BaseTileDegrees / ((float)Math.Pow(2, this.level)); float latMin = (float)(((double)this.dataset.BaseTileDegrees / 2.0 - (((double)this.y) * tileDegrees)) + this.dataset.OffsetY); float latMax = (float)(((double)this.dataset.BaseTileDegrees / 2.0 - (((double)(this.y + 1)) * tileDegrees)) + this.dataset.OffsetY); float lngMin = (float)((((double)this.x * tileDegrees) - (float)this.dataset.BaseTileDegrees / dataset.WidthFactor) + this.dataset.OffsetX); float lngMax = (float)(((((double)(this.x + 1)) * tileDegrees) - (float)this.dataset.BaseTileDegrees / dataset.WidthFactor) + this.dataset.OffsetX); float tileDegreesX = lngMax - lngMin; float tileDegreesY = latMax - latMin; TopLeft = GeoTo3d(latMin, lngMin, false); BottomRight = GeoTo3d(latMax, lngMax, false); TopRight = GeoTo3d(latMin, lngMax, false); BottomLeft = GeoTo3d(latMax, lngMin, false); // Create a vertex buffer PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) int x, y; float textureStep = 1.0f / SubDivisions; for (y = 0; y <= SubDivisions; y++) { if (y != SubDivisions) { lat = latMin + (textureStep * tileDegreesY * y); } else { lat = latMax; } for (x = 0; x <= SubDivisions; x++) { if (x != SubDivisions) { lng = lngMin + (textureStep * tileDegreesX * x); } else { lng = lngMax; } index = y * (SubDivisions + 1) + x; verts[index].Position = GeoTo3d(lat, lng, true); verts[index].Normal = GeoTo3d(lat, lng, false); verts[index].Tu = x * textureStep +.002f; verts[index].Tv = y * textureStep +.002f; } } vb.Unlock(); TriangleCount = (SubDivisions) * (SubDivisions) * 2; int quarterDivisions = SubDivisions / 2; int part = 0; for (int y2 = 0; y2 < 2; y2++) { for (int x2 = 0; x2 < 2; x2++) { short[] indexArray = (short[])this.indexBuffer[part].Lock(); index = 0; for (int y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++) { for (int x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++) { //index = ((y1 * quarterDivisions * 6) + 6 * x1); // First triangle in quad indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); index += 6; } } this.indexBuffer[part].Unlock(); part++; } } } catch { } }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { StringBuilder sb = new StringBuilder(); try { double lat, lng; int index = 0; double tileDegrees = 360 / (Math.Pow(2, this.level)); latMin = AbsoluteMetersToLatAtZoom(y * 256, level); latMax = AbsoluteMetersToLatAtZoom((y + 1) * 256, level); lngMin = (((double)this.x * tileDegrees) - 180.0); lngMax = ((((double)(this.x + 1)) * tileDegrees) - 180.0); double latCenter = AbsoluteMetersToLatAtZoom(((y * 2) + 1) * 256, level + 1); double lngCenter = (lngMin / lngMax) / 2; demIndex = 0; tileDegrees = lngMax - lngMin; // Create a vertex buffer PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) double dGrid = (tileDegrees / SubDivisions); int x1, y1; double textureStep = 1.0f / SubDivisions; double latDegrees = latMax - latCenter; demIndex = 0; for (y1 = 0; y1 < SubDivisions / 2; y1++) { if (y1 != SubDivisions / 2) { //lat = latMax - (2 * textureStep * latDegrees * (double)y1); lat = AbsoluteMetersToLatAtZoom(((y + 1) * 256) - y1 * 8, level); } else { lat = latCenter; } for (x1 = 0; x1 <= SubDivisions; x1++) { if (x1 != SubDivisions) { lng = lngMin + (textureStep * tileDegrees * (double)x1); } else { lng = lngMax; } index = y1 * (SubDivisions + 1) + x1; verts[index].Position = GeoTo3dWithAltitude(lat, lng, true);// Add Altitude mapping here verts[index].Normal = GeoTo3dWithAltitude(lat, lng, false); verts[index].Tu = (float)(x1 * textureStep) + .002f; verts[index].Lat = lat; verts[index].Lng = lng; // For top levels the geometry is vastly out of scale for v so we adjust with real Lat calculation, otherwise // simple linear interpolation will do verts[index].Tv = (float)((AbsoluteLatToMetersAtZoom(lat, level) - (y * 256)) / 256f) + .002f; sb.Append(verts[index].Tv.ToString() + ", " + verts[index].Tu.ToString() + "\n"); demIndex++; } } latDegrees = latMin - latCenter; for (y1 = SubDivisions / 2; y1 <= SubDivisions; y1++) { if (y1 != SubDivisions) { //lat = latCenter + (2 * textureStep * latDegrees * (double)(y1 - (SubDivisions / 2))); lat = AbsoluteMetersToLatAtZoom(((y + 1) * 256) - y1 * 8, level); } else { lat = latMin; } for (x1 = 0; x1 <= SubDivisions; x1++) { if (x1 != SubDivisions) { lng = lngMin + (textureStep * tileDegrees * (double)x1); } else { lng = lngMax; } index = y1 * (SubDivisions + 1) + x1; verts[index].Position = GeoTo3dWithAltitude(lat, lng, true);// Add Altitude mapping here verts[index].Normal = GeoTo3dWithAltitude(lat, lng, false); verts[index].Tu = (float)(x1 * textureStep) + .002f; verts[index].Lat = lat; verts[index].Lng = lng; // For top levels the geometry is vastly out of scale for v so we adjust with real Lat calculation, otherwise // simple linear interpolation will do verts[index].Tv = (float)((AbsoluteLatToMetersAtZoom(lat, level) - (y * 256)) / 256f) + .002f; sb.Append(verts[index].Tv.ToString() + ", " + verts[index].Tu.ToString() + "\n"); demIndex++; } } if (Y == 0) { // Send the tops to the pole to fill in the Bing Hole y1 = SubDivisions; for (x1 = 0; x1 <= SubDivisions; x1++) { index = y1 * (SubDivisions + 1) + x1; verts[index].Position = new Vector3d(0, 1, 0);// Add Altitude mapping here verts[index].Normal = new Vector3d(0, 1, 0); } } if (Y == Math.Pow(2, level) - 1) { // Send the tops to the pole to fill in the Bing Hole y1 = 0; for (x1 = 0; x1 <= SubDivisions; x1++) { index = y1 * (SubDivisions + 1) + x1; verts[index].Position = new Vector3d(0, -1, 0);// Add Altitude mapping here verts[index].Normal = new Vector3d(0, -1, 0); } } vb.Unlock(); #region createIndex TriangleCount = (SubDivisions) * (SubDivisions) * 2; //bool flipFlop = false; //int quarterDivisions = SubDivisions / 2; //int part = 0; //for (int y2 = 0; y2 < 2; y2++) //{ // for (int x2 = 0; x2 < 2; x2++) // { // short[] indexArray = (short[])this.indexBuffer[part].Lock(0, LockFlags.None); // index = 0; // for (y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++) // { // for (x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++) // { // if (flipFlop) // { // //index = ((y1 * quarterDivisions * 6) + 6 * x1); // // First triangle in quad // indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); // indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + x1); // indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // // Second triangle in quad // indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1); // indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); // index += 6; // } // else // { // //index = ((y1 * quarterDivisions * 6) + 6 * x1); // // First triangle in quad // indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); // indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); // indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // // Second triangle in quad // indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 )); // indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1); // indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); // index += 6; // } // flipFlop = !flipFlop; // } // flipFlop = !flipFlop; // } // this.indexBuffer[part].Unlock(); // part++; // } //} #endregion string data = sb.ToString(); // LoadMeshFile(); } catch { } }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { bool dem = DemEnabled; if (!subDivided) { if (vertexList == null) { InitializeGrids(); } for (int i = 0; i < 4; i++) { int count = subDivisionLevel; while (count-- > 1) { List <Triangle> newList = BufferPool11.GetTriagleList(); foreach (Triangle tri in childTriangleList[i]) { tri.SubDivide(newList, vertexList); } BufferPool11.ReturnTriangleList(childTriangleList[i]); childTriangleList[i] = newList; } } subDivided = true; } //for (int i = 0; i < 4; i++) //{ // indexBuffer[i] = BufferPool11.GetShortIndexBuffer(childTriangleList[i].Count * 3); //} int indexCount = childTriangleList[0].Count * 3; demIndex = 0; try { // Create a vertex buffer PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) int index = 0; if (dem && level > 1) { demArray = new double[17 * 17]; if (backslash) { if (backslashYIndex == null) { tempBackslashYIndex = new byte[demSize]; tempBackslashXIndex = new byte[demSize]; } } else { if (slashYIndex == null) { tempSlashYIndex = new byte[demSize]; tempSlashXIndex = new byte[demSize]; } } } foreach (PositionTexture vert in vertexList) { if (dem) { // todo map this with backslash as well verts[index++] = GetMappedVertex(vert); } else { verts[index++] = vert.PositionNormalTextured(localCenter, backslash); } demIndex++; } vb.Unlock(); TriangleCount = childTriangleList[0].Count * 4; int quarterDivisions = SubDivisions / 2; int part = 0; foreach (List <Triangle> triList in childTriangleList) { if (GetIndexBuffer(part, 0) == null) { short[] indexArray = new short[indexCount]; int indexer = 0; //dumpMutex.WaitOne(); //System.Diagnostics.Debug.WriteLine("start Index dump:" + part.ToString() + ";" + (backslash ? "Backslash" : "Slash")); foreach (Triangle tri in triList) { indexArray[indexer++] = (short)tri.A; indexArray[indexer++] = (short)tri.B; indexArray[indexer++] = (short)tri.C; //WriteDebugVertex(tri.A); //WriteDebugVertex(tri.B); //WriteDebugVertex(tri.C); } //System.Diagnostics.Debug.WriteLine("End Index dump"); //dumpMutex.ReleaseMutex(); ProcessIndexBuffer(indexArray, part); } part++; } if (backslash) { if (tempBackslashXIndex != null) { backslashXIndex = tempBackslashXIndex; backslashYIndex = tempBackslashYIndex; tempBackslashXIndex = null; tempBackslashYIndex = null; } } else { if (tempSlashYIndex != null) { slashXIndex = tempSlashXIndex; slashYIndex = tempSlashYIndex; tempSlashYIndex = null; tempSlashXIndex = null; } } } catch { } ReturnBuffers(); }
public override void OnCreateVertexBuffer(VertexBuffer11 vb) { indexBuffer[0] = new IndexBuffer11(typeof(short), subDivisionsX * subDivisionsY * 6, RenderContext11.PrepDevice); double lat, lng; int index = 0; // double tileDegrees = 360; double latMin = 90; double latMax = -90; double lngMin = -180; double lngMax = 180; // Create a vertex buffer PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) int x1, y1; double latDegrees = latMax - latMin; double lngDegrees = lngMax - lngMin; double textureStepX = 1.0f / subDivisionsX; double textureStepY = 1.0f / subDivisionsY; for (y1 = 0; y1 <= subDivisionsY; y1++) { if (y1 != subDivisionsY) { lat = latMax - (textureStepY * latDegrees * (double)y1); } else { lat = latMin; } for (x1 = 0; x1 <= subDivisionsX; x1++) { if (x1 != subDivisionsX) { lng = lngMin + (textureStepX * lngDegrees * (double)x1); } else { lng = lngMax; } index = y1 * (subDivisionsX + 1) + x1; verts[index].Position = GeoTo3d(lat, lng, false);// Add Altitude mapping here verts[index].Normal = verts[index].Position; if (domeMaster) { double dist = (90 - lat) / 180; verts[index].Tu = (float)(.5 + Math.Sin((lng + 180) / 180 * Math.PI) * dist); verts[index].Tv = (float)(.5 + Math.Cos((lng + 180) / 180 * Math.PI) * dist); } else { verts[index].Tu = (float)(x1 * textureStepX); verts[index].Tv = (float)(1f - (y1 * textureStepY)); } } } vb.Unlock(); TriangleCount = (subDivisionsX) * (subDivisionsY) * 2; short[] indexArray = (short[])this.indexBuffer[0].Lock(); for (y1 = 0; y1 < subDivisionsY; y1++) { if (!(domeMaster && y1 < subDivisionsY / 2)) { for (x1 = 0; x1 < subDivisionsX; x1++) { index = (y1 * subDivisionsX * 6) + 6 * x1; // First triangle in quad indexArray[index] = (short)(y1 * (subDivisionsX + 1) + x1); indexArray[index + 2] = (short)((y1 + 1) * (subDivisionsX + 1) + x1); indexArray[index + 1] = (short)(y1 * (subDivisionsX + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (short)(y1 * (subDivisionsX + 1) + (x1 + 1)); indexArray[index + 5] = (short)((y1 + 1) * (subDivisionsX + 1) + x1); indexArray[index + 4] = (short)((y1 + 1) * (subDivisionsX + 1) + (x1 + 1)); } } } this.indexBuffer[0].Unlock(); }
static void InitRings() { if (ringsVertexBuffer != null) { ringsVertexBuffer.Dispose(); GC.SuppressFinalize(ringsVertexBuffer); ringsVertexBuffer = null; } var inner = 1.113; var outer = 2.25; ringsVertexBuffer = new VertexBuffer11(typeof(PositionNormalTextured), ((subDivisionsRings + 1) * 4), RenderContext11.PrepDevice); triangleCountRings = (subDivisionsRings) * 2; var verts = (PositionNormalTexturedX2[])ringsVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs) var radStep = Math.PI * 2.0 / subDivisionsRings; var index = 0; for (var x = 0; x <= subDivisionsRings; x += 2) { var rads1 = x * radStep; var rads2 = (x + 1) * radStep; verts[index].Position = new Vector3d((Math.Cos(rads1) * inner), 0, (Math.Sin(rads1) * inner)); verts[index].Normal = new Vector3d(0, 1, 0); verts[index].Tu = 1; verts[index].Tv = 0; index++; verts[index].Position = new Vector3d((Math.Cos(rads1) * outer), 0, (Math.Sin(rads1) * outer)); verts[index].Normal = new Vector3d(0, 1, 0); verts[index].Tu = 0; verts[index].Tv = 0; index++; verts[index].Position = new Vector3d((Math.Cos(rads2) * inner), 0, (Math.Sin(rads2) * inner)); verts[index].Normal = new Vector3d(0, 1, 0); verts[index].Tu = 1; verts[index].Tv = 1; index++; verts[index].Position = new Vector3d((Math.Cos(rads2) * outer), 0, (Math.Sin(rads2) * outer)); verts[index].Normal = new Vector3d(0, 1, 0); verts[index].Tu = 0; verts[index].Tv = 1; index++; } ringsVertexBuffer.Unlock(); }
public void OnCreateVertexBufferBottomsUp(VertexBuffer11 vb) { double lat, lng; int index = 0; float tileDegrees = (float)this.dataset.BaseTileDegrees / ((float)Math.Pow(2, this.level)); float latMin = (float)((-90 + (((double)(this.y + 1)) * tileDegrees)) + dataset.OffsetY); float latMax = (float)((-90 + (((double)this.y) * tileDegrees)) + dataset.OffsetY); float lngMin = (float)((((double)this.x * tileDegrees) - 180.0) + dataset.OffsetX); float lngMax = (float)(((((double)(this.x + 1)) * tileDegrees) - 180.0) + dataset.OffsetX); float tileDegreesX = lngMax - lngMin; float tileDegreesY = latMax - latMin; // Create a vertex buffer PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs) int x, y; float textureStep = 1.0f / SubDivisions; for (y = 0; y <= SubDivisions; y++) { if (y != SubDivisions) { lat = latMin + (textureStep * tileDegreesY * y); } else { lat = latMax; } for (x = 0; x <= SubDivisions; x++) { if (x != SubDivisions) { lng = lngMin + (textureStep * tileDegreesX * x); } else { lng = lngMax; } index = y * (SubDivisions + 1) + x; verts[index].Position = GeoTo3d(lat, lng, true);// Add Altitude mapping here verts[index].Normal = GeoTo3d(lat, lng, false); verts[index].Tu = x * textureStep; verts[index].Tv = y * textureStep; } } vb.Unlock(); TriangleCount = (SubDivisions) * (SubDivisions) * 2; int quarterDivisions = SubDivisions / 2; int part = 0; for (int y2 = 0; y2 < 2; y2++) { for (int x2 = 0; x2 < 2; x2++) { short[] indexArray = (short[])this.indexBuffer[part].Lock(); index = 0; for (int y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++) { for (int x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++) { //index = ((y1 * quarterDivisions * 6) + 6 * x1); // First triangle in quad indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1); indexArray[index + 1] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 2] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1)); indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + x1); indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1)); index += 6; } } this.indexBuffer[part].Unlock(); part++; } } }