Vector3.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. using System;
  2. using System.Globalization;
  3. namespace PF
  4. {
  5. [Serializable]
  6. public struct Vector3: IEquatable<Vector3>
  7. {
  8. private const float k1OverSqrt2 = 0.7071068f;
  9. private const float epsilon = 1E-05f;
  10. public static readonly Vector3 zero = new Vector3();
  11. public static readonly Vector3 one = new Vector3(1f, 1f, 1f);
  12. public static readonly Vector3 up = new Vector3(0.0f, 1f, 0.0f);
  13. public static readonly Vector3 down = new Vector3(0.0f, -1f, 0.0f);
  14. public static readonly Vector3 right = new Vector3(1f, 0.0f, 0.0f);
  15. public static readonly Vector3 left = new Vector3(-1f, 0.0f, 0.0f);
  16. public static readonly Vector3 forward = new Vector3(0.0f, 0.0f, 1f);
  17. public static readonly Vector3 back = new Vector3(0.0f, 0.0f, -1f);
  18. public float x;
  19. public float y;
  20. public float z;
  21. #if !SERVER
  22. public static implicit operator UnityEngine.Vector3(Vector3 v3)
  23. {
  24. return new UnityEngine.Vector3(v3.x, v3.y, v3.z);
  25. }
  26. public static implicit operator Vector3(UnityEngine.Vector3 v3)
  27. {
  28. return new Vector3(v3.x, v3.y, v3.z);
  29. }
  30. #endif
  31. public Vector3(float x, float y, float z)
  32. {
  33. this.x = x;
  34. this.y = y;
  35. this.z = z;
  36. }
  37. public Vector3(float value)
  38. {
  39. this.x = this.y = this.z = value;
  40. }
  41. public Vector3(Vector2 value, float z)
  42. {
  43. this.x = value.x;
  44. this.y = value.y;
  45. this.z = z;
  46. }
  47. public override string ToString()
  48. {
  49. CultureInfo currentCulture = CultureInfo.CurrentCulture;
  50. return string.Format((IFormatProvider) currentCulture, "({0}, {1}, {2})", (object) this.x.ToString((IFormatProvider) currentCulture),
  51. (object) this.y.ToString((IFormatProvider) currentCulture),
  52. (object) this.z.ToString((IFormatProvider) currentCulture));
  53. }
  54. public bool Equals(Vector3 other)
  55. {
  56. if ((double) this.x == (double) other.x && (double) this.y == (double) other.y)
  57. return (double) this.z == (double) other.z;
  58. return false;
  59. }
  60. public override bool Equals(object obj)
  61. {
  62. bool flag = false;
  63. if (obj is Vector3)
  64. flag = this.Equals((Vector3) obj);
  65. return flag;
  66. }
  67. public override int GetHashCode()
  68. {
  69. return this.x.GetHashCode() + this.y.GetHashCode() + this.z.GetHashCode();
  70. }
  71. public float Length()
  72. {
  73. return (float) Math.Sqrt((double) this.x * (double) this.x + (double) this.y * (double) this.y + (double) this.z * (double) this.z);
  74. }
  75. public float LengthSquared()
  76. {
  77. return (float) ((double) this.x * (double) this.x + (double) this.y * (double) this.y + (double) this.z * (double) this.z);
  78. }
  79. public float magnitude
  80. {
  81. get
  82. {
  83. return this.Length();
  84. }
  85. }
  86. public float sqrMagnitude
  87. {
  88. get
  89. {
  90. return this.LengthSquared();
  91. }
  92. }
  93. public static float Distance(Vector3 value1, Vector3 value2)
  94. {
  95. float num1 = value1.x - value2.x;
  96. float num2 = value1.y - value2.y;
  97. float num3 = value1.z - value2.z;
  98. return (float) Math.Sqrt((double) num1 * (double) num1 + (double) num2 * (double) num2 + (double) num3 * (double) num3);
  99. }
  100. public static void Distance(ref Vector3 value1, ref Vector3 value2, out float result)
  101. {
  102. float num1 = value1.x - value2.x;
  103. float num2 = value1.y - value2.y;
  104. float num3 = value1.z - value2.z;
  105. float num4 = (float) ((double) num1 * (double) num1 + (double) num2 * (double) num2 + (double) num3 * (double) num3);
  106. result = (float) Math.Sqrt((double) num4);
  107. }
  108. public static float DistanceSquared(Vector3 value1, Vector3 value2)
  109. {
  110. float num1 = value1.x - value2.x;
  111. float num2 = value1.y - value2.y;
  112. float num3 = value1.z - value2.z;
  113. return (float) ((double) num1 * (double) num1 + (double) num2 * (double) num2 + (double) num3 * (double) num3);
  114. }
  115. public static void DistanceSquared(ref Vector3 value1, ref Vector3 value2, out float result)
  116. {
  117. float num1 = value1.x - value2.x;
  118. float num2 = value1.y - value2.y;
  119. float num3 = value1.z - value2.z;
  120. result = (float) ((double) num1 * (double) num1 + (double) num2 * (double) num2 + (double) num3 * (double) num3);
  121. }
  122. public static float Dot(Vector3 vector1, Vector3 vector2)
  123. {
  124. return (float) ((double) vector1.x * (double) vector2.x + (double) vector1.y * (double) vector2.y +
  125. (double) vector1.z * (double) vector2.z);
  126. }
  127. public static void Dot(ref Vector3 vector1, ref Vector3 vector2, out float result)
  128. {
  129. result = (float) ((double) vector1.x * (double) vector2.x + (double) vector1.y * (double) vector2.y +
  130. (double) vector1.z * (double) vector2.z);
  131. }
  132. public void Normalize()
  133. {
  134. float num1 = (float) ((double) this.x * (double) this.x + (double) this.y * (double) this.y + (double) this.z * (double) this.z);
  135. if ((double) num1 < (double) Mathf.Epsilon)
  136. return;
  137. float num2 = 1f / (float) Math.Sqrt((double) num1);
  138. this.x *= num2;
  139. this.y *= num2;
  140. this.z *= num2;
  141. }
  142. public Vector3 normalized
  143. {
  144. get
  145. {
  146. return Vector3.Normalize(this);
  147. }
  148. }
  149. public static Vector3 Normalize(Vector3 value)
  150. {
  151. float num1 = (float) ((double) value.x * (double) value.x + (double) value.y * (double) value.y + (double) value.z * (double) value.z);
  152. if ((double) num1 < (double) Mathf.Epsilon)
  153. return value;
  154. float num2 = 1f / (float) Math.Sqrt((double) num1);
  155. Vector3 vector3;
  156. vector3.x = value.x * num2;
  157. vector3.y = value.y * num2;
  158. vector3.z = value.z * num2;
  159. return vector3;
  160. }
  161. public static void Normalize(ref Vector3 value, out Vector3 result)
  162. {
  163. float num1 = (float) ((double) value.x * (double) value.x + (double) value.y * (double) value.y + (double) value.z * (double) value.z);
  164. if ((double) num1 < (double) Mathf.Epsilon)
  165. {
  166. result = value;
  167. }
  168. else
  169. {
  170. float num2 = 1f / (float) Math.Sqrt((double) num1);
  171. result.x = value.x * num2;
  172. result.y = value.y * num2;
  173. result.z = value.z * num2;
  174. }
  175. }
  176. public static Vector3 Cross(Vector3 vector1, Vector3 vector2)
  177. {
  178. Vector3 vector3;
  179. vector3.x = (float) ((double) vector1.y * (double) vector2.z - (double) vector1.z * (double) vector2.y);
  180. vector3.y = (float) ((double) vector1.z * (double) vector2.x - (double) vector1.x * (double) vector2.z);
  181. vector3.z = (float) ((double) vector1.x * (double) vector2.y - (double) vector1.y * (double) vector2.x);
  182. return vector3;
  183. }
  184. public static void Cross(ref Vector3 vector1, ref Vector3 vector2, out Vector3 result)
  185. {
  186. float num1 = (float) ((double) vector1.y * (double) vector2.z - (double) vector1.z * (double) vector2.y);
  187. float num2 = (float) ((double) vector1.z * (double) vector2.x - (double) vector1.x * (double) vector2.z);
  188. float num3 = (float) ((double) vector1.x * (double) vector2.y - (double) vector1.y * (double) vector2.x);
  189. result.x = num1;
  190. result.y = num2;
  191. result.z = num3;
  192. }
  193. public static Vector3 Reflect(Vector3 vector, Vector3 normal)
  194. {
  195. float num =
  196. (float) ((double) vector.x * (double) normal.x + (double) vector.y * (double) normal.y + (double) vector.z * (double) normal.z);
  197. Vector3 vector3;
  198. vector3.x = vector.x - 2f * num * normal.x;
  199. vector3.y = vector.y - 2f * num * normal.y;
  200. vector3.z = vector.z - 2f * num * normal.z;
  201. return vector3;
  202. }
  203. public static void Reflect(ref Vector3 vector, ref Vector3 normal, out Vector3 result)
  204. {
  205. float num =
  206. (float) ((double) vector.x * (double) normal.x + (double) vector.y * (double) normal.y + (double) vector.z * (double) normal.z);
  207. result.x = vector.x - 2f * num * normal.x;
  208. result.y = vector.y - 2f * num * normal.y;
  209. result.z = vector.z - 2f * num * normal.z;
  210. }
  211. public static Vector3 Min(Vector3 value1, Vector3 value2)
  212. {
  213. Vector3 vector3;
  214. vector3.x = (double) value1.x < (double) value2.x? value1.x : value2.x;
  215. vector3.y = (double) value1.y < (double) value2.y? value1.y : value2.y;
  216. vector3.z = (double) value1.z < (double) value2.z? value1.z : value2.z;
  217. return vector3;
  218. }
  219. public static void Min(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
  220. {
  221. result.x = (double) value1.x < (double) value2.x? value1.x : value2.x;
  222. result.y = (double) value1.y < (double) value2.y? value1.y : value2.y;
  223. result.z = (double) value1.z < (double) value2.z? value1.z : value2.z;
  224. }
  225. public static Vector3 Max(Vector3 value1, Vector3 value2)
  226. {
  227. Vector3 vector3;
  228. vector3.x = (double) value1.x > (double) value2.x? value1.x : value2.x;
  229. vector3.y = (double) value1.y > (double) value2.y? value1.y : value2.y;
  230. vector3.z = (double) value1.z > (double) value2.z? value1.z : value2.z;
  231. return vector3;
  232. }
  233. public static void Max(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
  234. {
  235. result.x = (double) value1.x > (double) value2.x? value1.x : value2.x;
  236. result.y = (double) value1.y > (double) value2.y? value1.y : value2.y;
  237. result.z = (double) value1.z > (double) value2.z? value1.z : value2.z;
  238. }
  239. public static Vector3 Clamp(Vector3 value1, Vector3 min, Vector3 max)
  240. {
  241. float x = value1.x;
  242. float num1 = (double) x > (double) max.x? max.x : x;
  243. float num2 = (double) num1 < (double) min.x? min.x : num1;
  244. float y = value1.y;
  245. float num3 = (double) y > (double) max.y? max.y : y;
  246. float num4 = (double) num3 < (double) min.y? min.y : num3;
  247. float z = value1.z;
  248. float num5 = (double) z > (double) max.z? max.z : z;
  249. float num6 = (double) num5 < (double) min.z? min.z : num5;
  250. Vector3 vector3;
  251. vector3.x = num2;
  252. vector3.y = num4;
  253. vector3.z = num6;
  254. return vector3;
  255. }
  256. public static void Clamp(ref Vector3 value1, ref Vector3 min, ref Vector3 max, out Vector3 result)
  257. {
  258. float x = value1.x;
  259. float num1 = (double) x > (double) max.x? max.x : x;
  260. float num2 = (double) num1 < (double) min.x? min.x : num1;
  261. float y = value1.y;
  262. float num3 = (double) y > (double) max.y? max.y : y;
  263. float num4 = (double) num3 < (double) min.y? min.y : num3;
  264. float z = value1.z;
  265. float num5 = (double) z > (double) max.z? max.z : z;
  266. float num6 = (double) num5 < (double) min.z? min.z : num5;
  267. result.x = num2;
  268. result.y = num4;
  269. result.z = num6;
  270. }
  271. public static Vector3 Lerp(Vector3 value1, Vector3 value2, float amount)
  272. {
  273. Vector3 vector3;
  274. vector3.x = value1.x + (value2.x - value1.x) * amount;
  275. vector3.y = value1.y + (value2.y - value1.y) * amount;
  276. vector3.z = value1.z + (value2.z - value1.z) * amount;
  277. return vector3;
  278. }
  279. public static void Lerp(ref Vector3 value1, ref Vector3 value2, float amount, out Vector3 result)
  280. {
  281. result.x = value1.x + (value2.x - value1.x) * amount;
  282. result.y = value1.y + (value2.y - value1.y) * amount;
  283. result.z = value1.z + (value2.z - value1.z) * amount;
  284. }
  285. public static Vector3 SmoothStep(Vector3 value1, Vector3 value2, float amount)
  286. {
  287. amount = (double) amount > 1.0? 1f : ((double) amount < 0.0? 0.0f : amount);
  288. amount = (float) ((double) amount * (double) amount * (3.0 - 2.0 * (double) amount));
  289. Vector3 vector3;
  290. vector3.x = value1.x + (value2.x - value1.x) * amount;
  291. vector3.y = value1.y + (value2.y - value1.y) * amount;
  292. vector3.z = value1.z + (value2.z - value1.z) * amount;
  293. return vector3;
  294. }
  295. public static void SmoothStep(ref Vector3 value1, ref Vector3 value2, float amount, out Vector3 result)
  296. {
  297. amount = (double) amount > 1.0? 1f : ((double) amount < 0.0? 0.0f : amount);
  298. amount = (float) ((double) amount * (double) amount * (3.0 - 2.0 * (double) amount));
  299. result.x = value1.x + (value2.x - value1.x) * amount;
  300. result.y = value1.y + (value2.y - value1.y) * amount;
  301. result.z = value1.z + (value2.z - value1.z) * amount;
  302. }
  303. public static Vector3 Hermite(Vector3 value1, Vector3 tangent1, Vector3 value2, Vector3 tangent2, float amount)
  304. {
  305. float num1 = amount * amount;
  306. float num2 = amount * num1;
  307. float num3 = (float) (2.0 * (double) num2 - 3.0 * (double) num1 + 1.0);
  308. float num4 = (float) (-2.0 * (double) num2 + 3.0 * (double) num1);
  309. float num5 = num2 - 2f * num1 + amount;
  310. float num6 = num2 - num1;
  311. Vector3 vector3;
  312. vector3.x = (float) ((double) value1.x * (double) num3 + (double) value2.x * (double) num4 + (double) tangent1.x * (double) num5 +
  313. (double) tangent2.x * (double) num6);
  314. vector3.y = (float) ((double) value1.y * (double) num3 + (double) value2.y * (double) num4 + (double) tangent1.y * (double) num5 +
  315. (double) tangent2.y * (double) num6);
  316. vector3.z = (float) ((double) value1.z * (double) num3 + (double) value2.z * (double) num4 + (double) tangent1.z * (double) num5 +
  317. (double) tangent2.z * (double) num6);
  318. return vector3;
  319. }
  320. public static void Hermite(
  321. ref Vector3 value1, ref Vector3 tangent1, ref Vector3 value2, ref Vector3 tangent2, float amount, out Vector3 result)
  322. {
  323. float num1 = amount * amount;
  324. float num2 = amount * num1;
  325. float num3 = (float) (2.0 * (double) num2 - 3.0 * (double) num1 + 1.0);
  326. float num4 = (float) (-2.0 * (double) num2 + 3.0 * (double) num1);
  327. float num5 = num2 - 2f * num1 + amount;
  328. float num6 = num2 - num1;
  329. result.x = (float) ((double) value1.x * (double) num3 + (double) value2.x * (double) num4 + (double) tangent1.x * (double) num5 +
  330. (double) tangent2.x * (double) num6);
  331. result.y = (float) ((double) value1.y * (double) num3 + (double) value2.y * (double) num4 + (double) tangent1.y * (double) num5 +
  332. (double) tangent2.y * (double) num6);
  333. result.z = (float) ((double) value1.z * (double) num3 + (double) value2.z * (double) num4 + (double) tangent1.z * (double) num5 +
  334. (double) tangent2.z * (double) num6);
  335. }
  336. public static Vector3 Negate(Vector3 value)
  337. {
  338. Vector3 vector3;
  339. vector3.x = -value.x;
  340. vector3.y = -value.y;
  341. vector3.z = -value.z;
  342. return vector3;
  343. }
  344. public static void Negate(ref Vector3 value, out Vector3 result)
  345. {
  346. result.x = -value.x;
  347. result.y = -value.y;
  348. result.z = -value.z;
  349. }
  350. public static Vector3 Add(Vector3 value1, Vector3 value2)
  351. {
  352. Vector3 vector3;
  353. vector3.x = value1.x + value2.x;
  354. vector3.y = value1.y + value2.y;
  355. vector3.z = value1.z + value2.z;
  356. return vector3;
  357. }
  358. public static void Add(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
  359. {
  360. result.x = value1.x + value2.x;
  361. result.y = value1.y + value2.y;
  362. result.z = value1.z + value2.z;
  363. }
  364. public static Vector3 Sub(Vector3 value1, Vector3 value2)
  365. {
  366. Vector3 vector3;
  367. vector3.x = value1.x - value2.x;
  368. vector3.y = value1.y - value2.y;
  369. vector3.z = value1.z - value2.z;
  370. return vector3;
  371. }
  372. public static void Sub(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
  373. {
  374. result.x = value1.x - value2.x;
  375. result.y = value1.y - value2.y;
  376. result.z = value1.z - value2.z;
  377. }
  378. public static Vector3 Multiply(Vector3 value1, Vector3 value2)
  379. {
  380. Vector3 vector3;
  381. vector3.x = value1.x * value2.x;
  382. vector3.y = value1.y * value2.y;
  383. vector3.z = value1.z * value2.z;
  384. return vector3;
  385. }
  386. public static void Multiply(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
  387. {
  388. result.x = value1.x * value2.x;
  389. result.y = value1.y * value2.y;
  390. result.z = value1.z * value2.z;
  391. }
  392. public static Vector3 Multiply(Vector3 value1, float scaleFactor)
  393. {
  394. Vector3 vector3;
  395. vector3.x = value1.x * scaleFactor;
  396. vector3.y = value1.y * scaleFactor;
  397. vector3.z = value1.z * scaleFactor;
  398. return vector3;
  399. }
  400. public static void Multiply(ref Vector3 value1, float scaleFactor, out Vector3 result)
  401. {
  402. result.x = value1.x * scaleFactor;
  403. result.y = value1.y * scaleFactor;
  404. result.z = value1.z * scaleFactor;
  405. }
  406. public static Vector3 Divide(Vector3 value1, Vector3 value2)
  407. {
  408. Vector3 vector3;
  409. vector3.x = value1.x / value2.x;
  410. vector3.y = value1.y / value2.y;
  411. vector3.z = value1.z / value2.z;
  412. return vector3;
  413. }
  414. public static void Divide(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
  415. {
  416. result.x = value1.x / value2.x;
  417. result.y = value1.y / value2.y;
  418. result.z = value1.z / value2.z;
  419. }
  420. public static Vector3 Divide(Vector3 value1, float divider)
  421. {
  422. float num = 1f / divider;
  423. Vector3 vector3;
  424. vector3.x = value1.x * num;
  425. vector3.y = value1.y * num;
  426. vector3.z = value1.z * num;
  427. return vector3;
  428. }
  429. public static void Divide(ref Vector3 value1, float divider, out Vector3 result)
  430. {
  431. float num = 1f / divider;
  432. result.x = value1.x * num;
  433. result.y = value1.y * num;
  434. result.z = value1.z * num;
  435. }
  436. private static float magnitudeStatic(ref Vector3 inV)
  437. {
  438. return (float) Math.Sqrt((double) Vector3.Dot(inV, inV));
  439. }
  440. private static Vector3 orthoNormalVectorFast(ref Vector3 n)
  441. {
  442. Vector3 vector3;
  443. if ((double) Math.Abs(n.z) > (double) Vector3.k1OverSqrt2)
  444. {
  445. float num = 1f / (float) Math.Sqrt((double) n.y * (double) n.y + (double) n.z * (double) n.z);
  446. vector3.x = 0.0f;
  447. vector3.y = -n.z * num;
  448. vector3.z = n.y * num;
  449. }
  450. else
  451. {
  452. float num = 1f / (float) Math.Sqrt((double) n.x * (double) n.x + (double) n.y * (double) n.y);
  453. vector3.x = -n.y * num;
  454. vector3.y = n.x * num;
  455. vector3.z = 0.0f;
  456. }
  457. return vector3;
  458. }
  459. public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent)
  460. {
  461. float num1 = Vector3.magnitudeStatic(ref normal);
  462. if ((double) num1 > (double) Mathf.Epsilon)
  463. normal /= num1;
  464. else
  465. normal = new Vector3(1f, 0.0f, 0.0f);
  466. float num2 = Vector3.Dot(normal, tangent);
  467. tangent -= num2 * normal;
  468. float num3 = Vector3.magnitudeStatic(ref tangent);
  469. if ((double) num3 < (double) Mathf.Epsilon)
  470. tangent = Vector3.orthoNormalVectorFast(ref normal);
  471. else
  472. tangent /= num3;
  473. }
  474. public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent, ref Vector3 binormal)
  475. {
  476. float num1 = Vector3.magnitudeStatic(ref normal);
  477. if ((double) num1 > (double) Mathf.Epsilon)
  478. normal /= num1;
  479. else
  480. normal = new Vector3(1f, 0.0f, 0.0f);
  481. float num2 = Vector3.Dot(normal, tangent);
  482. tangent -= num2 * normal;
  483. float num3 = Vector3.magnitudeStatic(ref tangent);
  484. if ((double) num3 > (double) Mathf.Epsilon)
  485. tangent /= num3;
  486. else
  487. tangent = Vector3.orthoNormalVectorFast(ref normal);
  488. float num4 = Vector3.Dot(tangent, binormal);
  489. float num5 = Vector3.Dot(normal, binormal);
  490. binormal -= num5 * normal + num4 * tangent;
  491. float num6 = Vector3.magnitudeStatic(ref binormal);
  492. if ((double) num6 > (double) Mathf.Epsilon)
  493. binormal /= num6;
  494. else
  495. binormal = Vector3.Cross(normal, tangent);
  496. }
  497. public static Vector3 Project(Vector3 vector, Vector3 onNormal)
  498. {
  499. return onNormal * Vector3.Dot(vector, onNormal) / Vector3.Dot(onNormal, onNormal);
  500. }
  501. public static void Project(ref Vector3 vector, ref Vector3 onNormal, out Vector3 result)
  502. {
  503. result = onNormal * Vector3.Dot(vector, onNormal) / Vector3.Dot(onNormal, onNormal);
  504. }
  505. public static float Angle(Vector3 from, Vector3 to)
  506. {
  507. from.Normalize();
  508. to.Normalize();
  509. float result;
  510. Vector3.Dot(ref from, ref to, out result);
  511. return Mathf.Cos(Mathf.Clamp(result, -1f, 1f)) * 57.29578f;
  512. }
  513. public static void Angle(ref Vector3 from, ref Vector3 to, out float result)
  514. {
  515. from.Normalize();
  516. to.Normalize();
  517. float result1;
  518. Vector3.Dot(ref from, ref to, out result1);
  519. result = Mathf.Cos(Mathf.Clamp(result1, -1f, 1f)) * 57.29578f;
  520. }
  521. public static Vector3 operator -(Vector3 value)
  522. {
  523. Vector3 vector3;
  524. vector3.x = -value.x;
  525. vector3.y = -value.y;
  526. vector3.z = -value.z;
  527. return vector3;
  528. }
  529. public static bool operator ==(Vector3 lhs, Vector3 rhs)
  530. {
  531. return (double) (lhs - rhs).sqrMagnitude < 9.99999943962493E-11;
  532. }
  533. public static bool operator !=(Vector3 lhs, Vector3 rhs)
  534. {
  535. return !(lhs == rhs);
  536. }
  537. public static Vector3 operator +(Vector3 value1, Vector3 value2)
  538. {
  539. Vector3 vector3;
  540. vector3.x = value1.x + value2.x;
  541. vector3.y = value1.y + value2.y;
  542. vector3.z = value1.z + value2.z;
  543. return vector3;
  544. }
  545. public static Vector3 operator -(Vector3 value1, Vector3 value2)
  546. {
  547. Vector3 vector3;
  548. vector3.x = value1.x - value2.x;
  549. vector3.y = value1.y - value2.y;
  550. vector3.z = value1.z - value2.z;
  551. return vector3;
  552. }
  553. public static Vector3 operator *(Vector3 value1, Vector3 value2)
  554. {
  555. Vector3 vector3;
  556. vector3.x = value1.x * value2.x;
  557. vector3.y = value1.y * value2.y;
  558. vector3.z = value1.z * value2.z;
  559. return vector3;
  560. }
  561. public static Vector3 operator *(Vector3 value, float scaleFactor)
  562. {
  563. Vector3 vector3;
  564. vector3.x = value.x * scaleFactor;
  565. vector3.y = value.y * scaleFactor;
  566. vector3.z = value.z * scaleFactor;
  567. return vector3;
  568. }
  569. public static Vector3 operator *(float scaleFactor, Vector3 value)
  570. {
  571. Vector3 vector3;
  572. vector3.x = value.x * scaleFactor;
  573. vector3.y = value.y * scaleFactor;
  574. vector3.z = value.z * scaleFactor;
  575. return vector3;
  576. }
  577. public static Vector3 operator /(Vector3 value1, Vector3 value2)
  578. {
  579. Vector3 vector3;
  580. vector3.x = value1.x / value2.x;
  581. vector3.y = value1.y / value2.y;
  582. vector3.z = value1.z / value2.z;
  583. return vector3;
  584. }
  585. public static Vector3 operator /(Vector3 value, float divider)
  586. {
  587. float num = 1f / divider;
  588. Vector3 vector3;
  589. vector3.x = value.x * num;
  590. vector3.y = value.y * num;
  591. vector3.z = value.z * num;
  592. return vector3;
  593. }
  594. }
  595. }