Exemplo n.º 1
0
        unsafe void updateVisualHandle(ref RealLOSVisualData handle, int minX, int minZ)
        {
            if (handle == null)
            {
                return;
            }

            int width = (int)(mNumXVertsPerCell + 1);

            GraphicsStream stream = handle.mVB.Lock(0, handle.mNumVerts * sizeof(VertexTypes.Pos_Color), LockFlags.None);

            VertexTypes.Pos_Color *verts = (VertexTypes.Pos_Color *)stream.InternalDataPointer;

            uint obsCol = 0x440000FF;

            obsCol = mColors[minX * mWidth + minZ];
            //generate each tile as a seperate triList
            int counter = 0;

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < width; z++)
                {
                    int    offX = (int)BMathLib.Clamp(minX + x, 0, mWidth - 1);
                    int    offZ = (int)BMathLib.Clamp(minZ + z, 0, mHeight - 1);
                    float3 wsp  = new float3(offX * mTileScale, getCompositeHeight(offX, offZ), offZ * mTileScale);
                    verts[counter].x     = wsp.X;
                    verts[counter].y     = wsp.Y + cVisualHeightOffset;
                    verts[counter].z     = wsp.Z;
                    verts[counter].color = (int)obsCol;
                    counter++;
                }
            }
            handle.mVB.Unlock();
        }
Exemplo n.º 2
0
        //---------------------------------
        public void toVisualBuffer(ref VertexBuffer vb, ref IndexBuffer ib, ref int numVerts, ref int numPrims)
        {
            numVerts = mPathMeshVerts.Count;
            numPrims = mPathMeshTris.Count;

            int numInds = numPrims * 3;

            vb = new VertexBuffer(typeof(VertexTypes.Pos_Color), numVerts, BRenderDevice.getDevice(), Usage.None, VertexTypes.Pos_Color.FVF_Flags, Pool.Managed);
            GraphicsStream gStream = vb.Lock(0, 0, LockFlags.None);

            unsafe
            {
                VertexTypes.Pos_Color *vP = (VertexTypes.Pos_Color *)gStream.InternalDataPointer;
                for (int i = 0; i < numVerts; i++)
                {
                    vP[i].x     = mPathMeshVerts[i].X;
                    vP[i].y     = mPathMeshVerts[i].Y;
                    vP[i].z     = mPathMeshVerts[i].Z;
                    vP[i].color = 0x440000FF;
                }
            }

            vb.Unlock();


            ib      = new IndexBuffer(typeof(int), numInds, BRenderDevice.getDevice(), Usage.None, Pool.Managed);
            gStream = ib.Lock(0, 0, LockFlags.None);
            unsafe
            {
                int *iP = (int *)gStream.InternalDataPointer;
                for (int i = 0; i < numPrims; i++)
                {
                    iP[i * 3 + 0] = mPathMeshTris[i].vertIndex[0];
                    iP[i * 3 + 1] = mPathMeshTris[i].vertIndex[1];
                    iP[i * 3 + 2] = mPathMeshTris[i].vertIndex[2];
                }
            }
            ib.Unlock();
        }
Exemplo n.º 3
0
        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();
        }