Advertisement
szymski

Untitled

Aug 21st, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SrajtasmaEngine
  8. {
  9. [Serializable]
  10. public class Vector2
  11. {
  12. public float x = 0;
  13. public float y = 0;
  14.  
  15. public Vector2()
  16. {
  17.  
  18. }
  19.  
  20. public Vector2(float x, float y)
  21. {
  22. this.x = x;
  23. this.y = y;
  24. }
  25.  
  26. public float length
  27. {
  28. get
  29. {
  30. return (float)Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
  31. }
  32. }
  33.  
  34. public float angle
  35. {
  36. get
  37. {
  38. return (float)(Math.Atan2(x, y) * (180 / Math.PI));
  39. }
  40. }
  41.  
  42. public Vector2 floored
  43. {
  44. get
  45. {
  46. return new Vector2((float)Math.Floor(x), (float)Math.Floor(y));
  47. }
  48. }
  49.  
  50. public Vector2 rounded
  51. {
  52. get
  53. {
  54. return new Vector2((float)Math.Round(x), (float)Math.Round(y));
  55. }
  56. }
  57.  
  58. public Vector2 normalized
  59. {
  60. get
  61. {
  62. float len = length;
  63. return new Vector2(x/length, y/length);
  64. }
  65. }
  66.  
  67. public static Vector2 operator +(Vector2 v1, Vector2 v2)
  68. {
  69. return new Vector2(v1.x + v2.x, v1.y + v2.y);
  70. }
  71.  
  72. public static Vector2 operator -(Vector2 v1, Vector2 v2)
  73. {
  74. return new Vector2(v1.x - v2.x, v1.y - v2.y);
  75. }
  76.  
  77. public static Vector2 operator *(Vector2 v1, float value)
  78. {
  79. return new Vector2(v1.x * value, v1.y * value);
  80. }
  81.  
  82. public static Vector2 operator /(Vector2 v1, float value)
  83. {
  84. return new Vector2(v1.x / value, v1.y / value);
  85. }
  86.  
  87. public static bool operator ==(Vector2 v1, Vector2 v2)
  88. {
  89. return (v1.x == v2.x && v1.y == v2.y);
  90. }
  91.  
  92. public static bool operator !=(Vector2 v1, Vector2 v2)
  93. {
  94. return !(v1.x == v2.x && v1.y == v2.y);
  95. }
  96.  
  97. public override string ToString()
  98. {
  99. return x + ", " + y;
  100. }
  101.  
  102. public static implicit operator SFML.Window.Vector2f(Vector2 vec)
  103. {
  104. return new SFML.Window.Vector2f(vec.x, vec.y);
  105. }
  106.  
  107. public static implicit operator SFML.Window.Vector2i(Vector2 vec)
  108. {
  109. return new SFML.Window.Vector2i((int)vec.x, (int)vec.y);
  110. }
  111.  
  112. public static Vector2 FromAngle(float angle)
  113. {
  114. return new Vector2(MathUtils.Cos(angle), -MathUtils.Sin(angle));
  115. }
  116.  
  117. public static bool IsInRange(Vector2 position, Vector2 size, Vector2 vector)
  118. {
  119. if (vector.x > position.x && vector.y > position.y && vector.x < position.x + size.x && vector.y < position.y + size.y) return true;
  120. return false;
  121. }
  122.  
  123. public static float Distance(Vector2 vec1, Vector2 vec2)
  124. {
  125. return (float)Math.Sqrt(Math.Pow((vec1 - vec2).x, 2) + Math.Pow((vec1 - vec2).y, 2));
  126. }
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement