static public void createCursor() { // Release first if (gCircleVB != null) { gCircleVB.Dispose(); gCircleVB = null; } gCircleVB = new VertexBuffer(typeof(VertexTypes.Pos), cNumCircleVBVerts, BRenderDevice.getDevice(), Usage.WriteOnly, VertexTypes.Pos.FVF_Flags, Pool.Managed); VertexTypes.Pos[] circularVerts = new VertexTypes.Pos[cNumCircleVBVerts]; float angle = 0; float angleInc = (float)((Math.PI * 2.0f) / (cNumCircleVBVerts - 1)); float radius = TerrainGlobals.getEditor().getCurrentBrushInfo().mRadius; for (int i = 0; i < cNumCircleVBVerts; i++) { float x = (float)(Math.Cos(angle)); float y = (float)(Math.Sin(angle)); circularVerts[i].x = x; circularVerts[i].y = y; circularVerts[i].z = 0; angle += angleInc; } //copy verts over unsafe { using (GraphicsStream stream = gCircleVB.Lock(0, cNumCircleVBVerts * sizeof(VertexTypes.Pos), LockFlags.None))// (void**)&pVertices, 0)) { stream.Write(circularVerts); gCircleVB.Unlock(); } } }
//creation private void makeLODVB(ref VertexBuffer vb, ref uint numVerts, eLODLevel lod) { VertexTypes.Pos[] verts = null; uint width = BTerrainQuadNodeDesc.cMaxWidth; uint vd = width + 1; uint tw = width; uint td = width; int counter = 0; switch (lod) { case eLODLevel.cLOD0: { numVerts = (BTerrainQuadNodeDesc.cMaxWidth + 1) * (BTerrainQuadNodeDesc.cMaxHeight + 1) * 6; //*3 (TRILIST) *2 (per tile) verts = new VertexTypes.Pos[numVerts]; vd = width * 2; // width + 1; tw = width; td = width; for (int z = 0; z < td; z++) { for (int x = 0; x < tw; x++) { int k = z + (int)(x * vd); verts[counter++].x = (k); verts[counter++].x = (k + vd); verts[counter++].x = (k + 1); verts[counter++].x = (k + 1); verts[counter++].x = (k + vd); verts[counter++].x = (k + vd + 1); } } } break; case eLODLevel.cLOD1: { numVerts = (1 + (width >> 1)) * (1 + (width >> 1)) * 6; //*3 (TRILIST) *2 (per tile) verts = new VertexTypes.Pos[numVerts]; vd = (width >> 1) * 2; // width + 1; tw = (width >> 1); td = (width >> 1); for (int z = 0; z < td; z++) { for (int x = 0; x < tw; x++) { int k = z + (int)(x * vd); verts[counter++].x = (k); verts[counter++].x = (k + vd); verts[counter++].x = (k + 1); verts[counter++].x = (k + 1); verts[counter++].x = (k + vd); verts[counter++].x = (k + vd + 1); } } } break; case eLODLevel.cLOD2: { numVerts = (1 + (width >> 2)) * (1 + (width >> 2)) * 6; //*3 (TRILIST) *2 (per tile) verts = new VertexTypes.Pos[numVerts]; vd = (width >> 2) * 2; // width + 1; tw = (width >> 2); td = (width >> 2); for (int z = 0; z < td; z++) { for (int x = 0; x < tw; x++) { int k = z + (int)(x * vd); verts[counter++].x = (k); verts[counter++].x = (k + vd); verts[counter++].x = (k + 1); verts[counter++].x = (k + 1); verts[counter++].x = (k + vd); verts[counter++].x = (k + vd + 1); } } } break; case eLODLevel.cLOD3: { numVerts = (1 + (width >> 3)) * (1 + (width >> 3)) * 6; //*3 (TRILIST) *2 (per tile) verts = new VertexTypes.Pos[numVerts]; vd = (width >> 3) * 2; // width + 1; tw = (width >> 3); td = (width >> 3); for (int z = 0; z < td; z++) { for (int x = 0; x < tw; x++) { int k = z + (int)(x * vd); verts[counter++].x = (k); verts[counter++].x = (k + vd); verts[counter++].x = (k + 1); verts[counter++].x = (k + 1); verts[counter++].x = (k + vd); verts[counter++].x = (k + vd + 1); } } } break; default: return; } vb = new VertexBuffer(typeof(VertexTypes.Pos), (int)numVerts, BRenderDevice.getDevice(), Usage.None, VertexFormats.Position, Pool.Managed); GraphicsStream stream = vb.Lock(0, (int)numVerts * sizeof(float) * 3, LockFlags.None); stream.Write(verts); vb.Unlock(); verts = null; }
private void makeCursorLODVB(ref VertexBuffer vb, ref uint numVerts, BTerrainVisual.eLODLevel lod) { VertexTypes.Pos[] verts = null; uint width = BTerrainQuadNode.getMaxNodeWidth(); uint vd = width * 2; uint tw = width; uint td = width; int counter = 0; switch (lod) { case BTerrainVisual.eLODLevel.cLOD0: { numVerts = (width + 1) * (width + 1); verts = new VertexTypes.Pos[numVerts]; vd = width * 2; tw = width; td = width; for (int z = 0; z < td; z++) { for (int x = 0; x < tw; x++) { int k = z + (int)(x * vd); verts[counter++].x = (k); } } } break; case BTerrainVisual.eLODLevel.cLOD1: { numVerts = (1 + (width >> 1)) * (1 + (width >> 1)); verts = new VertexTypes.Pos[numVerts]; tw = width >> 1; td = width >> 1; vd = 2 * (width >> 1); for (int x = 0; x < tw; x++) { for (int z = 0; z < td; z++) { int k = z + (int)(x * vd); verts[counter++].x = (k); } } } break; case BTerrainVisual.eLODLevel.cLOD2: { numVerts = (1 + (width >> 2)) * (1 + (width >> 2)); verts = new VertexTypes.Pos[numVerts]; tw = width >> 2; td = width >> 2; vd = 2 * (width >> 2); for (int x = 0; x < tw; x++) { for (int z = 0; z < td; z++) { int k = z + (int)(x * vd); verts[counter++].x = (k); } } } break; case BTerrainVisual.eLODLevel.cLOD3: { numVerts = (1 + (width >> 3)) * (1 + (width >> 3)); verts = new VertexTypes.Pos[numVerts]; tw = width >> 3; td = width >> 3; vd = 2 * (width >> 3); for (int x = 0; x < tw; x++) { for (int z = 0; z < td; z++) { int k = z + (int)(x * vd); verts[counter++].x = (k); } } } break; default: return; } vb = new VertexBuffer(typeof(VertexTypes.Pos), (int)numVerts, BRenderDevice.getDevice(), Usage.None, VertexFormats.Position, Pool.Managed); GraphicsStream stream = vb.Lock(0, (int)numVerts * sizeof(float) * 3, LockFlags.None); stream.Write(verts); vb.Unlock(); verts = null; }