-
Notifications
You must be signed in to change notification settings - Fork 0
/
Car.cs
276 lines (223 loc) · 6.04 KB
/
Car.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
using rgn.CarParts;
using rgn.Physics;
using System;
namespace rgn
{
public class Car
{
private Differential differential = new Differential();
private Clutch clutch = new Clutch();
private Gearbox gearbox = new Gearbox();
private Suspension suspension = new Suspension();
public Car(string make, string model)
{
Make = make;
Model = model;
}
internal Car(Differential differential, Clutch clutch, Gearbox gearbox, Suspension suspension)
{
this.differential = differential;
this.clutch = clutch;
this.gearbox = gearbox;
this.suspension = suspension;
}
// car related types
public enum DriveType
{
Awd,
Fwd,
Rwd
}
public enum TransmissionType
{
MT,
AT
}
public enum CarType
{
Sports,
Racecar,
Supercar,
Drift,
Drag,
Rally,
Concept,
Hypercar,
Tuned
}
public enum RacingType
{
GTR,
F1,
Touring
}
public enum TireType
{
Sport,
SemiSlick,
Slick,
Supersoft,
Soft,
Medium,
Hard,
Dry,
Wet,
Street,
Rally,
Dirt,
Snow,
Summer,
}
public enum Paint
{
Matte,
Chrome,
Metallic,
Pearl,
Solid
}
public enum SafetySystems
{
ABS,
ESP,
TCS,
ESC,
ASR,
}
public enum Price
{
Usd,
Eur
}
public float Speed
{
get;
set;
}
public float Distance
{
get;
set;
}
public int TopSpeed { get; set; }
public int Handling { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public string Color { get; set; }
public string Description { get; set; }
// horsepower
public int HP { get; set; }
public int Weight { get; set; }
public float WheelBase { get; set; }
public float RearTrack { get; set; }
public float TurnRadius { get; set; }
public float WheelRadius { get; set; }
public int RPM { get; set; }
public bool IsLocked { get; set; }
public bool IsInMeeting { get; set; }
public bool IsOnTrack { get; set; }
public bool IsWon { get; set; }
public bool IsUsed { get; set; }
public bool AImode { get; set; }
public bool EnableCarPhysics { get; set; }
public float FuelConsumption { get; set; }
public float TireExploit { get; set; }
public enum Wheels
{
// front
FR,
FL,
// rear
RL,
RR
}
public enum WheelColliders
{
// front
ColFR,
ColFL,
// rear
ColRL,
ColRR
}
private Rigid rb;
/// <summary>
/// left angle of ackermann steering in degrees
/// </summary>
/// params in metres
/// <param name="rearTrack"></param>
/// <param name="wheelBase"></param>
/// <param name="turnRadius"></param>
///
/// <returns>angle</returns>
public static double AckermannLeft(float rearTrack, float wheelBase, float turnRadius)
{
var left = Math.Atan(wheelBase / (turnRadius + rearTrack / 2));
return Maths.RadToDeg(left);
}
/// <summary>
/// right angle of ackermann steering in degrees
/// </summary>
/// <param name="rearTrack"></param>
/// <param name="wheelBase"></param>
/// <param name="turnRadius"></param>
/// <returns>angle</returns>
public static double AckermannRight(float rearTrack, float wheelBase, float turnRadius)
{
var right = Math.Atan(wheelBase / (turnRadius - rearTrack / 2));
return Maths.RadToDeg(right);
}
/// <summary>
/// Meters per second to kmh.
/// </summary>
/// <returns>speed in kmh</returns>
/// <param name="speed">Speed</param>
public int MpsToKmh(float speed)
{
return (int)(speed * 3.6);
}
/// <summary>
/// Meters to km.
/// </summary>
/// <returns>The km.</returns>
/// <param name="distance">Distance.</param>
public float MToKm(float distance)
{
return distance / 1000;
}
/// <summary>
/// Kmh to mph
/// </summary>
/// <returns>speed in mph</returns>
/// <param name="speed">Speed</param>
public int KmhToMph(int speed)
{
return (int)(speed / 1.61);
}
/// <summary>
/// Mph to kmh
/// </summary>
/// <returns>speed in kmh</returns>
/// <param name="speed">Speed</param>
public int MphToKmh(int speed)
{
return (int)(speed * 1.61);
}
public void Accelerate(int engineForce)
{
rb.AddForce(engineForce);
}
public void Brake(int brakeForce)
{
rb.AddForce(brakeForce);
}
public void SteerLeft(int torque)
{
rb.AddTorque(torque * -1);
}
public void SteerRight(int torque)
{
rb.AddTorque(torque);
}
}
}