TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_constants.hpp
1 
9 #ifndef TurtleBrains_Constants_hpp
10 #define TurtleBrains_Constants_hpp
11 
12 namespace TurtleBrains
13 {
14  namespace Math
15  {
16  template<typename Type> constexpr Type Pi(void) { return static_cast<Type>(3.141592653589793); }
17  template<typename Type> constexpr Type TwoPi(void) { return static_cast<Type>(Pi<long double>() * 2.0); }
18 
19  static const float kPi = Pi<float>();
20  static const float kTwoPi = TwoPi<float>();
21 
26  static const float kTolerance(0.00001f);
27 
28  //Conversions
29  const float kPoundsToKilograms(0.45359237f);
30  const float kKilogramsToPounds(1.0f / kPoundsToKilograms);
31  const float kInchesToMeters(0.0254f);
32  const float kMetersToInches(1.0f / kInchesToMeters);
33  const float kFeetToMeters(0.3048f);
34  const float kMetersToFeet(1.0f / kFeetToMeters);
35  const float kMilesToKilometers(1.609344f);
36  const float kKilometersToMiles(1.0f / kMilesToKilometers);
37  const float kFootPoundsToNewtonMeters(0.73756214837f);
39 
40  namespace Convert
41  { //Conversion Functions... Most of these values were found from Google.
42  //Rotations
43 
47  template<typename Type> constexpr Type DegreesToRadians(const Type& degrees) { return degrees * Pi<Type>() / Type(180.0); }
48 
52  template<typename Type> constexpr Type RadiansToDegrees(const Type& radians) { return radians * Type(180.0) / Pi<Type>(); }
53 
54  //Weights/Mass
55 
59  template<typename Type> constexpr Type PoundsToKilograms(const Type& pounds) { return static_cast<Type>(pounds * kPoundsToKilograms); }
60 
64  template<typename Type> constexpr Type KilogramsToPounds(const Type& kilograms) { return static_cast<Type>(kilograms * kKilogramsToPounds); }
65 
66  //Distances
67 
71  template<typename Type> constexpr Type InchesToMeters(const Type& inches) { return static_cast<Type>(inches * kInchesToMeters); }
72 
76  template<typename Type> constexpr Type FeetToMeters(const Type& feet) { return static_cast<Type>(feet * kFeetToMeters); };
77 
81  template<typename Type> constexpr Type MetersToFeet(const Type& meters) { return static_cast<Type>(meters * kMetersToFeet); };
82 
86  template<typename Type> constexpr Type MilesToKilometers(const Type& mile) { return static_cast<Type>(mile * kMilesToKilometers); }
87 
91  template<typename Type> constexpr Type KilometersToMiles(const Type& kilometers) { return static_cast<Type>(kilometers * kKilometersToMiles); }
92 
97  template<typename Type> constexpr Type KilometersToMeters(const Type& kmh) { return static_cast<Type>(kmh * 1000.0f); }
98 
99  //Speeds
100 
104  template<typename Type> constexpr Type MileHourToMeterSecond(const Type& mph) { return static_cast<Type>(mph / 2.2369362920544f); }
105 
109  template<typename Type> constexpr Type MeterSecondToMileHour(const Type& meterSec) { return static_cast<Type>(meterSec * 2.2369362920544f); }
110 
114  template<typename Type> constexpr Type KilometerHourToMeterSecond(const Type& kmh) { return static_cast<Type>(kmh / 3.6f); }
115 
119  template<typename Type> constexpr Type MeterSecondToKilometerHour(const Type& meterSecond) { return static_cast<Type>(meterSecond * 3.6f); }
120 
121  //Torque
122 
126  template<typename Type> constexpr Type FootPoundsToNewtonMeters(const Type& footPounds) { return static_cast<Type>(footPounds / kFootPoundsToNewtonMeters); }
127 
131  template<typename Type> constexpr Type NewtonMetersToFootPounds(const Type& newtonMeters) { return static_cast<Type>(newtonMeters / kNewtonMetersToFootPounds); }
132 
133  //Temperature
134 
138  template<typename Type> constexpr Type FahrenheitToCelsius(const Type& fahrenheit) { return static_cast<Type>((fahrenheit - 32.0f) / 1.8000f); }
139 
143  template<typename Type> constexpr Type CelsiusToFahrenheit(const Type& celsius) { return static_cast<Type>((celsius * 1.8000f) + 32.0f); }
144 
145  }; /* namespace Convert */
146  }; /* namespace Math */
147 }; /* namespace TurtleBrains */
148 
149 namespace tbMath = TurtleBrains::Math;
150 
151 #endif /* TurtleBrains_Constants_hpp */
const float kPoundsToKilograms(0.45359237f)
A constant for the conversion of 1 pound (lb) to 1 kilogram (kg).
Contains objects and functions for dealing with Vector and Matrix math.
const float kKilogramsToPounds(1.0f/kPoundsToKilograms)
A constant for the conversion of 1 kilogram (kg) to 1 pound (lb).
const float kInchesToMeters(0.0254f)
A constant for the distance conversion of 1 inch to 1 meter.
const float kFeetToMeters(0.3048f)
A constant for the distance conversion from 1 foot to 1 meter.
static const float kTolerance(0.00001f)
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
const float kMetersToInches(1.0f/kInchesToMeters)
A constant for the distance conversion of 1 meter to 1 inch.
const float kMilesToKilometers(1.609344f)
A constant for the distance conversion from 1 mile to 1 kilometer.
static const float kPi
A constant for the mathematical concept of Pi stored in a float.
Definition: tb_constants.hpp:19
const float kKilometersToMiles(1.0f/kMilesToKilometers)
A constant for the distance conversion from 1 kilometer to 1 mile.
const float kNewtonMetersToFootPounds(1.0f/kFootPoundsToNewtonMeters)
A constant for the torque conversion from Nm to ft-lbs.
static const float kTwoPi
A constant for Pi * 2 stored in a float.
Definition: tb_constants.hpp:20
const float kFootPoundsToNewtonMeters(0.73756214837f)
A constant for the torque in ft-lbs to Nm.
const float kMetersToFeet(1.0f/kFeetToMeters)
A constant for the distance conversion from 1 meter to 1 foot.