Beispiel #1
0
 public Yacht(Game game)
     : base(game)
 {
     vertexFormat = new VertexPositionNormalTexture2();
 }
Beispiel #2
0
 public FoliageTree1(Game game)
     : base(game)
 {
     vertexFormat = new VertexPositionNormalTexture2();
 }
Beispiel #3
0
 public ShipNatlaRoom(Game game)
     : base(game)
 {
     vertexFormat = new VertexPositionNormalTexture2();
 }
Beispiel #4
0
 public ThailandMirrorStatueRight(Game game)
     : base(game)
 {
     vertexFormat = new VertexPositionNormalTexture2();
 }
Beispiel #5
0
        public PatchContent Build()
        {
            #region Local vertex buffer

            // create local vertex buffer for patch
            int numVertices = _patchSize * _patchSize;
            VertexBufferContent localVertexBuffer = new VertexBufferContent(numVertices);

            // fill vertex buffer
            VertexPositionNormalTexture2[] vertices = new VertexPositionNormalTexture2[numVertices];

            int nStartX = _patchOffsetX * (_patchSize - 1);
            int nStartY = _patchOffsetY * (_patchSize - 1);
            int nEndX   = nStartX + _patchSize;
            int nEndY   = nStartY + _patchSize;

            float fMinZ = float.MaxValue, fMaxZ = float.MinValue;
            int   index = 0;
            for (int y = nStartY; y < nEndY; y++)
            {
                for (int x = nStartX; x < nEndX; x++)
                {
                    // write local data
                    float fZ = _heightMap[x, y];

                    if (fZ < fMinZ)
                    {
                        fMinZ = fZ;
                    }
                    if (fZ > fMaxZ)
                    {
                        fMaxZ = fZ;
                    }

                    Vector2 texCoords1 = new Vector2(x / (float)(_heightMap.Width - 1), y / (float)(_heightMap.Height - 1));
                    Vector2 texCoords2 = texCoords1 * _detailTextureTiling;

                    vertices[index++] = new VertexPositionNormalTexture2(
                        new Vector3(x * _horizontalScale, fZ, y * _horizontalScale),
                        new Vector3(0, 1, 0),
                        texCoords1,
                        texCoords2);
                }
            }

            localVertexBuffer.Write(0, VertexBufferContent.SizeOf(typeof(VertexPositionNormalTexture2)), vertices);
            localVertexBuffer.VertexDeclaration = new VertexDeclarationContent();
            foreach (VertexElement vertexElement in VertexPositionNormalTexture2.VertexDeclaration.GetVertexElements())
            {
                localVertexBuffer.VertexDeclaration.VertexElements.Add(vertexElement);
            }

            #endregion

            LevelContent[] levels = new LevelContent[_numLevels];
            for (int i = 0; i < _numLevels; i++)
            {
                LevelContentBuilder levelContentBuilder = new LevelContentBuilder(_heightMap, _patchSize, _numLevels, i, nStartX,
                                                                                  nEndX, nStartY, nEndY);
                levels[i] = levelContentBuilder.Build();
            }

            #region Bounding box, centre, and offset

            BoundingBox boundingBox = new BoundingBox(
                new Vector3(nStartX * _horizontalScale, fMinZ, nStartY * _horizontalScale),
                new Vector3(nEndX * _horizontalScale, fMaxZ, nEndY * _horizontalScale));

            float fAverageZ = (fMinZ + fMaxZ) / 2.0f;

            Vector3 center = new Vector3(
                (nStartX + ((_patchSize - 1) / 2.0f)) * _horizontalScale,
                fAverageZ,
                (nStartY + ((_patchSize - 1) / 2.0f)) * _horizontalScale);

            Vector2 offset = new Vector2(
                (_patchOffsetX * (_patchSize - 1)) * _horizontalScale,
                (_patchOffsetY * (_patchSize - 1)) * _horizontalScale);

            #endregion

            return(new PatchContent
            {
                VertexBuffer = localVertexBuffer,
                Levels = levels,
                BoundingBox = boundingBox,
                Center = center,
                Offset = offset
            });
        }