math.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * Copyright 2011-2024 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
  4. */
  5. #ifndef BX_MATH_H_HEADER_GUARD
  6. #define BX_MATH_H_HEADER_GUARD
  7. #include "bx.h"
  8. #include "uint32_t.h"
  9. namespace bx
  10. {
  11. ///
  12. typedef float (*LerpFn)(float _a, float _b, float _t);
  13. ///
  14. struct Handedness
  15. {
  16. enum Enum
  17. {
  18. Left,
  19. Right,
  20. };
  21. };
  22. ///
  23. struct NearFar
  24. {
  25. enum Enum
  26. {
  27. Default,
  28. Reverse,
  29. };
  30. };
  31. ///
  32. struct Vec3
  33. {
  34. Vec3() = delete;
  35. ///
  36. Vec3(InitNoneTag);
  37. ///
  38. constexpr Vec3(InitZeroTag);
  39. ///
  40. constexpr Vec3(InitIdentityTag);
  41. ///
  42. explicit constexpr Vec3(float _v);
  43. ///
  44. constexpr Vec3(float _x, float _y, float _z);
  45. float x, y, z;
  46. };
  47. ///
  48. struct Plane
  49. {
  50. Plane() = delete;
  51. ///
  52. Plane(InitNoneTag);
  53. ///
  54. constexpr Plane(InitZeroTag);
  55. ///
  56. constexpr Plane(InitIdentityTag);
  57. ///
  58. constexpr Plane(Vec3 _normal, float _dist);
  59. Vec3 normal;
  60. float dist;
  61. };
  62. ///
  63. struct Quaternion
  64. {
  65. Quaternion() = delete;
  66. ///
  67. Quaternion(InitNoneTag);
  68. ///
  69. constexpr Quaternion(InitZeroTag);
  70. ///
  71. constexpr Quaternion(InitIdentityTag);
  72. ///
  73. constexpr Quaternion(float _x, float _y, float _z, float _w);
  74. float x, y, z, w;
  75. };
  76. /// Returns converted the argument _deg to radians.
  77. ///
  78. BX_CONSTEXPR_FUNC float toRad(float _deg);
  79. /// Returns converted the argument _rad to degrees.
  80. ///
  81. BX_CONSTEXPR_FUNC float toDeg(float _rad);
  82. /// Reinterprets the bit pattern of _a as uint32_t.
  83. ///
  84. BX_CONSTEXPR_FUNC uint32_t floatToBits(float _a);
  85. /// Reinterprets the bit pattern of _a as float.
  86. ///
  87. BX_CONSTEXPR_FUNC float bitsToFloat(uint32_t _a);
  88. /// Reinterprets the bit pattern of _a as uint64_t.
  89. ///
  90. BX_CONSTEXPR_FUNC uint64_t doubleToBits(double _a);
  91. /// Reinterprets the bit pattern of _a as double.
  92. ///
  93. BX_CONSTEXPR_FUNC double bitsToDouble(uint64_t _a);
  94. /// Returns sortable floating point value.
  95. ///
  96. BX_CONST_FUNC uint32_t floatFlip(uint32_t _value);
  97. /// Returns true if _f is a number that is NaN.
  98. ///
  99. BX_CONST_FUNC bool isNan(float _f);
  100. /// Returns true if _f is a number that is NaN.
  101. ///
  102. BX_CONST_FUNC bool isNan(double _f);
  103. /// Returns true if _f is not infinite and is not a NaN.
  104. ///
  105. BX_CONST_FUNC bool isFinite(float _f);
  106. /// Returns true if _f is not infinite and is not a NaN.
  107. ///
  108. BX_CONST_FUNC bool isFinite(double _f);
  109. /// Returns true if _f is infinite and is not a NaN.
  110. ///
  111. BX_CONST_FUNC bool isInfinite(float _f);
  112. /// Returns true if _f is infinite and is not a NaN.
  113. ///
  114. BX_CONST_FUNC bool isInfinite(double _f);
  115. /// Returns the largest integer value not greater than _f.
  116. ///
  117. BX_CONSTEXPR_FUNC float floor(float _f);
  118. /// Returns the smallest integer value not less than _f.
  119. ///
  120. BX_CONSTEXPR_FUNC float ceil(float _f);
  121. /// Returns the nearest integer value to _f, rounding halfway cases away from zero,
  122. ///
  123. BX_CONSTEXPR_FUNC float round(float _f);
  124. /// Returns linear interpolation between two values _a and _b.
  125. ///
  126. BX_CONSTEXPR_FUNC float lerp(float _a, float _b, float _t);
  127. /// Returns inverse linear interpolation of _value between two values _a and _b.
  128. ///
  129. BX_CONSTEXPR_FUNC float invLerp(float _a, float _b, float _value);
  130. /// Extracts the sign of value `_a`.
  131. ///
  132. /// @param[in] _a Value.
  133. ///
  134. /// @returns -1 if `_a` is less than zero, 0 if `_a` is equal to 0, or +1 if `_a` is greater than zero.
  135. ///
  136. BX_CONSTEXPR_FUNC float sign(float _a);
  137. /// Returns `true` if the velue `_a` is negative.
  138. ///
  139. /// @param[in] _a Value.
  140. ///
  141. /// @returns `true` if `_a` is less than zero, otherwise returns `false`.
  142. ///
  143. BX_CONSTEXPR_FUNC bool signBit(float _a);
  144. /// Returns value with the magnitude `_value`, and the sign of `_sign`.
  145. ///
  146. /// @param[in] _value Value.
  147. /// @param[in] _sign Sign.
  148. ///
  149. /// @returns Value with the magnitude `_value`, and the sign of `_sign`.
  150. ///
  151. BX_CONSTEXPR_FUNC float copySign(float _value, float _sign);
  152. /// Returns the absolute of _a.
  153. ///
  154. BX_CONSTEXPR_FUNC float abs(float _a);
  155. /// Returns the square of _a.
  156. ///
  157. BX_CONSTEXPR_FUNC float square(float _a);
  158. /// Returns the both sine and cosine of the argument _a.
  159. ///
  160. /// @remarks The function calculates cosine, and then approximates sine based on the cosine
  161. /// result. Therefore calculation of sine is less accurate than calling `bx::sin` function.
  162. ///
  163. void sinCosApprox(float& _outSinApprox, float& _outCos, float _a);
  164. /// Returns the sine of the argument _a.
  165. ///
  166. BX_CONST_FUNC float sin(float _a);
  167. /// Returns hyperbolic sine of the argument _a.
  168. ///
  169. BX_CONST_FUNC float sinh(float _a);
  170. /// Returns radian angle between -pi/2 and +pi/2 whose sine is _a.
  171. ///
  172. BX_CONST_FUNC float asin(float _a);
  173. /// Returns the cosine of the argument _a.
  174. ///
  175. BX_CONST_FUNC float cos(float _a);
  176. /// Returns hyperbolic cosine of the argument _a.
  177. ///
  178. BX_CONST_FUNC float cosh(float _a);
  179. /// Returns radian angle between 0 and pi whose cosine is _a.
  180. ///
  181. BX_CONST_FUNC float acos(float _a);
  182. /// Returns the circular tangent of the radian argument _a.
  183. ///
  184. BX_CONST_FUNC float tan(float _a);
  185. /// Returns hyperbolic tangent of the argument _a.
  186. ///
  187. BX_CONST_FUNC float tanh(float _a);
  188. /// Returns radian angle between -pi/2 and +pi/2 whose tangent is _a.
  189. ///
  190. BX_CONST_FUNC float atan(float _a);
  191. /// Returns the inverse tangent of _y/_x.
  192. ///
  193. BX_CONST_FUNC float atan2(float _y, float _x);
  194. /// Computes _a raised to the _b power.
  195. ///
  196. BX_CONST_FUNC float pow(float _a, float _b);
  197. /// Returns the result of multiplying _a by 2 raised to the power of the exponent.
  198. ///
  199. BX_CONST_FUNC float ldexp(float _a, int32_t _b);
  200. /// Returns decomposed given floating point value _a into a normalized fraction and
  201. /// an integral power of two.
  202. ///
  203. float frexp(float _a, int32_t* _outExp);
  204. /// Returns e (2.71828...) raised to the _a power.
  205. ///
  206. BX_CONST_FUNC float exp(float _a);
  207. /// Returns 2 raised to the _a power.
  208. ///
  209. BX_CONST_FUNC float exp2(float _a);
  210. /// Returns the base e (2.71828...) logarithm of _a.
  211. ///
  212. BX_CONST_FUNC float log(float _a);
  213. /// Returns the base 2 logarithm of _a.
  214. ///
  215. BX_CONST_FUNC float log2(float _a);
  216. /// Count number of bits set.
  217. ///
  218. template<typename Ty>
  219. BX_CONSTEXPR_FUNC uint8_t countBits(Ty _val);
  220. /// Count number of leading zeros.
  221. ///
  222. template<typename Ty>
  223. BX_CONSTEXPR_FUNC uint8_t countLeadingZeros(Ty _val);
  224. /// Count number of trailing zeros.
  225. ///
  226. template<typename Ty>
  227. BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(Ty _val);
  228. /// Find first set.
  229. ///
  230. template<typename Ty>
  231. BX_CONSTEXPR_FUNC uint8_t findFirstSet(Ty _val);
  232. /// Find last set.
  233. ///
  234. template<typename Ty>
  235. BX_CONSTEXPR_FUNC uint8_t findLastSet(Ty _val);
  236. /// Returns the next smallest integer base 2 logarithm of _a.
  237. ///
  238. template<typename Ty>
  239. BX_CONSTEXPR_FUNC uint8_t ceilLog2(Ty _a);
  240. /// Returns the next biggest integer base 2 logarithm of _a.
  241. ///
  242. template<typename Ty>
  243. BX_CONSTEXPR_FUNC uint8_t floorLog2(Ty _a);
  244. /// Returns the next smallest power of two value.
  245. ///
  246. template<typename Ty>
  247. BX_CONSTEXPR_FUNC Ty nextPow2(Ty _a);
  248. /// Returns the square root of _a.
  249. ///
  250. BX_CONST_FUNC float sqrt(float _a);
  251. /// Returns reciprocal square root of _a.
  252. ///
  253. BX_CONST_FUNC float rsqrt(float _a);
  254. /// Returns the nearest integer not greater in magnitude than _a.
  255. ///
  256. BX_CONSTEXPR_FUNC float trunc(float _a);
  257. /// Returns the fractional (or decimal) part of _a, which is greater than or equal to 0
  258. /// and less than 1.
  259. ///
  260. BX_CONSTEXPR_FUNC float fract(float _a);
  261. /// Returns result of negated multiply-sub operation -(_a * _b - _c) -> _c - _a * _b.
  262. ///
  263. BX_CONSTEXPR_FUNC float nms(float _a, float _b, float _c);
  264. /// Returns result of addition (_a + _b).
  265. ///
  266. BX_CONSTEXPR_FUNC float add(float _a, float _b);
  267. /// Returns result of subtracion (_a - _b).
  268. ///
  269. BX_CONSTEXPR_FUNC float sub(float _a, float _b);
  270. /// Returns result of multiply (_a * _b).
  271. ///
  272. BX_CONSTEXPR_FUNC float mul(float _a, float _b);
  273. /// Returns result of multiply and add (_a * _b + _c).
  274. ///
  275. BX_CONSTEXPR_FUNC float mad(float _a, float _b, float _c);
  276. /// Returns reciprocal of _a.
  277. ///
  278. BX_CONSTEXPR_FUNC float rcp(float _a);
  279. /// Returns reciprocal of _a. Avoids divide by zero.
  280. ///
  281. BX_CONSTEXPR_FUNC float rcpSafe(float _a);
  282. /// Returns the floating-point remainder of the division operation _a/_b.
  283. ///
  284. BX_CONSTEXPR_FUNC float mod(float _a, float _b);
  285. ///
  286. BX_CONSTEXPR_FUNC bool isEqual(float _a, float _b, float _epsilon);
  287. ///
  288. BX_CONST_FUNC bool isEqual(const float* _a, const float* _b, uint32_t _num, float _epsilon);
  289. ///
  290. BX_CONSTEXPR_FUNC float wrap(float _a, float _wrap);
  291. ///
  292. BX_CONSTEXPR_FUNC float step(float _edge, float _a);
  293. ///
  294. BX_CONSTEXPR_FUNC float pulse(float _a, float _start, float _end);
  295. ///
  296. BX_CONSTEXPR_FUNC float smoothStep(float _a);
  297. ///
  298. BX_CONST_FUNC float invSmoothStep(float _a);
  299. ///
  300. BX_CONSTEXPR_FUNC float bias(float _time, float _bias);
  301. ///
  302. BX_CONSTEXPR_FUNC float gain(float _time, float _gain);
  303. ///
  304. BX_CONSTEXPR_FUNC float angleDiff(float _a, float _b);
  305. /// Returns shortest distance linear interpolation between two angles.
  306. ///
  307. BX_CONSTEXPR_FUNC float angleLerp(float _a, float _b, float _t);
  308. ///
  309. template<typename Ty>
  310. Ty load(const void* _ptr);
  311. ///
  312. template<typename Ty>
  313. void store(void* _ptr, const Ty& _a);
  314. ///
  315. BX_CONSTEXPR_FUNC Vec3 round(const Vec3 _a);
  316. ///
  317. BX_CONSTEXPR_FUNC Vec3 abs(const Vec3 _a);
  318. ///
  319. BX_CONSTEXPR_FUNC Vec3 neg(const Vec3 _a);
  320. ///
  321. BX_CONSTEXPR_FUNC Vec3 add(const Vec3 _a, const Vec3 _b);
  322. ///
  323. BX_CONSTEXPR_FUNC Vec3 add(const Vec3 _a, float _b);
  324. ///
  325. BX_CONSTEXPR_FUNC Vec3 sub(const Vec3 _a, const Vec3 _b);
  326. ///
  327. BX_CONSTEXPR_FUNC Vec3 sub(const Vec3 _a, float _b);
  328. ///
  329. BX_CONSTEXPR_FUNC Vec3 mul(const Vec3 _a, const Vec3 _b);
  330. ///
  331. BX_CONSTEXPR_FUNC Vec3 mul(const Vec3 _a, float _b);
  332. ///
  333. BX_CONSTEXPR_FUNC Vec3 div(const Vec3 _a, const Vec3 _b);
  334. ///
  335. BX_CONSTEXPR_FUNC Vec3 divSafe(const Vec3 _a, const Vec3 _b);
  336. ///
  337. BX_CONSTEXPR_FUNC Vec3 div(const Vec3 _a, float _b);
  338. ///
  339. BX_CONSTEXPR_FUNC Vec3 divSafe(const Vec3 _a, float _b);
  340. /// Returns result of negated multiply-sub operation -(_a * _b - _c) -> _c - _a * _b.
  341. ///
  342. BX_CONSTEXPR_FUNC Vec3 nms(const Vec3 _a, const float _b, const Vec3 _c);
  343. /// Returns result of negated multiply-sub operation -(_a * _b - _c) -> _c - _a * _b.
  344. ///
  345. BX_CONSTEXPR_FUNC Vec3 nms(const Vec3 _a, const Vec3 _b, const Vec3 _c);
  346. ///
  347. BX_CONSTEXPR_FUNC Vec3 mad(const Vec3 _a, const float _b, const Vec3 _c);
  348. ///
  349. BX_CONSTEXPR_FUNC Vec3 mad(const Vec3 _a, const Vec3 _b, const Vec3 _c);
  350. ///
  351. BX_CONSTEXPR_FUNC float dot(const Vec3 _a, const Vec3 _b);
  352. ///
  353. BX_CONSTEXPR_FUNC Vec3 cross(const Vec3 _a, const Vec3 _b);
  354. ///
  355. BX_CONST_FUNC float length(const Vec3 _a);
  356. ///
  357. BX_CONST_FUNC float distanceSq(const Vec3 _a, const Vec3 _b);
  358. ///
  359. BX_CONST_FUNC float distance(const Vec3 _a, const Vec3 _b);
  360. ///
  361. BX_CONSTEXPR_FUNC Vec3 lerp(const Vec3 _a, const Vec3 _b, float _t);
  362. ///
  363. BX_CONSTEXPR_FUNC Vec3 lerp(const Vec3 _a, const Vec3 _b, const Vec3 _t);
  364. ///
  365. BX_CONST_FUNC Vec3 normalize(const Vec3 _a);
  366. ///
  367. BX_CONSTEXPR_FUNC Vec3 min(const Vec3 _a, const Vec3 _b);
  368. ///
  369. BX_CONSTEXPR_FUNC Vec3 max(const Vec3 _a, const Vec3 _b);
  370. /// Returns component wise reciprocal of _a.
  371. ///
  372. BX_CONSTEXPR_FUNC Vec3 rcp(const Vec3 _a);
  373. /// Returns component wise reciprocal of _a.
  374. ///
  375. BX_CONSTEXPR_FUNC Vec3 rcpSafe(const Vec3 _a);
  376. ///
  377. BX_CONSTEXPR_FUNC bool isEqual(const Vec3 _a, const Vec3 _b, float _epsilon);
  378. ///
  379. void calcTangentFrame(Vec3& _outT, Vec3& _outB, const Vec3 _n);
  380. ///
  381. void calcTangentFrame(Vec3& _outT, Vec3& _outB, const Vec3 _n, float _angle);
  382. ///
  383. BX_CONST_FUNC Vec3 fromLatLong(float _u, float _v);
  384. ///
  385. void toLatLong(float* _outU, float* _outV, const Vec3 _dir);
  386. ///
  387. BX_CONSTEXPR_FUNC Quaternion invert(const Quaternion _a);
  388. ///
  389. BX_CONSTEXPR_FUNC Vec3 mulXyz(const Quaternion _a, const Quaternion _b);
  390. ///
  391. BX_CONSTEXPR_FUNC Quaternion add(const Quaternion _a, const Quaternion _b);
  392. ///
  393. BX_CONSTEXPR_FUNC Quaternion sub(const Quaternion _a, const Quaternion _b);
  394. ///
  395. BX_CONSTEXPR_FUNC Quaternion mul(const Quaternion _a, float _b);
  396. ///
  397. BX_CONSTEXPR_FUNC Quaternion mul(const Quaternion _a, const Quaternion _b);
  398. ///
  399. BX_CONSTEXPR_FUNC Vec3 mul(const Vec3 _v, const Quaternion _q);
  400. ///
  401. BX_CONSTEXPR_FUNC float dot(const Quaternion _a, const Quaternion _b);
  402. ///
  403. BX_CONSTEXPR_FUNC Quaternion normalize(const Quaternion _a);
  404. ///
  405. BX_CONSTEXPR_FUNC Quaternion lerp(const Quaternion _a, const Quaternion _b, float _t);
  406. ///
  407. BX_CONST_FUNC Quaternion fromEuler(const Vec3 _euler);
  408. ///
  409. BX_CONST_FUNC Vec3 toEuler(const Quaternion _a);
  410. ///
  411. BX_CONST_FUNC Vec3 toXAxis(const Quaternion _a);
  412. ///
  413. BX_CONST_FUNC Vec3 toYAxis(const Quaternion _a);
  414. ///
  415. BX_CONST_FUNC Vec3 toZAxis(const Quaternion _a);
  416. ///
  417. BX_CONST_FUNC Quaternion fromAxisAngle(const Vec3 _axis, float _angle);
  418. ///
  419. void toAxisAngle(Vec3& _outAxis, float& _outAngle, const Quaternion _a);
  420. ///
  421. BX_CONST_FUNC Quaternion rotateX(float _ax);
  422. ///
  423. BX_CONST_FUNC Quaternion rotateY(float _ay);
  424. ///
  425. BX_CONST_FUNC Quaternion rotateZ(float _az);
  426. ///
  427. BX_CONSTEXPR_FUNC bool isEqual(const Quaternion _a, const Quaternion _b, float _epsilon);
  428. ///
  429. void mtxIdentity(float* _result);
  430. ///
  431. void mtxTranslate(float* _result, float _tx, float _ty, float _tz);
  432. ///
  433. void mtxScale(float* _result, float _sx, float _sy, float _sz);
  434. ///
  435. void mtxScale(float* _result, float _scale);
  436. ///
  437. void mtxFromNormal(
  438. float* _result
  439. , const Vec3& _normal
  440. , float _scale
  441. , const Vec3& _pos
  442. );
  443. ///
  444. void mtxFromNormal(
  445. float* _result
  446. , const Vec3& _normal
  447. , float _scale
  448. , const Vec3& _pos
  449. , float _angle
  450. );
  451. ///
  452. void mtxFromQuaternion(float* _result, const Quaternion& _rotation);
  453. ///
  454. void mtxFromQuaternion(float* _result, const Quaternion& _rotation, const Vec3& _translation);
  455. ///
  456. void mtxLookAt(
  457. float* _result
  458. , const Vec3& _eye
  459. , const Vec3& _at
  460. , const Vec3& _up = { 0.0f, 1.0f, 0.0f }
  461. , Handedness::Enum _handedness = Handedness::Left
  462. );
  463. ///
  464. void mtxProj(
  465. float* _result
  466. , float _ut
  467. , float _dt
  468. , float _lt
  469. , float _rt
  470. , float _near
  471. , float _far
  472. , bool _homogeneousNdc
  473. , Handedness::Enum _handedness = Handedness::Left
  474. );
  475. ///
  476. void mtxProj(
  477. float* _result
  478. , const float _fov[4]
  479. , float _near
  480. , float _far
  481. , bool _homogeneousNdc
  482. , Handedness::Enum _handedness = Handedness::Left
  483. );
  484. ///
  485. void mtxProj(
  486. float* _result
  487. , float _fovy
  488. , float _aspect
  489. , float _near
  490. , float _far
  491. , bool _homogeneousNdc
  492. , Handedness::Enum _handedness = Handedness::Left
  493. );
  494. ///
  495. void mtxProjInf(
  496. float* _result
  497. , const float _fov[4]
  498. , float _near
  499. , bool _homogeneousNdc
  500. , Handedness::Enum _handedness = Handedness::Left
  501. , NearFar::Enum _nearFar = NearFar::Default
  502. );
  503. ///
  504. void mtxProjInf(
  505. float* _result
  506. , float _ut
  507. , float _dt
  508. , float _lt
  509. , float _rt
  510. , float _near
  511. , bool _homogeneousNdc
  512. , Handedness::Enum _handedness = Handedness::Left
  513. , NearFar::Enum _nearFar = NearFar::Default
  514. );
  515. ///
  516. void mtxProjInf(
  517. float* _result
  518. , float _fovy
  519. , float _aspect
  520. , float _near
  521. , bool _homogeneousNdc
  522. , Handedness::Enum _handedness = Handedness::Left
  523. , NearFar::Enum _nearFar = NearFar::Default
  524. );
  525. ///
  526. void mtxOrtho(
  527. float* _result
  528. , float _left
  529. , float _right
  530. , float _bottom
  531. , float _top
  532. , float _near
  533. , float _far
  534. , float _offset
  535. , bool _homogeneousNdc
  536. , Handedness::Enum _handedness = Handedness::Left
  537. );
  538. ///
  539. void mtxRotateX(float* _result, float _ax);
  540. ///
  541. void mtxRotateY(float* _result, float _ay);
  542. ///
  543. void mtxRotateZ(float* _result, float _az);
  544. ///
  545. void mtxRotateXY(float* _result, float _ax, float _ay);
  546. ///
  547. void mtxRotateXYZ(float* _result, float _ax, float _ay, float _az);
  548. ///
  549. void mtxRotateZYX(float* _result, float _ax, float _ay, float _az);
  550. ///
  551. void mtxSRT(
  552. float* _result
  553. , float _sx
  554. , float _sy
  555. , float _sz
  556. , float _ax
  557. , float _ay
  558. , float _az
  559. , float _tx
  560. , float _ty
  561. , float _tz
  562. );
  563. ///
  564. Vec3 mul(const Vec3& _vec, const float* _mat);
  565. ///
  566. Vec3 mulXyz0(const Vec3& _vec, const float* _mat);
  567. ///
  568. Vec3 mulH(const Vec3& _vec, const float* _mat);
  569. ///
  570. void vec4MulMtx(float* _result, const float* _vec, const float* _mat);
  571. ///
  572. void mtxMul(float* _result, const float* _a, const float* _b);
  573. ///
  574. void mtxTranspose(float* _result, const float* _a);
  575. ///
  576. void mtx3Inverse(float* _result, const float* _a);
  577. ///
  578. void mtxInverse(float* _result, const float* _a);
  579. ///
  580. void mtx3Cofactor(float* _result, const float* _a);
  581. ///
  582. void mtxCofactor(float* _result, const float* _a);
  583. ///
  584. Vec3 calcNormal(const Vec3& _va, const Vec3& _vb, const Vec3& _vc);
  585. ///
  586. void calcPlane(Plane& _outPlane, const Vec3& _va, const Vec3& _vb, const Vec3& _vc);
  587. ///
  588. void calcPlane(Plane& _outPlane, const Vec3& _normal, const Vec3& _pos);
  589. ///
  590. BX_CONSTEXPR_FUNC float distance(const Plane& _plane, const Vec3& _pos);
  591. ///
  592. BX_CONSTEXPR_FUNC bool isEqual(const Plane& _a, const Plane& _b, float _epsilon);
  593. ///
  594. void calcLinearFit2D(float _result[2], const void* _points, uint32_t _stride, uint32_t _numPoints);
  595. ///
  596. void calcLinearFit3D(float _result[3], const void* _points, uint32_t _stride, uint32_t _numPoints);
  597. ///
  598. void rgbToHsv(float _hsv[3], const float _rgb[3]);
  599. ///
  600. void hsvToRgb(float _rgb[3], const float _hsv[3]);
  601. ///
  602. BX_CONST_FUNC float toLinear(float _a);
  603. ///
  604. BX_CONST_FUNC float toGamma(float _a);
  605. } // namespace bx
  606. #include "inline/math.inl"
  607. #endif // BX_MATH_H_HEADER_GUARD