Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. private void PushSprite(Rectangle dest, Rectangle src, Vector2 origin, double rotation, bool flipH = false, bool flipV = false, float depth = 0f)
  2. {
  3. if (depth != 0.0f)
  4. {
  5. //Console.WriteLine($"Depth: {depth}");
  6. }
  7. float cos = (float) Math.Cos(rotation);
  8. float sin = (float) Math.Sin(rotation);
  9. //if (Game.Instance.Debug)
  10. //Console.WriteLine($"cos/sin: {cos} {sin}");
  11. float texLeft = (float)src.Left / Texture.Width;
  12. float texRight = (float)src.Right / Texture.Width;
  13. float texTop = (float)src.Top / Texture.Height;
  14. float texBottom = (float)src.Bottom / Texture.Height;
  15.  
  16. //float originCorrectionX = origin.X * dest.Width;
  17. //float originCorrectionY = origin.Y * dest.Height;
  18.  
  19. float cornerX = -origin.X * dest.Width;
  20. float cornerY = -origin.Y * dest.Height;
  21. float xOffset = (-sin * cornerY) + (cos * cornerX);// + originCorrectionX;
  22. float yOffset = (cos * cornerY) + (sin * cornerX);// + originCorrectionY;
  23. Vertex topLeft = new Vertex {
  24. x = dest.X + xOffset,
  25. y = dest.Y + yOffset,
  26. z = depth,
  27. u = flipH ? texRight : texLeft,
  28. v = flipV ? texBottom : texTop };
  29.  
  30. cornerX = (1.0f - origin.X) * dest.Width;
  31. cornerY = -origin.Y * dest.Height;
  32. xOffset = (-sin * cornerY) + (cos * cornerX);// + originCorrectionX;
  33. yOffset = (cos * cornerY) + (sin * cornerX);// + originCorrectionY;
  34. Vertex topRight = new Vertex {
  35. x = dest.X + xOffset,
  36. y = dest.Y + yOffset,
  37. z = depth,
  38. u = flipH ? texLeft : texRight,
  39. v = flipV ? texBottom : texTop };
  40.  
  41. cornerX = (1.0f - origin.X) * dest.Width;
  42. cornerY = (1.0f - origin.Y) * dest.Height;
  43. xOffset = (-sin * cornerY) + (cos * cornerX);// + originCorrectionX;
  44. yOffset = (cos * cornerY) + (sin * cornerX);// + originCorrectionY;
  45. Vertex bottomRight = new Vertex {
  46. x = dest.X + xOffset,
  47. y = dest.Y + yOffset,
  48. z = depth,
  49. u = flipH ? texLeft : texRight,
  50. v = flipV ? texTop : texBottom };
  51.  
  52. cornerX = (-origin.X) * dest.Width;
  53. cornerY = (1.0f - origin.Y) * dest.Height;
  54. xOffset = (-sin * cornerY) + (cos * cornerX);// + originCorrectionX;
  55. yOffset = (cos * cornerY) + (sin * cornerX);// + originCorrectionY;
  56. Vertex bottomLeft = new Vertex {
  57. x = dest.X + xOffset,
  58. y = dest.Y + yOffset,
  59. z = depth,
  60. u = flipH ? texRight : texLeft,
  61. v = flipV ? texTop : texBottom };
  62.  
  63. Vertex[] newVertices = new Vertex[]{topLeft, topRight, bottomRight, bottomLeft};
  64. newVertices.CopyTo(Vertices, VerticesIndex);
  65.  
  66. ushort[] NewIndices = new ushort[] {
  67. (ushort)(VerticesIndex + 0), (ushort)(VerticesIndex + 1), (ushort)(VerticesIndex + 2),
  68. (ushort)(VerticesIndex + 2), (ushort)(VerticesIndex + 3), (ushort)(VerticesIndex + 0),
  69. };
  70.  
  71. NewIndices.CopyTo(Indices, IndicesIndex);
  72.  
  73. VerticesIndex += newVertices.Length;
  74. IndicesIndex += NewIndices.Length;
  75. NumSprites += 1;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement