Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void PushSprite(Rectangle dest, Rectangle src, Vector2 origin, double rotation, bool flipH = false, bool flipV = false, float depth = 0f)
- {
- if (depth != 0.0f)
- {
- //Console.WriteLine($"Depth: {depth}");
- }
- float cos = (float) Math.Cos(rotation);
- float sin = (float) Math.Sin(rotation);
- //if (Game.Instance.Debug)
- //Console.WriteLine($"cos/sin: {cos} {sin}");
- float texLeft = (float)src.Left / Texture.Width;
- float texRight = (float)src.Right / Texture.Width;
- float texTop = (float)src.Top / Texture.Height;
- float texBottom = (float)src.Bottom / Texture.Height;
- //float originCorrectionX = origin.X * dest.Width;
- //float originCorrectionY = origin.Y * dest.Height;
- float cornerX = -origin.X * dest.Width;
- float cornerY = -origin.Y * dest.Height;
- float xOffset = (-sin * cornerY) + (cos * cornerX);// + originCorrectionX;
- float yOffset = (cos * cornerY) + (sin * cornerX);// + originCorrectionY;
- Vertex topLeft = new Vertex {
- x = dest.X + xOffset,
- y = dest.Y + yOffset,
- z = depth,
- u = flipH ? texRight : texLeft,
- v = flipV ? texBottom : texTop };
- cornerX = (1.0f - origin.X) * dest.Width;
- cornerY = -origin.Y * dest.Height;
- xOffset = (-sin * cornerY) + (cos * cornerX);// + originCorrectionX;
- yOffset = (cos * cornerY) + (sin * cornerX);// + originCorrectionY;
- Vertex topRight = new Vertex {
- x = dest.X + xOffset,
- y = dest.Y + yOffset,
- z = depth,
- u = flipH ? texLeft : texRight,
- v = flipV ? texBottom : texTop };
- cornerX = (1.0f - origin.X) * dest.Width;
- cornerY = (1.0f - origin.Y) * dest.Height;
- xOffset = (-sin * cornerY) + (cos * cornerX);// + originCorrectionX;
- yOffset = (cos * cornerY) + (sin * cornerX);// + originCorrectionY;
- Vertex bottomRight = new Vertex {
- x = dest.X + xOffset,
- y = dest.Y + yOffset,
- z = depth,
- u = flipH ? texLeft : texRight,
- v = flipV ? texTop : texBottom };
- cornerX = (-origin.X) * dest.Width;
- cornerY = (1.0f - origin.Y) * dest.Height;
- xOffset = (-sin * cornerY) + (cos * cornerX);// + originCorrectionX;
- yOffset = (cos * cornerY) + (sin * cornerX);// + originCorrectionY;
- Vertex bottomLeft = new Vertex {
- x = dest.X + xOffset,
- y = dest.Y + yOffset,
- z = depth,
- u = flipH ? texRight : texLeft,
- v = flipV ? texTop : texBottom };
- Vertex[] newVertices = new Vertex[]{topLeft, topRight, bottomRight, bottomLeft};
- newVertices.CopyTo(Vertices, VerticesIndex);
- ushort[] NewIndices = new ushort[] {
- (ushort)(VerticesIndex + 0), (ushort)(VerticesIndex + 1), (ushort)(VerticesIndex + 2),
- (ushort)(VerticesIndex + 2), (ushort)(VerticesIndex + 3), (ushort)(VerticesIndex + 0),
- };
- NewIndices.CopyTo(Indices, IndicesIndex);
- VerticesIndex += newVertices.Length;
- IndicesIndex += NewIndices.Length;
- NumSprites += 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement