Quaternion.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. #region License
  2. /*
  3. MIT License
  4. Copyright © 2006 The Mono.Xna Team
  5. All rights reserved.
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in all
  13. copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. SOFTWARE.
  21. */
  22. #endregion License
  23. using System;
  24. using System.ComponentModel;
  25. namespace MonoXnaCompactMaths
  26. {
  27. [Serializable]
  28. //[TypeConverter(typeof(QuaternionConverter))]
  29. public struct Quaternion : IEquatable<Quaternion>
  30. {
  31. public float X;
  32. public float Y;
  33. public float Z;
  34. public float W;
  35. static Quaternion identity = new Quaternion(0, 0, 0, 1);
  36. public Quaternion(float x, float y, float z, float w)
  37. {
  38. this.X = x;
  39. this.Y = y;
  40. this.Z = z;
  41. this.W = w;
  42. }
  43. public Quaternion(Vector3 vectorPart, float scalarPart)
  44. {
  45. this.X = vectorPart.X;
  46. this.Y = vectorPart.Y;
  47. this.Z = vectorPart.Z;
  48. this.W = scalarPart;
  49. }
  50. public static Quaternion Identity
  51. {
  52. get{ return identity; }
  53. }
  54. public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2)
  55. {
  56. throw new NotImplementedException();
  57. }
  58. public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
  59. {
  60. throw new NotImplementedException();
  61. }
  62. public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle)
  63. {
  64. throw new NotImplementedException();
  65. }
  66. public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Quaternion result)
  67. {
  68. throw new NotImplementedException();
  69. }
  70. public static Quaternion CreateFromRotationMatrix(Matrix matrix)
  71. {
  72. throw new NotImplementedException();
  73. }
  74. public static void CreateFromRotationMatrix(ref Matrix matrix, out Quaternion result)
  75. {
  76. throw new NotImplementedException();
  77. }
  78. public static Quaternion Divide(Quaternion quaternion1, Quaternion quaternion2)
  79. {
  80. throw new NotImplementedException();
  81. }
  82. public static void Divide(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
  83. {
  84. throw new NotImplementedException();
  85. }
  86. public static float Dot(Quaternion quaternion1, Quaternion quaternion2)
  87. {
  88. throw new NotImplementedException();
  89. }
  90. public static void Dot(ref Quaternion quaternion1, ref Quaternion quaternion2, out float result)
  91. {
  92. throw new NotImplementedException();
  93. }
  94. public override bool Equals(object obj)
  95. {
  96. throw new NotImplementedException();
  97. }
  98. public bool Equals(Quaternion other)
  99. {
  100. throw new NotImplementedException();
  101. }
  102. public override int GetHashCode()
  103. {
  104. throw new NotImplementedException();
  105. }
  106. public static Quaternion Inverse(Quaternion quaternion)
  107. {
  108. throw new NotImplementedException();
  109. }
  110. public static void Inverse(ref Quaternion quaternion, out Quaternion result)
  111. {
  112. throw new NotImplementedException();
  113. }
  114. public float Length()
  115. {
  116. //---
  117. return (float)Math.Sqrt(Math.Pow(this.W, 2.0) + Math.Pow(this.X, 2.0) + Math.Pow(this.Y, 2.0) + Math.Pow(this.Z, 2.0));
  118. //---
  119. //throw new NotImplementedException();
  120. }
  121. public float LengthSquared()
  122. {
  123. //---
  124. return (float)(Math.Pow(this.W, 2.0) + Math.Pow(this.X, 2.0) + Math.Pow(this.Y, 2.0) + Math.Pow(this.Z, 2.0));
  125. //---
  126. //throw new NotImplementedException();
  127. }
  128. public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
  129. {
  130. throw new NotImplementedException();
  131. }
  132. public static void Lerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result)
  133. {
  134. throw new NotImplementedException();
  135. }
  136. public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
  137. {
  138. throw new NotImplementedException();
  139. }
  140. public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result)
  141. {
  142. throw new NotImplementedException();
  143. }
  144. public static Quaternion Subtract(Quaternion quaternion1, Quaternion quaternion2)
  145. {
  146. throw new NotImplementedException();
  147. }
  148. public static void Subtract(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
  149. {
  150. throw new NotImplementedException();
  151. }
  152. public static Quaternion Multiply(Quaternion quaternion1, Quaternion quaternion2)
  153. {
  154. throw new NotImplementedException();
  155. }
  156. public static Quaternion Multiply(Quaternion quaternion1, float scaleFactor)
  157. {
  158. throw new NotImplementedException();
  159. }
  160. public static void Multiply(ref Quaternion quaternion1, float scaleFactor, out Quaternion result)
  161. {
  162. throw new NotImplementedException();
  163. }
  164. public static void Multiply(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
  165. {
  166. throw new NotImplementedException();
  167. }
  168. public static Quaternion Negate(Quaternion quaternion)
  169. {
  170. throw new NotImplementedException();
  171. }
  172. public static void Negate(ref Quaternion quaternion, out Quaternion result)
  173. {
  174. throw new NotImplementedException();
  175. }
  176. public void Normalize()
  177. {
  178. //---
  179. this = Normalize(this);
  180. //---
  181. //throw new NotImplementedException();
  182. }
  183. public static Quaternion Normalize(Quaternion quaternion)
  184. {
  185. //---
  186. return quaternion / quaternion.Length();
  187. //---
  188. //throw new NotImplementedException();
  189. }
  190. public static void Normalize(ref Quaternion quaternion, out Quaternion result)
  191. {
  192. throw new NotImplementedException();
  193. }
  194. public static Quaternion operator +(Quaternion quaternion1, Quaternion quaternion2)
  195. {
  196. throw new NotImplementedException();
  197. }
  198. public static Quaternion operator /(Quaternion quaternion1, Quaternion quaternion2)
  199. {
  200. throw new NotImplementedException();
  201. }
  202. public static Quaternion operator /(Quaternion quaternion, float factor)
  203. {
  204. quaternion.W /= factor;
  205. quaternion.X /= factor;
  206. quaternion.Y /= factor;
  207. quaternion.Z /= factor;
  208. return quaternion;
  209. }
  210. public static bool operator ==(Quaternion quaternion1, Quaternion quaternion2)
  211. {
  212. throw new NotImplementedException();
  213. }
  214. public static bool operator !=(Quaternion quaternion1, Quaternion quaternion2)
  215. {
  216. throw new NotImplementedException();
  217. }
  218. public static Quaternion operator *(Quaternion quaternion1, Quaternion quaternion2)
  219. {
  220. //---
  221. //Grassmann product
  222. Quaternion quaternionProduct = new Quaternion();
  223. quaternionProduct.W = quaternion1.W * quaternion2.W - quaternion1.X * quaternion2.X - quaternion1.Y * quaternion2.Y - quaternion1.Z * quaternion2.Z;
  224. quaternionProduct.X = quaternion1.W * quaternion2.X + quaternion1.X * quaternion2.W + quaternion1.Y * quaternion2.Z - quaternion1.Z * quaternion2.Y;
  225. quaternionProduct.Y = quaternion1.W * quaternion2.Y - quaternion1.X * quaternion2.Z + quaternion1.Y * quaternion2.W + quaternion1.Z * quaternion2.X;
  226. quaternionProduct.Z = quaternion1.W * quaternion2.Z + quaternion1.X * quaternion2.Y - quaternion1.Y * quaternion2.X + quaternion1.Z * quaternion2.W;
  227. return quaternionProduct;
  228. //---
  229. //throw new NotImplementedException();
  230. }
  231. public static Quaternion operator *(Quaternion quaternion1, float scaleFactor)
  232. {
  233. throw new NotImplementedException();
  234. }
  235. public static Quaternion operator -(Quaternion quaternion1, Quaternion quaternion2)
  236. {
  237. throw new NotImplementedException();
  238. }
  239. public static Quaternion operator -(Quaternion quaternion)
  240. {
  241. throw new NotImplementedException();
  242. }
  243. public override string ToString()
  244. {
  245. throw new NotImplementedException();
  246. }
  247. private static void Conjugate(ref Quaternion quaternion, out Quaternion result)
  248. {
  249. throw new NotImplementedException();
  250. }
  251. }
  252. }