Exemplo n.º 1
0
        public PatchGrid( Terrain terrain, int gridWidth, int gridHeight )
        {
            int highestRes = Patch.GetLevelResolution( Patch.HighestDetailLod );
            highestRes *= highestRes;

            VertexBufferFormat format = new VertexBufferFormat( );
            format.Add( VertexFieldSemantic.Position, VertexFieldElementTypeId.Float32, 3 );
            m_Vb = RbGraphics.Factory.CreateVertexBuffer( );
            m_Vb.Create( format, gridWidth * gridHeight * highestRes );

            m_Patches = new Patch[ gridWidth, gridHeight ];

            float z = -PatchDepth * ( gridHeight / 2 );
            float xInc = PatchWidth;
            float zInc = PatchDepth;

            float maxWidth = gridWidth * PatchWidth;
            float maxHeight = gridWidth * PatchDepth;

            terrain.SetTerrainArea( maxWidth, maxHeight );

            int vbOffset = 0;

            for ( int row = 0; row < gridHeight; ++row, z += zInc )
            {
                float x = -PatchWidth * ( gridWidth / 2 );
                for ( int col = 0; col < gridWidth; ++col, x += xInc )
                {
                    Color c = ( ( col + row ) % 2 ) == 0 ? Color.Black : Color.White;

                    m_Patches[ col, row ] = new Patch( terrain, vbOffset, x, z, PatchWidth, PatchDepth, c );
                    vbOffset += highestRes;
                }
            }

            int maxCol = gridWidth - 1;
            int maxRow = gridHeight - 1;
            for ( int row = 0; row < gridHeight; ++row )
            {
                for ( int col = 0; col < gridWidth; ++col )
                {
                    Patch left	= ( col == 0 ) ? null : ( m_Patches[ col - 1, row ] );
                    Patch right	= ( col == maxCol ) ? null : ( m_Patches[ col + 1, row ] );
                    Patch up	= ( row == 0 ) ? null : ( m_Patches[ col, row - 1] );
                    Patch down	= ( row == maxRow ) ? null : ( m_Patches[ col, row + 1 ] );

                    m_Patches[ col, row ].Link( left, right, up, down );
                }
            }
        }
Exemplo n.º 2
0
        public QuadPatch( Terrain terrain, QuadPatchVertices vertices, Color patchColour, float x, float z, float w, float d )
        {
            m_Rs.FaceRenderMode = PolygonRenderMode.Lines;
            m_Rs.Colour = patchColour;

            m_Terrain = terrain;
            m_Vertices = vertices;
            m_X = x;
            m_Z = z;
            m_Width = w;
            m_Depth = d;

            m_IncreaseDetailDistance = float.MaxValue;
            m_VbIndex = vertices.Allocate( );

            m_BuildVertices = true;
            m_BuildIndices = true;
        }
 public QuadPatchTree( Terrain terrain )
 {
     terrain.SetTerrainArea( Width, Height );
     m_Vertices = new QuadPatchVertices( );
     m_Root = new QuadPatch( terrain, m_Vertices, Color.Black, -Width / 2, -Height / 2, Width, Height );
 }