-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.go
178 lines (167 loc) · 3.75 KB
/
model.go
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
package F1_2021_game_udp
import "github.com/ariyn/F1-2021-game-udp/packet"
type Float3d struct {
X float32
Y float32
Z float32
}
type Int3d struct {
X int
Y int
Z int
}
type FloatWheels struct {
RL float32
RR float32
FL float32
FR float32
}
type IntWheels struct {
RL int
RR int
FL int
FR int
}
type MotionData struct {
Position Float3d
Velocity Float3d
ForwardDir Int3d
RightDir Int3d
GForce Float3d
Heading Float3d
}
type PlayerMotionData struct {
Timestamp uint64
Position Float3d
Velocity Float3d
ForwardDir Int3d
RightDir Int3d
GForce Float3d
Heading Float3d
SuspensionPosition FloatWheels
SuspensionVelocity FloatWheels
SuspensionAcceleration FloatWheels
WheelSpeed FloatWheels
WheelSlip FloatWheels
LocalVelocity Float3d
AngularVelocity Float3d
AngularAcceleration Float3d
FrontWheelsAngle float32 // Current front wheels angle in radians
}
func GetPlayerMotionData(timestamp int64, m *packet.MotionData) PlayerMotionData {
player := m.Player()
return PlayerMotionData{
Timestamp: uint64(timestamp),
Position: Float3d{
X: player.WorldPositionX,
Y: player.WorldPositionY,
Z: player.WorldPositionZ,
},
Velocity: Float3d{
X: player.WorldVelocityX,
Y: player.WorldVelocityY,
Z: player.WorldVelocityZ,
},
ForwardDir: Int3d{
X: int(player.WorldForwardDirX),
Y: int(player.WorldForwardDirY),
Z: int(player.WorldForwardDirZ),
},
RightDir: Int3d{
X: int(player.WorldRightDirX),
Y: int(player.WorldRightDirY),
Z: int(player.WorldRightDirZ),
},
GForce: Float3d{
X: player.GForceLateral,
Y: player.GForceLongitudinal,
Z: player.GForceVertical,
},
Heading: Float3d{
X: player.Yaw,
Y: player.Roll,
Z: player.Pitch,
},
SuspensionPosition: FloatWheels{
RL: m.SuspensionPosition[0],
RR: m.SuspensionPosition[1],
FL: m.SuspensionPosition[2],
FR: m.SuspensionPosition[3],
},
SuspensionVelocity: FloatWheels{
RL: m.SuspensionVelocity[0],
RR: m.SuspensionVelocity[1],
FL: m.SuspensionVelocity[2],
FR: m.SuspensionVelocity[3],
},
SuspensionAcceleration: FloatWheels{
RL: m.SuspensionAcceleration[0],
RR: m.SuspensionAcceleration[1],
FL: m.SuspensionAcceleration[2],
FR: m.SuspensionAcceleration[3],
},
WheelSpeed: FloatWheels{
RL: m.WheelSpeed[0],
RR: m.WheelSpeed[1],
FL: m.WheelSpeed[2],
FR: m.WheelSpeed[3],
},
WheelSlip: FloatWheels{
RL: m.WheelSlip[0],
RR: m.WheelSlip[1],
FL: m.WheelSlip[2],
FR: m.WheelSlip[3],
},
LocalVelocity: Float3d{
X: m.LocalVelocityX,
Y: m.LocalVelocityY,
Z: m.LocalVelocityZ,
},
AngularVelocity: Float3d{
X: m.AngularVelocityX,
Y: m.AngularVelocityY,
Z: m.AngularVelocityZ,
},
AngularAcceleration: Float3d{
X: m.AngularAccelerationX,
Y: m.AngularAccelerationY,
Z: m.AngularAccelerationZ,
},
FrontWheelsAngle: m.FrontWheelsAngle,
}
}
func GetMotionData(timestamp int64, m packet.CarMotionData) PlayerMotionData {
return PlayerMotionData{
Timestamp: uint64(timestamp),
Position: Float3d{
X: m.WorldPositionX,
Y: m.WorldPositionY,
Z: m.WorldPositionZ,
},
Velocity: Float3d{
X: m.WorldVelocityX,
Y: m.WorldVelocityY,
Z: m.WorldVelocityZ,
},
ForwardDir: Int3d{
X: int(m.WorldForwardDirX),
Y: int(m.WorldForwardDirY),
Z: int(m.WorldForwardDirZ),
},
RightDir: Int3d{
X: int(m.WorldRightDirX),
Y: int(m.WorldRightDirY),
Z: int(m.WorldRightDirZ),
},
GForce: Float3d{
X: m.GForceLateral,
Y: m.GForceLongitudinal,
Z: m.GForceVertical,
},
Heading: Float3d{
X: m.Yaw, // TODO: yaw -> Z, roll -> X, pitch -> Y
Y: m.Roll,
Z: m.Pitch,
},
}
}