GameServer
MathUtil.h
[詳解]
1 #ifndef __MATHUTIL_H__
2 #define __MATHUTIL_H__
3 
4 #define _USE_MATH_DEFINES
5 #include <math.h>
6 #include "Vector3D.h"
7 
8 // 演算関係.
9 class MathUtil
10 {
11 
12 public:
13 
14  // 補間.
15  template<class T>
16  static T Lerp(T Start, T End, float Rate);
17 
18  // DegreeをRadianに変換.
19  static float DegToRad(float Deg)
20  {
21  if (fabsf(Deg) < FLT_EPSILON) { return 0.0f; }
22  return (float)(Deg * M_PI / 180.0f);
23  }
24 
25  // RadianをDegreeに変換.
26  static float RadToDeg(float Rad)
27  {
28  if (fabsf(Rad) < FLT_EPSILON) { return 0.0f; }
29  return (float)(Rad * 180.0f / M_PI);
30  }
31 
32  // ベクトルを回転.
33  static Vector3D RotateVector(const Vector3D &Vec, float Deg)
34  {
35  Vector3D Result;
36  float Rad = DegToRad(Deg);
37  Result.X = ((Vec.X * cosf(Rad)) - (Vec.Y * sinf(Rad)));
38  Result.Y = ((Vec.X * sinf(Rad)) + (Vec.Y * cosf(Rad)));
39  Result.Z = Vec.Z;
40  return Result;
41  }
42 
43  // 内積.
44  static float Dot(const Vector3D &A, const Vector3D &B)
45  {
46  return ((A.X * B.X) + (A.Y * B.Y) + (A.Z * B.Z));
47  }
48 
49  // 外積.
50  static Vector3D Cross(const Vector3D &A, const Vector3D &B)
51  {
52  Vector3D Vec;
53  Vec.X = (A.Y * B.Z) - (A.Z * B.Y);
54  Vec.Y = (A.Z * B.X) - (A.X * B.Z);
55  Vec.Z = (A.X * B.Y) - (A.Y * B.X);
56  return Vec;
57  }
58 
59 };
60 
61 #endif // #ifndef __MATHUTIL_H__
static float DegToRad(float Deg)
Definition: MathUtil.h:19
static float RadToDeg(float Rad)
Definition: MathUtil.h:26
float Z
Definition: Vector3D.h:32
static float Dot(const Vector3D &A, const Vector3D &B)
Definition: MathUtil.h:44
Definition: Vector3D.h:8
float X
Definition: Vector3D.h:30
float Y
Definition: Vector3D.h:31
static T Lerp(T Start, T End, float Rate)
static Vector3D RotateVector(const Vector3D &Vec, float Deg)
Definition: MathUtil.h:33
Definition: MathUtil.h:9
static Vector3D Cross(const Vector3D &A, const Vector3D &B)
Definition: MathUtil.h:50