raymath.d 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /**********************************************************************************************
  2. *
  3. * raymath v2.0 - Math functions to work with Vector2, Vector3, Matrix and Quaternions
  4. *
  5. * CONVENTIONS:
  6. * - Matrix structure is defined as row-major (memory layout) but parameters naming AND all
  7. * math operations performed by the library consider the structure as it was column-major
  8. * It is like transposed versions of the matrices are used for all the maths
  9. * It benefits some functions making them cache-friendly and also avoids matrix
  10. * transpositions sometimes required by OpenGL
  11. * Example: In memory order, row0 is [m0 m4 m8 m12] but in semantic math row0 is [m0 m1 m2 m3]
  12. * - Functions are always self-contained, no function use another raymath function inside,
  13. * required code is directly re-implemented inside
  14. * - Functions input parameters are always received by value (2 unavoidable exceptions)
  15. * - Functions use always a "result" variable for return (except C++ operators)
  16. * - Functions are always defined inline
  17. * - Angles are always in radians (DEG2RAD/RAD2DEG macros provided for convenience)
  18. * - No compound literals used to make sure libray is compatible with C++
  19. *
  20. * CONFIGURATION:
  21. * #define RAYMATH_IMPLEMENTATION
  22. * Generates the implementation of the library into the included file.
  23. * If not defined, the library is in header only mode and can be included in other headers
  24. * or source files without problems. But only ONE file should hold the implementation.
  25. *
  26. * #define RAYMATH_STATIC_INLINE
  27. * Define static inline functions code, so #include header suffices for use.
  28. * This may use up lots of memory.
  29. *
  30. * #define RAYMATH_DISABLE_CPP_OPERATORS
  31. * Disables C++ operator overloads for raymath types.
  32. *
  33. * LICENSE: zlib/libpng
  34. *
  35. * Copyright (c) 2015-2024 Ramon Santamaria (@raysan5)
  36. *
  37. * This software is provided "as-is", without any express or implied warranty. In no event
  38. * will the authors be held liable for any damages arising from the use of this software.
  39. *
  40. * Permission is granted to anyone to use this software for any purpose, including commercial
  41. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  42. *
  43. * 1. The origin of this software must not be misrepresented; you must not claim that you
  44. * wrote the original software. If you use this software in a product, an acknowledgment
  45. * in the product documentation would be appreciated but is not required.
  46. *
  47. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  48. * as being the original software.
  49. *
  50. * 3. This notice may not be removed or altered from any source distribution.
  51. *
  52. **********************************************************************************************/
  53. module raylib.raymath;
  54. import raylib;
  55. extern (C) @nogc nothrow:
  56. // Function specifiers definition
  57. // We are building raylib as a Win32 shared library (.dll)
  58. // We are building raylib as a Unix shared library (.so/.dylib)
  59. // We are using raylib as a Win32 shared library (.dll)
  60. // Provide external definition
  61. // Functions may be inlined, no external out-of-line definition
  62. // plain inline not supported by tinycc (See issue #435) // Functions may be inlined or external definition used
  63. //----------------------------------------------------------------------------------
  64. // Defines and Macros
  65. //----------------------------------------------------------------------------------
  66. enum PI = 3.14159265358979323846f;
  67. enum EPSILON = 0.000001f;
  68. enum DEG2RAD = PI / 180.0f;
  69. enum RAD2DEG = 180.0f / PI;
  70. // Get float vector for Matrix
  71. extern (D) auto MatrixToFloat(T)(auto ref T mat)
  72. {
  73. return MatrixToFloatV(mat).v;
  74. }
  75. // Get float vector for Vector3
  76. extern (D) auto Vector3ToFloat(T)(auto ref T vec)
  77. {
  78. return Vector3ToFloatV(vec).v;
  79. }
  80. //----------------------------------------------------------------------------------
  81. // Types and Structures Definition
  82. //----------------------------------------------------------------------------------
  83. // Vector2 type
  84. // Vector3 type
  85. // Vector4 type
  86. // Quaternion type
  87. // Matrix type (OpenGL style 4x4 - right handed, column major)
  88. // Matrix first row (4 components)
  89. // Matrix second row (4 components)
  90. // Matrix third row (4 components)
  91. // Matrix fourth row (4 components)
  92. // NOTE: Helper types to be used instead of array return types for *ToFloat functions
  93. struct float3
  94. {
  95. float[3] v;
  96. }
  97. struct float16
  98. {
  99. float[16] v;
  100. }
  101. // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabsf()
  102. //----------------------------------------------------------------------------------
  103. // Module Functions Definition - Utils math
  104. //----------------------------------------------------------------------------------
  105. // Clamp float value
  106. float Clamp(float value, float min, float max);
  107. // Calculate linear interpolation between two floats
  108. float Lerp(float start, float end, float amount);
  109. // Normalize input value within input range
  110. float Normalize(float value, float start, float end);
  111. // Remap input value within input range to output range
  112. float Remap(
  113. float value,
  114. float inputStart,
  115. float inputEnd,
  116. float outputStart,
  117. float outputEnd);
  118. // Wrap input value from min to max
  119. float Wrap(float value, float min, float max);
  120. // Check whether two given floats are almost equal
  121. int FloatEquals(float x, float y);
  122. //----------------------------------------------------------------------------------
  123. // Module Functions Definition - Vector2 math
  124. //----------------------------------------------------------------------------------
  125. // Vector with components value 0.0f
  126. Vector2 Vector2Zero();
  127. // Vector with components value 1.0f
  128. Vector2 Vector2One();
  129. // Add two vectors (v1 + v2)
  130. Vector2 Vector2Add(Vector2 v1, Vector2 v2);
  131. // Add vector and float value
  132. Vector2 Vector2AddValue(Vector2 v, float add);
  133. // Subtract two vectors (v1 - v2)
  134. Vector2 Vector2Subtract(Vector2 v1, Vector2 v2);
  135. // Subtract vector by float value
  136. Vector2 Vector2SubtractValue(Vector2 v, float sub);
  137. // Calculate vector length
  138. float Vector2Length(Vector2 v);
  139. // Calculate vector square length
  140. float Vector2LengthSqr(Vector2 v);
  141. // Calculate two vectors dot product
  142. float Vector2DotProduct(Vector2 v1, Vector2 v2);
  143. // Calculate distance between two vectors
  144. float Vector2Distance(Vector2 v1, Vector2 v2);
  145. // Calculate square distance between two vectors
  146. float Vector2DistanceSqr(Vector2 v1, Vector2 v2);
  147. // Calculate angle between two vectors
  148. // NOTE: Angle is calculated from origin point (0, 0)
  149. float Vector2Angle(Vector2 v1, Vector2 v2);
  150. // Calculate angle defined by a two vectors line
  151. // NOTE: Parameters need to be normalized
  152. // Current implementation should be aligned with glm::angle
  153. // TODO(10/9/2023): Currently angles move clockwise, determine if this is wanted behavior
  154. float Vector2LineAngle(Vector2 start, Vector2 end);
  155. // Scale vector (multiply by value)
  156. Vector2 Vector2Scale(Vector2 v, float scale);
  157. // Multiply vector by vector
  158. Vector2 Vector2Multiply(Vector2 v1, Vector2 v2);
  159. // Negate vector
  160. Vector2 Vector2Negate(Vector2 v);
  161. // Divide vector by vector
  162. Vector2 Vector2Divide(Vector2 v1, Vector2 v2);
  163. // Normalize provided vector
  164. Vector2 Vector2Normalize(Vector2 v);
  165. // Transforms a Vector2 by a given Matrix
  166. Vector2 Vector2Transform(Vector2 v, Matrix mat);
  167. // Calculate linear interpolation between two vectors
  168. Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount);
  169. // Calculate reflected vector to normal
  170. // Dot product
  171. Vector2 Vector2Reflect(Vector2 v, Vector2 normal);
  172. // Get min value for each pair of components
  173. Vector2 Vector2Min(Vector2 v1, Vector2 v2);
  174. // Get max value for each pair of components
  175. Vector2 Vector2Max(Vector2 v1, Vector2 v2);
  176. // Rotate vector by angle
  177. Vector2 Vector2Rotate(Vector2 v, float angle);
  178. // Move Vector towards target
  179. Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance);
  180. // Invert the given vector
  181. Vector2 Vector2Invert(Vector2 v);
  182. // Clamp the components of the vector between
  183. // min and max values specified by the given vectors
  184. Vector2 Vector2Clamp(Vector2 v, Vector2 min, Vector2 max);
  185. // Clamp the magnitude of the vector between two min and max values
  186. // By default, 1 as the neutral element.
  187. Vector2 Vector2ClampValue(Vector2 v, float min, float max);
  188. // Check whether two given vectors are almost equal
  189. int Vector2Equals(Vector2 p, Vector2 q);
  190. // Compute the direction of a refracted ray
  191. // v: normalized direction of the incoming ray
  192. // n: normalized normal vector of the interface of two optical media
  193. // r: ratio of the refractive index of the medium from where the ray comes
  194. // to the refractive index of the medium on the other side of the surface
  195. Vector2 Vector2Refract(Vector2 v, Vector2 n, float r);
  196. //----------------------------------------------------------------------------------
  197. // Module Functions Definition - Vector3 math
  198. //----------------------------------------------------------------------------------
  199. // Vector with components value 0.0f
  200. Vector3 Vector3Zero();
  201. // Vector with components value 1.0f
  202. Vector3 Vector3One();
  203. // Add two vectors
  204. Vector3 Vector3Add(Vector3 v1, Vector3 v2);
  205. // Add vector and float value
  206. Vector3 Vector3AddValue(Vector3 v, float add);
  207. // Subtract two vectors
  208. Vector3 Vector3Subtract(Vector3 v1, Vector3 v2);
  209. // Subtract vector by float value
  210. Vector3 Vector3SubtractValue(Vector3 v, float sub);
  211. // Multiply vector by scalar
  212. Vector3 Vector3Scale(Vector3 v, float scalar);
  213. // Multiply vector by vector
  214. Vector3 Vector3Multiply(Vector3 v1, Vector3 v2);
  215. // Calculate two vectors cross product
  216. Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2);
  217. // Calculate one vector perpendicular vector
  218. // Cross product between vectors
  219. Vector3 Vector3Perpendicular(Vector3 v);
  220. // Calculate vector length
  221. float Vector3Length(const Vector3 v);
  222. // Calculate vector square length
  223. float Vector3LengthSqr(const Vector3 v);
  224. // Calculate two vectors dot product
  225. float Vector3DotProduct(Vector3 v1, Vector3 v2);
  226. // Calculate distance between two vectors
  227. float Vector3Distance(Vector3 v1, Vector3 v2);
  228. // Calculate square distance between two vectors
  229. float Vector3DistanceSqr(Vector3 v1, Vector3 v2);
  230. // Calculate angle between two vectors
  231. float Vector3Angle(Vector3 v1, Vector3 v2);
  232. // Negate provided vector (invert direction)
  233. Vector3 Vector3Negate(Vector3 v);
  234. // Divide vector by vector
  235. Vector3 Vector3Divide(Vector3 v1, Vector3 v2);
  236. // Normalize provided vector
  237. Vector3 Vector3Normalize(Vector3 v);
  238. //Calculate the projection of the vector v1 on to v2
  239. Vector3 Vector3Project(Vector3 v1, Vector3 v2);
  240. //Calculate the rejection of the vector v1 on to v2
  241. Vector3 Vector3Reject(Vector3 v1, Vector3 v2);
  242. // Orthonormalize provided vectors
  243. // Makes vectors normalized and orthogonal to each other
  244. // Gram-Schmidt function implementation
  245. // Vector3Normalize(*v1);
  246. // Vector3CrossProduct(*v1, *v2)
  247. // Vector3Normalize(vn1);
  248. // Vector3CrossProduct(vn1, *v1)
  249. void Vector3OrthoNormalize(Vector3* v1, Vector3* v2);
  250. // Transforms a Vector3 by a given Matrix
  251. Vector3 Vector3Transform(Vector3 v, Matrix mat);
  252. // Transform a vector by quaternion rotation
  253. Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q);
  254. // Rotates a vector around an axis
  255. // Using Euler-Rodrigues Formula
  256. // Ref.: https://en.wikipedia.org/w/index.php?title=Euler%E2%80%93Rodrigues_formula
  257. // Vector3Normalize(axis);
  258. // Vector3CrossProduct(w, v)
  259. // Vector3CrossProduct(w, wv)
  260. // Vector3Scale(wv, 2*a)
  261. // Vector3Scale(wwv, 2)
  262. Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle);
  263. // Move Vector towards target
  264. Vector3 Vector3MoveTowards(Vector3 v, Vector3 target, float maxDistance);
  265. // Calculate linear interpolation between two vectors
  266. Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount);
  267. // Calculate cubic hermite interpolation between two vectors and their tangents
  268. // as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
  269. Vector3 Vector3CubicHermite(
  270. Vector3 v1,
  271. Vector3 tangent1,
  272. Vector3 v2,
  273. Vector3 tangent2,
  274. float amount);
  275. // Calculate reflected vector to normal
  276. // I is the original vector
  277. // N is the normal of the incident plane
  278. // R = I - (2*N*(DotProduct[I, N]))
  279. Vector3 Vector3Reflect(Vector3 v, Vector3 normal);
  280. // Get min value for each pair of components
  281. Vector3 Vector3Min(Vector3 v1, Vector3 v2);
  282. // Get max value for each pair of components
  283. Vector3 Vector3Max(Vector3 v1, Vector3 v2);
  284. // Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
  285. // NOTE: Assumes P is on the plane of the triangle
  286. // Vector3Subtract(b, a)
  287. // Vector3Subtract(c, a)
  288. // Vector3Subtract(p, a)
  289. // Vector3DotProduct(v0, v0)
  290. // Vector3DotProduct(v0, v1)
  291. // Vector3DotProduct(v1, v1)
  292. // Vector3DotProduct(v2, v0)
  293. // Vector3DotProduct(v2, v1)
  294. Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c);
  295. // Projects a Vector3 from screen space into object space
  296. // NOTE: We are avoiding calling other raymath functions despite available
  297. // Calculate unprojected matrix (multiply view matrix by projection matrix) and invert it
  298. // MatrixMultiply(view, projection);
  299. // Calculate inverted matrix -> MatrixInvert(matViewProj);
  300. // Cache the matrix values (speed optimization)
  301. // Calculate the invert determinant (inlined to avoid double-caching)
  302. // Create quaternion from source point
  303. // Multiply quat point by unprojecte matrix
  304. // QuaternionTransform(quat, matViewProjInv)
  305. // Normalized world points in vectors
  306. Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view);
  307. // Get Vector3 as float array
  308. float3 Vector3ToFloatV(Vector3 v);
  309. // Invert the given vector
  310. Vector3 Vector3Invert(Vector3 v);
  311. // Clamp the components of the vector between
  312. // min and max values specified by the given vectors
  313. Vector3 Vector3Clamp(Vector3 v, Vector3 min, Vector3 max);
  314. // Clamp the magnitude of the vector between two values
  315. // By default, 1 as the neutral element.
  316. Vector3 Vector3ClampValue(Vector3 v, float min, float max);
  317. // Check whether two given vectors are almost equal
  318. int Vector3Equals(Vector3 p, Vector3 q);
  319. // Compute the direction of a refracted ray
  320. // v: normalized direction of the incoming ray
  321. // n: normalized normal vector of the interface of two optical media
  322. // r: ratio of the refractive index of the medium from where the ray comes
  323. // to the refractive index of the medium on the other side of the surface
  324. Vector3 Vector3Refract(Vector3 v, Vector3 n, float r);
  325. //----------------------------------------------------------------------------------
  326. // Module Functions Definition - Vector4 math
  327. //----------------------------------------------------------------------------------
  328. Vector4 Vector4Zero();
  329. Vector4 Vector4One();
  330. Vector4 Vector4Add(Vector4 v1, Vector4 v2);
  331. Vector4 Vector4AddValue(Vector4 v, float add);
  332. Vector4 Vector4Subtract(Vector4 v1, Vector4 v2);
  333. Vector4 Vector4SubtractValue(Vector4 v, float add);
  334. float Vector4Length(Vector4 v);
  335. float Vector4LengthSqr(Vector4 v);
  336. float Vector4DotProduct(Vector4 v1, Vector4 v2);
  337. // Calculate distance between two vectors
  338. float Vector4Distance(Vector4 v1, Vector4 v2);
  339. // Calculate square distance between two vectors
  340. float Vector4DistanceSqr(Vector4 v1, Vector4 v2);
  341. Vector4 Vector4Scale(Vector4 v, float scale);
  342. // Multiply vector by vector
  343. Vector4 Vector4Multiply(Vector4 v1, Vector4 v2);
  344. // Negate vector
  345. Vector4 Vector4Negate(Vector4 v);
  346. // Divide vector by vector
  347. Vector4 Vector4Divide(Vector4 v1, Vector4 v2);
  348. // Normalize provided vector
  349. Vector4 Vector4Normalize(Vector4 v);
  350. // Get min value for each pair of components
  351. Vector4 Vector4Min(Vector4 v1, Vector4 v2);
  352. // Get max value for each pair of components
  353. Vector4 Vector4Max(Vector4 v1, Vector4 v2);
  354. // Calculate linear interpolation between two vectors
  355. Vector4 Vector4Lerp(Vector4 v1, Vector4 v2, float amount);
  356. // Move Vector towards target
  357. Vector4 Vector4MoveTowards(Vector4 v, Vector4 target, float maxDistance);
  358. // Invert the given vector
  359. Vector4 Vector4Invert(Vector4 v);
  360. // Check whether two given vectors are almost equal
  361. int Vector4Equals(Vector4 p, Vector4 q);
  362. //----------------------------------------------------------------------------------
  363. // Module Functions Definition - Matrix math
  364. //----------------------------------------------------------------------------------
  365. // Compute matrix determinant
  366. // Cache the matrix values (speed optimization)
  367. float MatrixDeterminant(Matrix mat);
  368. // Get the trace of the matrix (sum of the values along the diagonal)
  369. float MatrixTrace(Matrix mat);
  370. // Transposes provided matrix
  371. Matrix MatrixTranspose(Matrix mat);
  372. // Invert provided matrix
  373. // Cache the matrix values (speed optimization)
  374. // Calculate the invert determinant (inlined to avoid double-caching)
  375. Matrix MatrixInvert(Matrix mat);
  376. // Get identity matrix
  377. Matrix MatrixIdentity();
  378. // Add two matrices
  379. Matrix MatrixAdd(Matrix left, Matrix right);
  380. // Subtract two matrices (left - right)
  381. Matrix MatrixSubtract(Matrix left, Matrix right);
  382. // Get two matrix multiplication
  383. // NOTE: When multiplying matrices... the order matters!
  384. Matrix MatrixMultiply(Matrix left, Matrix right);
  385. // Get translation matrix
  386. Matrix MatrixTranslate(float x, float y, float z);
  387. // Create rotation matrix from axis and angle
  388. // NOTE: Angle should be provided in radians
  389. Matrix MatrixRotate(Vector3 axis, float angle);
  390. // Get x-rotation matrix
  391. // NOTE: Angle must be provided in radians
  392. // MatrixIdentity()
  393. Matrix MatrixRotateX(float angle);
  394. // Get y-rotation matrix
  395. // NOTE: Angle must be provided in radians
  396. // MatrixIdentity()
  397. Matrix MatrixRotateY(float angle);
  398. // Get z-rotation matrix
  399. // NOTE: Angle must be provided in radians
  400. // MatrixIdentity()
  401. Matrix MatrixRotateZ(float angle);
  402. // Get xyz-rotation matrix
  403. // NOTE: Angle must be provided in radians
  404. // MatrixIdentity()
  405. Matrix MatrixRotateXYZ(Vector3 angle);
  406. // Get zyx-rotation matrix
  407. // NOTE: Angle must be provided in radians
  408. Matrix MatrixRotateZYX(Vector3 angle);
  409. // Get scaling matrix
  410. Matrix MatrixScale(float x, float y, float z);
  411. // Get perspective projection matrix
  412. Matrix MatrixFrustum(
  413. double left,
  414. double right,
  415. double bottom,
  416. double top,
  417. double nearPlane,
  418. double farPlane);
  419. // Get perspective projection matrix
  420. // NOTE: Fovy angle must be provided in radians
  421. // MatrixFrustum(-right, right, -top, top, near, far);
  422. Matrix MatrixPerspective(
  423. double fovY,
  424. double aspect,
  425. double nearPlane,
  426. double farPlane);
  427. // Get orthographic projection matrix
  428. Matrix MatrixOrtho(
  429. double left,
  430. double right,
  431. double bottom,
  432. double top,
  433. double nearPlane,
  434. double farPlane);
  435. // Get camera look-at matrix (view matrix)
  436. // Vector3Subtract(eye, target)
  437. // Vector3Normalize(vz)
  438. // Vector3CrossProduct(up, vz)
  439. // Vector3Normalize(x)
  440. // Vector3CrossProduct(vz, vx)
  441. // Vector3DotProduct(vx, eye)
  442. // Vector3DotProduct(vy, eye)
  443. // Vector3DotProduct(vz, eye)
  444. Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up);
  445. // Get float array of matrix data
  446. float16 MatrixToFloatV(Matrix mat);
  447. //----------------------------------------------------------------------------------
  448. // Module Functions Definition - Quaternion math
  449. //----------------------------------------------------------------------------------
  450. // Add two quaternions
  451. Quaternion QuaternionAdd(Quaternion q1, Quaternion q2);
  452. // Add quaternion and float value
  453. Quaternion QuaternionAddValue(Quaternion q, float add);
  454. // Subtract two quaternions
  455. Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2);
  456. // Subtract quaternion and float value
  457. Quaternion QuaternionSubtractValue(Quaternion q, float sub);
  458. // Get identity quaternion
  459. Quaternion QuaternionIdentity();
  460. // Computes the length of a quaternion
  461. float QuaternionLength(Quaternion q);
  462. // Normalize provided quaternion
  463. Quaternion QuaternionNormalize(Quaternion q);
  464. // Invert provided quaternion
  465. Quaternion QuaternionInvert(Quaternion q);
  466. // Calculate two quaternion multiplication
  467. Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2);
  468. // Scale quaternion by float value
  469. Quaternion QuaternionScale(Quaternion q, float mul);
  470. // Divide two quaternions
  471. Quaternion QuaternionDivide(Quaternion q1, Quaternion q2);
  472. // Calculate linear interpolation between two quaternions
  473. Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount);
  474. // Calculate slerp-optimized interpolation between two quaternions
  475. // QuaternionLerp(q1, q2, amount)
  476. // QuaternionNormalize(q);
  477. Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount);
  478. // Calculates spherical linear interpolation between two quaternions
  479. Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount);
  480. // Calculate quaternion cubic spline interpolation using Cubic Hermite Spline algorithm
  481. // as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
  482. Quaternion QuaternionCubicHermiteSpline(
  483. Quaternion q1,
  484. Quaternion outTangent1,
  485. Quaternion q2,
  486. Quaternion inTangent2,
  487. float t);
  488. // Calculate quaternion based on the rotation from one vector to another
  489. // Vector3DotProduct(from, to)
  490. // Vector3CrossProduct(from, to)
  491. // QuaternionNormalize(q);
  492. // NOTE: Normalize to essentially nlerp the original and identity to 0.5
  493. Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to);
  494. // Get a quaternion for a given rotation matrix
  495. Quaternion QuaternionFromMatrix(Matrix mat);
  496. // Get a matrix for a given quaternion
  497. // MatrixIdentity()
  498. Matrix QuaternionToMatrix(Quaternion q);
  499. // Get rotation quaternion for an angle and axis
  500. // NOTE: Angle must be provided in radians
  501. // Vector3Normalize(axis)
  502. // QuaternionNormalize(q);
  503. Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle);
  504. // Get the rotation angle and axis for a given quaternion
  505. // QuaternionNormalize(q);
  506. // This occurs when the angle is zero.
  507. // Not a problem: just set an arbitrary normalized axis.
  508. void QuaternionToAxisAngle(Quaternion q, Vector3* outAxis, float* outAngle);
  509. // Get the quaternion equivalent to Euler angles
  510. // NOTE: Rotation order is ZYX
  511. Quaternion QuaternionFromEuler(float pitch, float yaw, float roll);
  512. // Get the Euler angles equivalent to quaternion (roll, pitch, yaw)
  513. // NOTE: Angles are returned in a Vector3 struct in radians
  514. // Roll (x-axis rotation)
  515. // Pitch (y-axis rotation)
  516. // Yaw (z-axis rotation)
  517. Vector3 QuaternionToEuler(Quaternion q);
  518. // Transform a quaternion given a transformation matrix
  519. Quaternion QuaternionTransform(Quaternion q, Matrix mat);
  520. // Check whether two given quaternions are almost equal
  521. int QuaternionEquals(Quaternion p, Quaternion q);
  522. // Decompose a transformation matrix into its rotational, translational and scaling components
  523. // Extract translation.
  524. // Extract upper-left for determinant computation
  525. // Extract scale
  526. // Remove scale from the matrix if it is not close to zero
  527. // Extract rotation
  528. // Set to identity if close to zero
  529. void MatrixDecompose(
  530. Matrix mat,
  531. Vector3* translation,
  532. Quaternion* rotation,
  533. Vector3* scale);
  534. // Optional C++ math operators
  535. //-------------------------------------------------------------------------------
  536. // Vector2 operators
  537. // Vector3 operators
  538. // Vector4 operators
  539. // Quaternion operators
  540. // Matrix operators
  541. //-------------------------------------------------------------------------------
  542. // C++ operators
  543. // RAYMATH_H