phunits.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. ** Command & Conquer Renegade(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 : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/phunits.h $*
  25. * *
  26. * Author:: Greg_h *
  27. * *
  28. * $Modtime:: 9/22/99 9:45a $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef PHUNITS_H
  39. #define PHUNITS_H
  40. /*
  41. ** The purpose of this header file is to define macros and functions which
  42. ** accept data in various units and convert it to the internal units used
  43. ** by the physics system (metric probably).
  44. **
  45. ** Examples:
  46. ** (1) defining a velocity of 10mph:
  47. ** vel = PhysicsUnits::Miles(10.0f) / PhysicsUnits::Hours(1.0f);
  48. **
  49. ** (2) defining a mass of 10 grams:
  50. ** mass = PhysicsUnits::Grams(10.0f);
  51. **
  52. ** (3) defining a force of 60 Newtons (kg*m/s^2):
  53. ** hmmm... ;-)
  54. */
  55. #define INCHES_TO_METERS (0.0254f)
  56. #define FEET_TO_METERS (INCHES_TO_METERS * 12.0f)
  57. #define YARDS_TO_METERS (INCHES_TO_METERS * 36.0f)
  58. #define MILES_TO_METERS (FEET_TO_METERS * 5280.0f)
  59. #define PHYSICS_INCHES(x) (INCHES_TO_METERS * (x))
  60. #define PHYSICS_FEET(x) (FEET_TO_METERS * (x))
  61. #define PHYSICS_YARDS(x) (YARDS_TO_METERS * (x))
  62. #define PHYSICS_MILES(x) (MILES_TO_METERS * (x))
  63. #define PHYSICS_MILLIMETERS(x) ((x) / 1000.0f)
  64. #define PHYSICS_CENTIMETERS(x) ((x) / 100.0f)
  65. #define PHYSICS_DECIMETERS(x) ((x) / 10.0f)
  66. #define PHYSICS_METERS(x) ((x))
  67. #define PHYSICS_KILOMETERS(x) ((x) * 1000.0f)
  68. #define PHYSICS_SECONDS(x) ((x))
  69. #define PHYSICS_MINUTES(x) ((x) * 60.0f)
  70. #define PHYSICS_HOURS(x) ((x) * 60.0f * 60.0f)
  71. #define PHYSICS_GRAMS(x) ((x) * 1000.0f)
  72. #define PHYSICS_KILOGRAMS(x) ((x))
  73. #define PHYSICS_NEWTONS(x) ((x))
  74. class PhysicsUnits
  75. {
  76. // Distance Units:
  77. static float Inches(float inches) { return INCHES_TO_METERS * inches; }
  78. static float Feet(float feet) { return FEET_TO_METERS * feet; }
  79. static float Yards(float yards) { return YARDS_TO_METERS * yards; }
  80. static float Miles(float miles) { return MILES_TO_METERS * miles; }
  81. static float Millimeters(float mm) { return mm / 1000.0f; }
  82. static float Centimeters(float cm) { return cm / 100.0f; }
  83. static float Decimeters(float dm) { return dm / 10.0f; }
  84. static float Meters(float m) { return m; }
  85. static float Kilometers(float km) { return km * 1000.0f; }
  86. // Time Units:
  87. static float Seconds(float s) { return s; }
  88. static float Minutes(float m) { return m * 60.0f; }
  89. static float Hours(float h) { return h * 60.0f * 60.0f; }
  90. // Mass Units:
  91. static float Grams(float g) { return g * 1000.0f; }
  92. static float Kilograms(float kg) { return kg; }
  93. // Force Units:
  94. static float Newtons(float n) { return n; }
  95. };
  96. #endif /*PHUNITS_H*/