-
Notifications
You must be signed in to change notification settings - Fork 33
/
AxisConfiguration.cs
87 lines (73 loc) · 2.27 KB
/
AxisConfiguration.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace KSPAdvancedFlyByWire
{
public struct AxisConfiguration
{
public float m_PositiveDeadZone;
public float m_NegativeDeadZone;
public float m_Left;
public float m_Identity;
public float m_Right;
public float Rescale(float value, Curve analogEvaluationCurve, bool manualDeadZones)
{
if (value < m_Left)
{
m_Left = value;
}
else if (value > m_Right)
{
m_Right = value;
}
float eps = 1e-4f;
if (value + eps > m_Identity && value - eps < m_Identity)
{
value = 0.0f;
}
else if (value < m_Identity)
{
value = (value - m_Identity) / (m_Identity - m_Left);
}
else if (value > m_Identity)
{
value = (value - m_Identity) / (m_Right - m_Identity);
}
if (Math.Abs(value) < 1e-4)
{
value = 0.0f;
}
if (value > 0.0f)
{
if (value < m_PositiveDeadZone && !manualDeadZones)
{
m_PositiveDeadZone = value;
}
float deadZone = m_PositiveDeadZone;
float t = (1.0f - deadZone);
if (t != 0.0f)
{
value = (value - deadZone) / t;
}
value = Mathf.Clamp(value, 0.0f, 1.0f);
}
else if (value < 0.0f)
{
if (Math.Abs(value) < m_NegativeDeadZone && !manualDeadZones)
{
m_NegativeDeadZone = Math.Abs(value);
}
float deadZone = m_NegativeDeadZone;
float t = (1.0f - deadZone);
if (t != 0.0f)
{
value = -1.0f * (Math.Abs(value) - deadZone) / t;
}
value = Mathf.Clamp(value, -1.0f, 0.0f);
}
return 1.0f * Math.Sign(value) * analogEvaluationCurve.Evaluate(Math.Abs(value));
}
}
}