Math.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. //========================================================================
  3. // CMath.h - useful and fast math functions and approximations
  4. //
  5. //
  6. // Part of the GameCode4 Application
  7. //
  8. // GameCode4 is the sample application that encapsulates much of the source code
  9. // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
  10. // "Rez" Graham, published by Charles River Media.
  11. // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
  12. //
  13. // If this source code has found it's way to you, and you think it has helped you
  14. // in any way, do the authors a favor and buy a new copy of the book - there are
  15. // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
  16. // by clicking here:
  17. // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
  18. //
  19. // There's a companion web site at http://www.mcshaffry.com/GameCode/
  20. //
  21. // The source code is managed and maintained through Google Code:
  22. // http://code.google.com/p/gamecode4/
  23. //
  24. // (c) Copyright 2012 Michael L. McShaffry and David Graham
  25. //
  26. // This program is free software; you can redistribute it and/or
  27. // modify it under the terms of the GNU Lesser GPL v3
  28. // as published by the Free Software Foundation.
  29. //
  30. // This program is distributed in the hope that it will be useful,
  31. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  33. // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
  34. //
  35. // You should have received a copy of the GNU Lesser GPL v3
  36. // along with this program; if not, write to the Free Software
  37. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  38. //
  39. //========================================================================
  40. //========================================================================
  41. //
  42. // Original Code written at Compulsive Development
  43. //
  44. //========================================================================
  45. //--------------------------------------------------------------------------------
  46. // Includes
  47. //--------------------------------------------------------------------------------
  48. #include "../Graphics3D/Geometry.h"
  49. #include <functional>
  50. #include <vector>
  51. //--------------------------------------------------------------------------------
  52. // Defines
  53. //--------------------------------------------------------------------------------
  54. //--------------------------------------------------------------------------------
  55. /* Period parameters */
  56. #define CMATH_N 624
  57. #define CMATH_M 397
  58. #define CMATH_MATRIX_A 0x9908b0df /* constant vector a */
  59. #define CMATH_UPPER_MASK 0x80000000 /* most significant w-r bits */
  60. #define CMATH_LOWER_MASK 0x7fffffff /* least significant r bits */
  61. /* Tempering parameters */
  62. #define CMATH_TEMPERING_MASK_B 0x9d2c5680
  63. #define CMATH_TEMPERING_MASK_C 0xefc60000
  64. #define CMATH_TEMPERING_SHIFT_U(y) (y >> 11)
  65. #define CMATH_TEMPERING_SHIFT_S(y) (y << 7)
  66. #define CMATH_TEMPERING_SHIFT_T(y) (y << 15)
  67. #define CMATH_TEMPERING_SHIFT_L(y) (y >> 18)
  68. #define RADIANS_TO_DEGREES(x) ((x) * 180.0f / GCC_PI)
  69. #define DEGREES_TO_RADIANS(x) ((x) * GCC_PI / 180.0f)