-
Notifications
You must be signed in to change notification settings - Fork 33
/
FlightProperty.cs
112 lines (91 loc) · 2.45 KB
/
FlightProperty.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using UnityEngine;
namespace KSPAdvancedFlyByWire
{
class FlightProperty
{
private float m_Value = 0.0f;
private float m_Velocity = 0.0f;
private float m_Acceleration = 0.0f;
private float m_MinValue = 0.0f;
private float m_MaxValue = 0.0f;
private int m_Increment = 0;
private float m_IncrementStep = 0.0f;
private float m_Trim = 0.0f;
public FlightProperty(float minValue, float maxValue)
{
m_MinValue = minValue;
m_MaxValue = maxValue;
}
public void SetAcceleration(float accel)
{
m_Acceleration = accel;
}
public void SetVelocity(float velocity)
{
m_Velocity = velocity;
}
public void SetValue(float value)
{
m_Value = value;
m_Velocity = 0.0f;
m_Acceleration = 0.0f;
}
public void SetIncrement(int increment, float incrementStep = 0.0f)
{
m_Increment = increment;
m_IncrementStep = incrementStep;
}
public void SetTrim(float trim)
{
m_Trim = trim;
}
public float GetTrim()
{
return m_Trim;
}
public bool HasIncrement()
{
return m_Increment != 0;
}
public float GetValue()
{
return m_Value;
}
public void SetZero()
{
m_Value = 0.0f;
m_Velocity = 0.0f;
m_Acceleration = 0.0f;
}
public void SetMax()
{
m_Value = m_MinValue;
m_Velocity = 0.0f;
m_Acceleration = 0.0f;
}
public void SetMinMaxValues(float min, float max)
{
m_MinValue = min;
m_MaxValue = max;
}
public void Increment(float value)
{
m_Value += value;
m_Velocity = 0.0f;
m_Acceleration = 0.0f;
}
public float Update()
{
if (m_Increment != 0)
{
SetAcceleration(m_Increment * m_IncrementStep);
}
m_Velocity += m_Acceleration * Time.deltaTime;
m_Value += m_Velocity * Time.deltaTime;
m_Value = Utility.Clamp(m_Value + m_Trim, m_MinValue, m_MaxValue);
return m_Value;
}
}
}