Leviathan  0.8.0.0
Leviathan game engine
Leviathan::MMath Namespace Reference

Functions

DLLEXPORT float CoordinateDistance (float x1, float x2, float y1, float y2)
 
DLLEXPORT double AngleBetweenPoints (float x1, float x2, float y1, float y2)
 
DLLEXPORT bool IsPointInsidePolygon (const std::vector< Float3 > &polygon, const Float3 &point)
 
DLLEXPORT int GreatestCommonDivisor (int a, int b)
 greatest common divisor, courtesy of Wikipedia More...
 
DLLEXPORT Float3 CalculateNormal (const Float3 &p1, const Float3 &p2, const Float3 &p3)
 calculates a normal for triangle and returns in normalized // More...
 
DLLEXPORT bool IsEqual (double x, double y)
 
DLLEXPORT bool IsEqual (float x, float y)
 

Function Documentation

◆ AngleBetweenPoints()

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

Definition at line 14 of file CommonMath.cpp.

15 {
16  return atan2(y2 - y1, x2 - x1);
17 }

◆ CalculateNormal()

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

calculates a normal for triangle and returns in normalized //

Definition at line 48 of file CommonMath.cpp.

50 {
51  // according to OpenGL wiki //
52 
53  // some vectors for calculating final normal //
54  const Float3 VecU = p2 - p1;
55  const Float3 VecV = p3 - p1;
56 
57  // normalize before returning //
58  return Float3(VecU.Y * VecV.Z - VecU.Z * VecV.Y, VecU.Z * VecV.X - VecU.X * VecV.Z,
59  VecU.X * VecV.Y - VecU.Y * VecV.X)
60  .Normalize();
61 }
DLLEXPORT Float3 Normalize() const
Definition: Types.h:1160

◆ CoordinateDistance()

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

Definition at line 7 of file CommonMath.cpp.

8 {
9  const auto distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
10 
11  return distance;
12 }
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
Definition: checked.h:198

◆ GreatestCommonDivisor()

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

greatest common divisor, courtesy of Wikipedia

Definition at line 19 of file CommonMath.cpp.

20 {
21  return (b == 0 ? a : GreatestCommonDivisor(b, a % b));
22 }
DLLEXPORT int GreatestCommonDivisor(int a, int b)
greatest common divisor, courtesy of Wikipedia
Definition: CommonMath.cpp:19

◆ IsEqual() [1/2]

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

Definition at line 63 of file CommonMath.cpp.

64 {
65  return abs(x - y) <= EPSILON * abs(x);
66 }
constexpr float EPSILON
Definition: Define.h:63

◆ IsEqual() [2/2]

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

Definition at line 68 of file CommonMath.cpp.

69 {
70  return abs(x - y) <= EPSILON * abs(x);
71 }
constexpr float EPSILON
Definition: Define.h:63

◆ IsPointInsidePolygon()

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

Definition at line 24 of file CommonMath.cpp.

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