Vector3.cs 27 KB

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