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
use libc::size_t;
use super::super::collision::shapes::shape;
use super::super::common::settings::*;
#[repr(C)]
#[derive(Debug)]
pub struct Filter {
pub category_bits: UInt16,
pub mask_bits: UInt16,
pub group_index: Int16,
}
impl Default for Filter {
fn default() -> Filter {
Filter {
category_bits: 0x0001,
mask_bits: 0xFFFF,
group_index: 0
}
}
}
#[repr(C)]
pub struct FixtureDef {
pub shape: *mut shape::B2Shape,
pub user_data: size_t,
pub friction: Float32,
pub restitution: Float32,
pub density: Float32,
pub is_sensor: bool,
pub filter: Filter
}
impl FixtureDef {
pub fn new(shape: &shape::Shape) -> FixtureDef {
FixtureDef {
shape: shape.handle(),
user_data: 0,
friction: 0.0,
restitution: 0.0,
density: 0.0,
is_sensor: false,
filter: Filter::default()
}
}
}
pub enum B2Fixture {}
extern {
fn b2Fixture_GetNext(this: *mut B2Fixture) -> *mut B2Fixture;
fn b2Fixture_GetShape(this: *mut B2Fixture) -> *mut shape::B2Shape;
fn b2Fixture_GetType(this: *mut B2Fixture) -> shape::Type;
}
#[allow(raw_pointer_derive)]
#[derive(Clone)]
pub struct Fixture {
pub ptr: *mut B2Fixture
}
impl Fixture {
pub fn get_type(&self) -> shape::Type {
unsafe {
b2Fixture_GetType(self.ptr)
}
}
pub fn get_shape(&self) -> *mut shape::B2Shape {
unsafe {
return b2Fixture_GetShape(self.ptr);
}
}
pub fn get_next(&self) -> Option<Fixture> {
let ptr: *mut B2Fixture;
unsafe {
ptr = b2Fixture_GetNext(self.ptr);
}
if ptr.is_null() {
None
} else {
Some(Fixture { ptr: ptr })
}
}
}