Leviathan  0.8.0.0
Leviathan game engine
Leviathan::MMath Class Reference

#include <CommonMath.h>

Static Public Member Functions

static DLLEXPORT float CoordinateDistance (float x1, float x2, float y1, float y2)
 
static DLLEXPORT double AngleBetweenPoints (float x1, float x2, float y1, float y2)
 
static DLLEXPORT bool IsPointInsidePolygon (const std::vector< Float3 > &polygon, const Float3 &point)
 
static DLLEXPORT int GreatestCommonDivisor (int a, int b)
 
static DLLEXPORT Float3 CalculateNormal (const Float3 &p1, const Float3 &p2, const Float3 &p3)
 
static DLLEXPORT bool IsEqual (double x, double y)
 
static DLLEXPORT bool IsEqual (float x, float y)
 

Detailed Description

Definition at line 14 of file CommonMath.h.

Member Function Documentation

◆ AngleBetweenPoints()

double MMath::AngleBetweenPoints ( float  x1,
float  x2,
float  y1,
float  y2 
)
static

Definition at line 14 of file CommonMath.cpp.

14  {
15  double angle = 0;
16 
17  angle = atan2(y2 - y1, x2 - x1);
18 
19 
20  return angle;
21 
22 
23 }

◆ CalculateNormal()

DLLEXPORT Float3 Leviathan::MMath::CalculateNormal ( const Float3 p1,
const Float3 p2,
const Float3 p3 
)
static

Definition at line 63 of file CommonMath.cpp.

63  {
64  // according to OpenGL wiki //
65 
66  // some vectors for calculating final normal //
67  const Float3 VecU = p2-p1;
68  const Float3 VecV = p3-p1;
69 
70  // normalize before returning //
71  return Float3(VecU.Y*VecV.Z-VecU.Z*VecV.Y, VecU.Z*VecV.X-VecU.X*VecV.Z, VecU.X*VecV.Y-VecU.Y*VecV.X).Normalize();
72 }
DLLEXPORT Float3 Normalize() const
Definition: Types.h:878

◆ CoordinateDistance()

float MMath::CoordinateDistance ( float  x1,
float  x2,
float  y1,
float  y2 
)
static

Definition at line 8 of file CommonMath.cpp.

8  {
9  float Distance=0;
10  Distance=sqrt( (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
11 
12  return Distance;
13 }

◆ GreatestCommonDivisor()

int MMath::GreatestCommonDivisor ( int  a,
int  b 
)
static

Definition at line 25 of file CommonMath.cpp.

25  {
26  return (b == 0 ? a : GreatestCommonDivisor(b, a%b));
27 }
static DLLEXPORT int GreatestCommonDivisor(int a, int b)
Definition: CommonMath.cpp:25

◆ IsEqual() [1/2]

DLLEXPORT bool Leviathan::MMath::IsEqual ( double  x,
double  y 
)
static

Definition at line 53 of file CommonMath.cpp.

53  {
54  const double epsilon = 1e-5;
55  return abs(x - y) <= epsilon * abs(x);
56 }

◆ IsEqual() [2/2]

DLLEXPORT bool Leviathan::MMath::IsEqual ( float  x,
float  y 
)
static

Definition at line 58 of file CommonMath.cpp.

58  {
59  const double epsilon = 1e-5;
60  return abs(x - y) <= epsilon * abs(x);
61 }

◆ IsPointInsidePolygon()

DLLEXPORT bool Leviathan::MMath::IsPointInsidePolygon ( const std::vector< Float3 > &  polygon,
const Float3 point 
)
static

Definition at line 29 of file CommonMath.cpp.

31 {
32  //bool IsInside = false;
33  //int i,j;
34  //for(i = 0, j = polygon.size()-1; i < polygon.size(); j = i++){
35  // if(((polygon[i].Y > point.Y) != (polygon[j].Y > point.Y))
36  // && (point.X < (polygon[j].X-polygon[i].X) * (point.Y-polygon[i].Y) / (polygon[j].Y-polygon[i].Y) + polygon[i].X))
37  // IsInside = !IsInside;
38  //}
39  //return IsInside;
40 
41  // better? one http://devmaster.net/forums/topic/5213-point-in-polygon-test/
42  Float3 p = (polygon[polygon.size()-1] - point).Cross(polygon[0] - point);
43  for (unsigned int i = 0; i < polygon.size() - 1; i++){
44 
45  Float3 q = (polygon[i] - point).Cross(polygon[i+1] - point);
46  if(p.Dot(q) < 0)
47  return false;
48  }
49  return true;
50 
51 }
DLLEXPORT float Dot(const Float3 &val) const
Definition: Types.h:860

The documentation for this class was generated from the following files: