Here are the examples of the csharp api System.Collections.Generic.ICollection.Add(VertexPositionColorTexture) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
19
Source : Map.cs
with GNU General Public License v3.0
from deccer
with GNU General Public License v3.0
from deccer
private VertexBuffer BuildLandVertexBuffer(GraphicsDevice graphicsDevice, int width, int height)
{
const int TileSize = 44;
const int TileSizeHalf = TileSize / 2;
void DrawSquare(int landId, int x, int y, float tileZ, float tileZEast, float tileZWest, float tileZSouth)
{
/*
var tile = tileZ == 0
? _textureAtlas.GetLandTile(landId)
: _textureAtlas.GetLandTextureTile(landId);
*/
/*
var tile = _textureAtlas.GetLandTile(landId);
*/
var tile = tileZ != 0
? _textureAtlas.GetLandTile(landId)
: _textureAtlas.GetLandTextureTile(landId);
var p0 = new Vector3(x + TileSizeHalf, y - tileZ * 4, tile.Uvws.V1.W);
var p1 = new Vector3(x + TileSize, y + TileSizeHalf - tileZEast * 4, tile.Uvws.V2.W);
var p2 = new Vector3(x, y + TileSizeHalf - tileZWest * 4, tile.Uvws.V3.W);
var p3 = new Vector3(x + TileSizeHalf, y + TileSize - tileZSouth * 4, tile.Uvws.V4.W);
var uv0 = new Vector2(tile.Uvws.V1.U, tile.Uvws.V1.V);
var uv1 = new Vector2(tile.Uvws.V2.U, tile.Uvws.V2.V);
var uv2 = new Vector2(tile.Uvws.V3.U, tile.Uvws.V3.V);
var uv3 = new Vector2(tile.Uvws.V4.U, tile.Uvws.V4.V);
var n1 = Vector3.Cross(p2 - p0, p1 - p0);
_landVertices.Add(new VertexPositionColorTexture(p0, Color.Red, uv0));
_landVertices.Add(new VertexPositionColorTexture(p1, Color.Red, uv1));
_landVertices.Add(new VertexPositionColorTexture(p2, Color.Red, uv2));
var n2 = Vector3.Cross(p2 - p3, p1 - p3);
_landVertices.Add(new VertexPositionColorTexture(p1, Color.Black, uv1));
_landVertices.Add(new VertexPositionColorTexture(p3, Color.Green, uv3));
_landVertices.Add(new VertexPositionColorTexture(p2, Color.Black, uv2));
}
for (var x = 0; x < width; ++x)
{
for (var y = 0; y < height; ++y)
{
var tileZ = GetTileZ(x, y, -15);
var tileZEast = GetTileZ(x + 1, y, tileZ);
var tileZWest = GetTileZ(x, y + 1, tileZ);
var tileZSouth = GetTileZ(x + 1, y + 1, tileZ);
var graphicId = _landTiles[(x, y)].TileId;
DrawSquare(graphicId, (x - y) * TileSizeHalf, (x + y) * TileSizeHalf, tileZ, tileZEast, tileZWest, tileZSouth);
}
}
var vertexBuffer = new VertexBuffer(
graphicsDevice,
typeof(VertexPositionColorTexture),
_landVertices.Count,
BufferUsage.WriteOnly
);
vertexBuffer.SetData(_landVertices.ToArray());
return vertexBuffer;
}