forked from duckman6969/fix-skill-issue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath.cpp
More file actions
88 lines (78 loc) · 2.83 KB
/
Math.cpp
File metadata and controls
88 lines (78 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <math.h>
namespace math
{
const float INCHES_TO_METER_RATE = 39.3701;
double distanceToMeters(float distance)
{
return distance / INCHES_TO_METER_RATE;
}
double calculateDistance(float x1, float y1, float z1, float x2, float y2, float z2)
{
float dx = (x1 - x2);
float dy = (y1 - y2);
float dz = (z1 - z2);
float distance = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2));
return distance;
}
double calculateDistanceInMeters(float x1, float y1, float z1, float x2, float y2, float z2)
{
return distanceToMeters(calculateDistance(x1, y1, z1, x2, y2, z2));
}
double calculateDistance2D(float x1, float y1, float x2, float y2)
{
float dx = (x1 - x2);
float dy = (y1 - y2);
float distance = sqrt(pow(dx, 2) + pow(dy, 2));
return distance;
}
double calculateDesiredYaw(
double localPlayerLocationX,
double localPlayerLocationY,
double enemyPlayerLocationX,
double enemyPlayerLocationY)
{
const double locationDeltaX = enemyPlayerLocationX - localPlayerLocationX;
const double locationDeltaY = enemyPlayerLocationY - localPlayerLocationY;
const double yawInRadians = atan2(locationDeltaY, locationDeltaX);
const double yawInDegrees = yawInRadians * (180 / M_PI);
return yawInDegrees;
}
double calculateDesiredPitch(
double localPlayerLocationX,
double localPlayerLocationY,
double localPlayerLocationZ,
double enemyPlayerLocationX,
double enemyPlayerLocationY,
double enemyPlayerLocationZ)
{
const double locationDeltaZ = (enemyPlayerLocationZ -
localPlayerLocationZ - INCHES_TO_METER_RATE * 0.5);
const double distanceBetweenPlayers = math::calculateDistance2D(enemyPlayerLocationX, enemyPlayerLocationY, localPlayerLocationX, localPlayerLocationY);
const double pitchInRadians = atan2(-locationDeltaZ, distanceBetweenPlayers);
const double pitchInDegrees = pitchInRadians * (180 / M_PI);
return pitchInDegrees;
}
double calculatePitchAngleDelta(double oldAngle, double newAngle)
{
double wayA = newAngle - oldAngle;
return wayA;
}
double calculateAngleDelta(double oldAngle, double newAngle)
{
double wayA = newAngle - oldAngle;
double wayB = 360 - abs(wayA);
if (wayA > 0 && wayB > 0)
wayB *= -1;
if (abs(wayA) < abs(wayB))
return wayA;
return wayB;
}
void convertPointByYaw(double yaw, double x, double y, double& xOut, double& yOut) {
double rad = (90 - yaw) / 180 * M_PI;
double cos = std::cos(rad);
double sin = std::sin(rad);
xOut = x * cos - y * sin;
yOut = y * cos + x * sin;
}
}