wwmath.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWMath *
  23. * *
  24. * $Archive:: /Commando/Code/wwmath/wwmath.cpp $*
  25. * *
  26. * Author:: Eric_c *
  27. * *
  28. * $Modtime:: 5/10/01 10:52p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "wwmath.h"
  36. #include "wwhack.h"
  37. #include "lookuptable.h"
  38. #include <stdlib.h>
  39. #include "wwdebug.h"
  40. #include "wwprofile.h"
  41. // TODO: convert to use loouptablemanager...
  42. float _FastAcosTable[ARC_TABLE_SIZE];
  43. float _FastAsinTable[ARC_TABLE_SIZE];
  44. float _FastSinTable[SIN_TABLE_SIZE];
  45. float _FastInvSinTable[SIN_TABLE_SIZE];
  46. void WWMath::Init(void)
  47. {
  48. LookupTableMgrClass::Init();
  49. for (int a=0;a<ARC_TABLE_SIZE;++a) {
  50. float cv=float(a-ARC_TABLE_SIZE/2)*(1.0f/(ARC_TABLE_SIZE/2));
  51. _FastAcosTable[a]=acos(cv);
  52. _FastAsinTable[a]=asin(cv);
  53. }
  54. for (a=0;a<SIN_TABLE_SIZE;++a) {
  55. float cv= (float)a * 2.0f * WWMATH_PI / SIN_TABLE_SIZE; //float(a-SIN_TABLE_SIZE/2)*(1.0f/(SIN_TABLE_SIZE/2));
  56. _FastSinTable[a]=sin(cv);
  57. if (a>0) {
  58. _FastInvSinTable[a]=1.0f/_FastSinTable[a];
  59. } else {
  60. _FastInvSinTable[a]=WWMATH_FLOAT_MAX;
  61. }
  62. }
  63. }
  64. void WWMath::Shutdown(void)
  65. {
  66. LookupTableMgrClass::Shutdown();
  67. }
  68. float WWMath::Random_Float(void)
  69. {
  70. return ((float)(rand() & 0xFFF)) / (float)(0xFFF);
  71. }
  72. /*
  73. ** Force link some modules from this library.
  74. */
  75. void Do_Force_Links(void)
  76. {
  77. FORCE_LINK(curve);
  78. FORCE_LINK(hermitespline);
  79. FORCE_LINK(catmullromspline);
  80. FORCE_LINK(cardinalspline);
  81. FORCE_LINK(tcbspline);
  82. }