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
use extend::ToFromC;
use ffi;
use na::{Point3, Vector3};
pub struct Ball(ffi::Ball);
impl Ball {
pub fn new() -> Self {
Ball(unsafe { ffi::Ball::new() })
}
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 t(&self) -> f32 {
self.0.t
}
pub fn set_t(&mut self, t: f32) {
self.0.t = t;
}
pub fn step(&mut self, dt: f32) {
unsafe { self.0.step(dt) };
}
}
#[cfg(test)]
mod tests {
use ball::Ball;
use na::{Point3, Vector3};
#[test]
fn ball() {
let mut ball = Ball::new();
ball.set_pos(Point3::new(0.0, 0.0, 100.0));
ball.set_vel(Vector3::new(1000.0, 0.0, 0.0));
ball.step(1.0 / 120.0);
println!("{:?}", ball.pos());
assert!(1.0 < ball.pos().x && ball.pos().x < 10.0);
assert!(99.0 < ball.pos().z && ball.pos().z < 99.99);
}
}