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
use extend::ToFromC;
use ffi;
use na::{Matrix3, Point3, Rotation3, Vector3};
pub struct Car(ffi::Car);
impl Car {
pub fn new() -> Self {
Car(unsafe { ffi::Car::new() })
}
pub fn step(&mut self, input: ffi::Input, dt: f32) {
unsafe { self.0.step(input, dt) };
}
pub fn pos(&self) -> Point3<f32> {
Point3::from_c(self.0.x)
}
pub fn set_pos(&mut self, pos: Point3<f32>) {
self.0.x = pos.to_c();
}
pub fn vel(&self) -> Vector3<f32> {
Vector3::from_c(self.0.v)
}
pub fn set_vel(&mut self, vel: Vector3<f32>) {
self.0.v = vel.to_c();
}
pub fn omega(&self) -> Vector3<f32> {
Vector3::from_c(self.0.w)
}
pub fn set_omega(&mut self, omega: Vector3<f32>) {
self.0.w = omega.to_c();
}
pub fn theta(&self) -> Rotation3<f32> {
Rotation3::from_matrix_unchecked(Matrix3::from_c(self.0.o))
}
pub fn set_theta(&mut self, theta: Rotation3<f32>) {
self.0.o = theta.matrix().to_c();
}
pub fn on_ground(&self) -> bool {
self.0.on_ground
}
pub fn set_on_ground(&mut self, on_ground: bool) {
self.0.on_ground = on_ground;
}
}
#[cfg(test)]
mod tests {
use car::Car;
use na::{Point3, Vector3};
#[test]
fn car() {
let mut car = Car::new();
car.set_on_ground(true);
car.set_pos(Point3::origin());
car.set_vel(Vector3::new(1000.0, 0.0, 0.0));
car.step(Default::default(), 1.0 / 120.0);
println!("{:?}", car.pos());
assert!(1.0 < car.pos().x && car.pos().x < 10.0);
}
}