void renderCell(SimHeightVisualData handle) { BRenderDevice.getDevice().VertexDeclaration = VertexTypes.Pos_Color.vertDecl; BRenderDevice.getDevice().VertexFormat = VertexTypes.Pos_Color.FVF_Flags; BRenderDevice.getDevice().VertexShader = null; BRenderDevice.getDevice().PixelShader = null; BRenderDevice.getDevice().SetTexture(0, null); BRenderDevice.getDevice().SetStreamSource(0, handle.mVB, 0); BRenderDevice.getDevice().Indices = handle.mIB; BRenderDevice.getDevice().RenderState.CullMode = Cull.None; BRenderDevice.getDevice().SetRenderState(RenderStates.ZBufferWriteEnable, false); BRenderDevice.getDevice().SetRenderState(RenderStates.FillMode, (int)FillMode.WireFrame); BRenderDevice.getDevice().DrawPrimitives(PrimitiveType.TriangleList, 0, handle.mNumPrims); BRenderDevice.getDevice().SetRenderState(RenderStates.FillMode, (int)FillMode.Solid); BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaTestEnable, false); BRenderDevice.getDevice().SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha); BRenderDevice.getDevice().SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha); BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, true); BRenderDevice.getDevice().DrawPrimitives(PrimitiveType.TriangleList, 0, handle.mNumPrims); BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, false); BRenderDevice.getDevice().SetRenderState(RenderStates.ZBufferWriteEnable, true); BRenderDevice.getDevice().RenderState.CullMode = Cull.CounterClockwise; }
public void destroy() { if (mVisualHandle != null) { mVisualHandle.destroy(); mVisualHandle = null; } }
unsafe SimHeightVisualData newVisualHandle(int minX, int minZ) { int width = (int)mNumXVertsPerCell; int vd = width + 1; int tw = width; int td = width; SimHeightVisualData svd = new SimHeightVisualData(); int numVertsPerTile = 6; svd.mNumVerts = width * numVertsPerTile * width * numVertsPerTile; svd.mVB = new VertexBuffer(typeof(VertexTypes.Pos_Color), (int)svd.mNumVerts, BRenderDevice.getDevice(), Usage.None, VertexTypes.Pos_Color.FVF_Flags, Pool.Managed); //standard IB svd.mNumPrims = width * width * 2; //update and fill our vertex buffer updateVisualHandle(ref svd, minX, minZ); return(svd); }
unsafe void updateVisualHandle(ref SimHeightVisualData handle, int minX, int minZ) { if (handle == null) { return; } int width = (int)(mNumXVertsPerCell + 1); int numTiles = (int)(mNumXVertsPerCell); GraphicsStream stream = handle.mVB.Lock(0, handle.mNumVerts * sizeof(VertexTypes.Pos_Color), LockFlags.None); VertexTypes.Pos_Color * verts = (VertexTypes.Pos_Color *)stream.InternalDataPointer; BTerrainSimRep.eChannels channel = TerrainGlobals.getEditor().getSimRep().getChannel(); //generate each tile as a seperate triList int counter = 0; for (int x = 0; x < numTiles; x++) { for (int z = 0; z < numTiles; z++) { int offX = (int)BMathLib.Clamp(minX + x, 0, mWidth - 1); int offZ = (int)BMathLib.Clamp(minZ + z, 0, mHeight - 1); //calculate our tile positions float3 wsp = getWorldspacePoint(offX, offZ);// new float3(offX * mTileScale, getCompositeHeight(offX, offZ), offZ * mTileScale); float3[] xyzVals = new float3[4]; xyzVals[0] = getWorldspacePoint(minX + x, minZ + z); xyzVals[1] = getWorldspacePoint(minX + x, minZ + z + 1); xyzVals[2] = getWorldspacePoint(minX + x + 1, minZ + z + 1); xyzVals[3] = getWorldspacePoint(minX + x + 1, minZ + z); //Determine our tile COLOR & VISUALIZATION MODE int xT = minX + x; int zT = minZ + z; if (xT >= TerrainGlobals.getEditor().getSimRep().getNumXTiles()) { xT = TerrainGlobals.getEditor().getSimRep().getNumXTiles() - 1; } if (zT >= TerrainGlobals.getEditor().getSimRep().getNumXTiles()) { zT = TerrainGlobals.getEditor().getSimRep().getNumXTiles() - 1; } int obsCol = 0x7FFFFFFF; bool obstruction = false; if (channel == BTerrainSimRep.eChannels.cObstrtuctionChannel) { if (TerrainGlobals.getEditor().getSimRep().getDataTiles().isTileLandObstructed(xT, zT) == true) { obstruction |= true; } } else if (channel == BTerrainSimRep.eChannels.cBuildableChannel) { if (TerrainGlobals.getEditor().getSimRep().getDataTiles().isBuildable(xT, zT) == true) { obstruction |= true; } } else if (channel == BTerrainSimRep.eChannels.cFloodObstructionChannel) { if (TerrainGlobals.getEditor().getSimRep().getDataTiles().isFloodObstructed(xT, zT) == true) { obstruction |= true; } } else if (channel == BTerrainSimRep.eChannels.cScarabObstructionChannel) { if (TerrainGlobals.getEditor().getSimRep().getDataTiles().isScarabObstructed(xT, zT) == true) { obstruction |= true; } } obsCol = obstruction ? TerrainGlobals.getEditor().getSimRep().getChannelNegColor(channel) : TerrainGlobals.getEditor().getSimRep().getChannelPosColor(channel); //tile type colors are defined by a text file, so we need to query for them if (channel == BTerrainSimRep.eChannels.cTileTypeChannel) { int tileTypeOverride = TerrainGlobals.getEditor().getSimRep().getDataTiles().getJaggedTileType(xT, zT); if (tileTypeOverride != 0) { obsCol = (int)TerrainGlobals.getEditor().getSimRep().getDataTiles().getTileTypeColor(tileTypeOverride); } } const float heightShift = 0.1f; const float xShift = 0; // -0.5f; const float zShift = 0; // -0.5f; //update our tiles verts[counter].x = xyzVals[0].X + xShift; verts[counter].y = xyzVals[0].Y + heightShift; verts[counter].z = xyzVals[0].Z + zShift; verts[counter].color = obsCol; counter++; verts[counter].x = xyzVals[1].X + xShift; verts[counter].y = xyzVals[1].Y + heightShift; verts[counter].z = xyzVals[1].Z + zShift; verts[counter].color = obsCol; counter++; verts[counter].x = xyzVals[2].X + xShift; verts[counter].y = xyzVals[2].Y + heightShift; verts[counter].z = xyzVals[2].Z + zShift; verts[counter].color = obsCol; counter++; verts[counter].x = xyzVals[0].X + xShift; verts[counter].y = xyzVals[0].Y + heightShift; verts[counter].z = xyzVals[0].Z + zShift; verts[counter].color = obsCol; counter++; verts[counter].x = xyzVals[2].X + xShift; verts[counter].y = xyzVals[2].Y + heightShift; verts[counter].z = xyzVals[2].Z + zShift; verts[counter].color = obsCol; counter++; verts[counter].x = xyzVals[3].X + xShift; verts[counter].y = xyzVals[3].Y + heightShift; verts[counter].z = xyzVals[3].Z + zShift; verts[counter].color = obsCol; counter++; } } handle.mVB.Unlock(); }