public BatchItem(TextureCoordinates texcoords, Vector position, Vector size, float rotation) { Texcoords = texcoords; Position = position; Size = size; Rotation = rotation; }
public BatchItem(TextureCoordinates texcoords, ShapeCache cache, Vector position, Vector size, float rotation, Image image, Color color) { Cache = cache; Texcoords = texcoords; Position = position; Size = size; Rotation = rotation; Image = image; Color = color; }
public void Draw(TextureCoordinates c, Vector position, Vector size, float angle) { Debug.Assert(beginHasBeenCalled); if (iTexture >= BufferSize) { Flush(); } Matrix matrix = Matrix.CreateScale((float)size.X, (float)size.Y, 1f) * Matrix.CreateRotationZ(angle) * Matrix.CreateTranslation((float)position.X, (float)position.Y, 0); Vector3[] transformedPoints = new Vector3[VerticesPerTexture]; for (int i = 0; i < transformedPoints.Length; i++) { transformedPoints[i] = Vector3.Transform(Vertices[i], matrix); } uint startIndex = (iTexture * VerticesPerTexture); for (int i = 0; i < VerticesPerTexture; i++) { uint bi = (uint)((iTexture * VerticesPerTexture) + i); vertexBuffer[bi].Position = transformedPoints[i]; } var color = System.Drawing.Color.FromArgb(255, 255, 255, 255); // Triangle 1 vertexBuffer[startIndex + 0].TexCoords = new Vector2((float)c.TopLeft.X, (float)c.TopLeft.Y); vertexBuffer[startIndex + 0].SetColor(color); vertexBuffer[startIndex + 1].TexCoords = new Vector2((float)c.BottomLeft.X, (float)c.BottomLeft.Y); vertexBuffer[startIndex + 1].SetColor(color); vertexBuffer[startIndex + 2].TexCoords = new Vector2((float)c.TopRight.X, (float)c.TopRight.Y); vertexBuffer[startIndex + 2].SetColor(color); // Triangle 2 vertexBuffer[startIndex + 3].TexCoords = new Vector2((float)c.BottomLeft.X, (float)c.BottomLeft.Y); vertexBuffer[startIndex + 3].SetColor(color); vertexBuffer[startIndex + 4].TexCoords = new Vector2((float)c.BottomRight.X, (float)c.BottomRight.Y); vertexBuffer[startIndex + 4].SetColor(color); vertexBuffer[startIndex + 5].TexCoords = new Vector2((float)c.TopRight.X, (float)c.TopRight.Y); vertexBuffer[startIndex + 5].SetColor(color); iTexture++; }
public void AddImage(Matrix4x4 matrix, Image image, TextureCoordinates texcoords, Vector position, Vector size, float rotation) { if (!ImageBatches.ContainsKey(image)) { ImageBatches.Add(image, new Dictionary <Matrix4x4, List <BatchItem> >()); } Dictionary <Matrix4x4, List <BatchItem> > batch = ImageBatches[image]; if (batch.TryGetValue(matrix, out List <BatchItem> list)) { if (list == null) { list = new List <BatchItem>(); batch[matrix] = list; } list.Add(new BatchItem(texcoords, position, size, rotation)); } else { batch.Add(matrix, new List <BatchItem>()); batch[matrix].Add(new BatchItem(texcoords, position, size, rotation)); } }
public void AddShader(Matrix4x4 matrix, IShader shader, Image image, TextureCoordinates texcoords, Vector position, Vector size, float rotation) { AddShader(matrix, shader, image, default, null, texcoords, position, size, rotation);