My Project
MathLib.h
1 #pragma once
2 
3 #ifndef EPSILON
4 #define EPSILON 0.00001f
5 #endif
6 
7 #ifndef FLOAT_POS_INFINITY
8 #define FLOAT_POS_INFINITY 999999999.0f
9 #endif
10 
11 namespace ParaEngine
12 {
13 
14  class CMath
15  {
16  public:
17  CMath(void);
18  ~CMath(void);
19  public:
21  static bool SmoothMoveFloat1(float& src, const float dest, const float fMaxStep);
22 
24  static bool SmoothMoveAngle1(float& src, const float dest, const float fMaxStep);
25 
30  static bool SmoothMoveVec3(Vector3* result, const Vector3& vPosTarget, const Vector3& vPos, FLOAT fIncrease, FLOAT fTolerance/*=0*/);
31 
33  static float ToStandardAngle(float fAngle);
34 
41  static bool MatchString(const std::string& matchPattern, const std::string& matchStr);
42 
47  static bool ComputeFacingTarget(const Vector3& target, const Vector3& source, FLOAT& fFacing);
52  static inline int Round(float fValue);
53 
55  static float MinVec3(const Vector3& v);
57  static float MaxVec3(const Vector3& v);
58 
60  template <class T>
61  static inline bool CompareXZ(const T& a, const T& b)
62  {
63  return (a.x==b.x && a.z==b.z);
64  }
65 
67  template <class T>
68  static bool CompareXZ(const T& a, const T& b, float epsilon)
69  {
70  return (fabs(a.x-b.x) + fabs(a.z-b.z)) < epsilon;
71  }
72 
86  static void GetMatrixScaling(const Matrix4& globalMat, float* fScalingX, float* fScalingY,float* fScalingZ);
87 
95  static Matrix4* CreateBillboardMatrix(Matrix4* pOut, const Matrix4* matModelview, const Vector3* vBillboardPos, bool bAxisAligned = false);
96 
97  // Make a rotation matrix based on the camera's yaw & pitch
98  static void CameraRotMatrixYawPitch(Matrix4& out, float fYaw, float fPitch);
99  };
100 
101  inline int Math::Round(float fValue)
102  {
103  return int(fValue > 0.0f ? fValue + 0.5f : fValue - 0.5f);
104  /*if(fValue>=0)
105  return (((fValue-(int)fValue)>0.5f)?((int)fValue+1):(int)fValue);
106  else
107  return -ToInt(-fValue);*/
108  }
109 }
static int Round(float fValue)
get the closest integer near the specified float number.
Definition: ParaMath.h:609
different physics engine has different winding order.
Definition: EventBinding.h:32
static bool ComputeFacingTarget(const Vector3 &target, const Vector3 &source, FLOAT &fFacing)
facing target in xz plane fFacing: [out] it is in the range [0, 2PI] return true if target!=source(a...
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
static float ToStandardAngle(float fAngle)
make sure that the angle is in the range (-Pi,Pi]
static bool SmoothMoveAngle1(float &src, const float dest, const float fMaxStep)
change src from src to dest, by a maximum of fMaxStep.
static Matrix4 * CreateBillboardMatrix(Matrix4 *pOut, const Matrix4 *matModelview, const Vector3 *vBillboardPos, bool bAxisAligned=false)
create a billboard matrix
static void GetMatrixScaling(const Matrix4 &globalMat, float *fScalingX, float *fScalingY, float *fScalingZ)
Get the scaling factor from globalMat.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
static float MaxVec3(const Vector3 &v)
Returns MAX(x, y, z);.
static bool CompareXZ(const T &a, const T &b, float epsilon)
return true if equal.
Definition: MathLib.h:68
static bool CompareXZ(const T &a, const T &b)
return true if equal.
Definition: MathLib.h:61
Definition: MathLib.h:14
static int Round(float fValue)
get the closest integer near the specified float number.
static bool SmoothMoveFloat1(float &src, const float dest, const float fMaxStep)
change src from src to dest, by a maximum of fMaxStep.
static bool MatchString(const std::string &matchPattern, const std::string &matchStr)
check if the matchStr matches the string pattern in matchPattern
static bool SmoothMoveVec3(Vector3 *result, const Vector3 &vPosTarget, const Vector3 &vPos, FLOAT fIncrease, FLOAT fTolerance)
linearly (smoothly) move vPos to vPosTarget by the amount fIncrease return true if we have reached th...
static float MinVec3(const Vector3 &v)
Returns MIN(x, y, z);.