1extern "C" {
10 fn bodydef_type() -> i32;
11 fn bodydef_set_type(slf: i64, body_type: i32);
12 fn bodydef_get_type(slf: i64) -> i32;
13 fn bodydef_set_position(slf: i64, val: i64);
14 fn bodydef_get_position(slf: i64) -> i64;
15 fn bodydef_set_angle(slf: i64, val: f32);
16 fn bodydef_get_angle(slf: i64) -> f32;
17 fn bodydef_set_face(slf: i64, val: i64);
18 fn bodydef_get_face(slf: i64) -> i64;
19 fn bodydef_set_face_pos(slf: i64, val: i64);
20 fn bodydef_get_face_pos(slf: i64) -> i64;
21 fn bodydef_set_linear_damping(slf: i64, val: f32);
22 fn bodydef_get_linear_damping(slf: i64) -> f32;
23 fn bodydef_set_angular_damping(slf: i64, val: f32);
24 fn bodydef_get_angular_damping(slf: i64) -> f32;
25 fn bodydef_set_linear_acceleration(slf: i64, val: i64);
26 fn bodydef_get_linear_acceleration(slf: i64) -> i64;
27 fn bodydef_set_fixed_rotation(slf: i64, val: i32);
28 fn bodydef_is_fixed_rotation(slf: i64) -> i32;
29 fn bodydef_set_bullet(slf: i64, val: i32);
30 fn bodydef_is_bullet(slf: i64) -> i32;
31 fn bodydef_polygon_with_center(center: i64, width: f32, height: f32, angle: f32, density: f32, friction: f32, restitution: f32) -> i64;
32 fn bodydef_polygon(width: f32, height: f32, density: f32, friction: f32, restitution: f32) -> i64;
33 fn bodydef_polygon_with_vertices(vertices: i64, density: f32, friction: f32, restitution: f32) -> i64;
34 fn bodydef_attach_polygon_with_center(slf: i64, center: i64, width: f32, height: f32, angle: f32, density: f32, friction: f32, restitution: f32);
35 fn bodydef_attach_polygon(slf: i64, width: f32, height: f32, density: f32, friction: f32, restitution: f32);
36 fn bodydef_attach_polygon_with_vertices(slf: i64, vertices: i64, density: f32, friction: f32, restitution: f32);
37 fn bodydef_multi(vertices: i64, density: f32, friction: f32, restitution: f32) -> i64;
38 fn bodydef_attach_multi(slf: i64, vertices: i64, density: f32, friction: f32, restitution: f32);
39 fn bodydef_disk_with_center(center: i64, radius: f32, density: f32, friction: f32, restitution: f32) -> i64;
40 fn bodydef_disk(radius: f32, density: f32, friction: f32, restitution: f32) -> i64;
41 fn bodydef_attach_disk_with_center(slf: i64, center: i64, radius: f32, density: f32, friction: f32, restitution: f32);
42 fn bodydef_attach_disk(slf: i64, radius: f32, density: f32, friction: f32, restitution: f32);
43 fn bodydef_chain(vertices: i64, friction: f32, restitution: f32) -> i64;
44 fn bodydef_attach_chain(slf: i64, vertices: i64, friction: f32, restitution: f32);
45 fn bodydef_attach_polygon_sensor(slf: i64, tag: i32, width: f32, height: f32);
46 fn bodydef_attach_polygon_sensor_with_center(slf: i64, tag: i32, center: i64, width: f32, height: f32, angle: f32);
47 fn bodydef_attach_polygon_sensor_with_vertices(slf: i64, tag: i32, vertices: i64);
48 fn bodydef_attach_disk_sensor_with_center(slf: i64, tag: i32, center: i64, radius: f32);
49 fn bodydef_attach_disk_sensor(slf: i64, tag: i32, radius: f32);
50 fn bodydef_new() -> i64;
51}
52use crate::dora::IObject;
53pub struct BodyDef { raw: i64 }
55crate::dora_object!(BodyDef);
56impl BodyDef {
57 pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
58 (unsafe { bodydef_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
59 match raw {
60 0 => None,
61 _ => Some(Box::new(BodyDef { raw: raw }))
62 }
63 })
64 }
65 pub fn set_type(&mut self, body_type: crate::dora::BodyType) {
71 unsafe { bodydef_set_type(self.raw(), body_type as i32); }
72 }
73 pub fn get_type(&self) -> crate::dora::BodyType {
79 unsafe { return core::mem::transmute(bodydef_get_type(self.raw())); }
80 }
81 pub fn set_position(&mut self, val: &crate::dora::Vec2) {
83 unsafe { bodydef_set_position(self.raw(), val.into_i64()) };
84 }
85 pub fn get_position(&self) -> crate::dora::Vec2 {
87 return unsafe { crate::dora::Vec2::from(bodydef_get_position(self.raw())) };
88 }
89 pub fn set_angle(&mut self, val: f32) {
91 unsafe { bodydef_set_angle(self.raw(), val) };
92 }
93 pub fn get_angle(&self) -> f32 {
95 return unsafe { bodydef_get_angle(self.raw()) };
96 }
97 pub fn set_face(&mut self, val: &str) {
99 unsafe { bodydef_set_face(self.raw(), crate::dora::from_string(val)) };
100 }
101 pub fn get_face(&self) -> String {
103 return unsafe { crate::dora::to_string(bodydef_get_face(self.raw())) };
104 }
105 pub fn set_face_pos(&mut self, val: &crate::dora::Vec2) {
107 unsafe { bodydef_set_face_pos(self.raw(), val.into_i64()) };
108 }
109 pub fn get_face_pos(&self) -> crate::dora::Vec2 {
111 return unsafe { crate::dora::Vec2::from(bodydef_get_face_pos(self.raw())) };
112 }
113 pub fn set_linear_damping(&mut self, val: f32) {
115 unsafe { bodydef_set_linear_damping(self.raw(), val) };
116 }
117 pub fn get_linear_damping(&self) -> f32 {
119 return unsafe { bodydef_get_linear_damping(self.raw()) };
120 }
121 pub fn set_angular_damping(&mut self, val: f32) {
123 unsafe { bodydef_set_angular_damping(self.raw(), val) };
124 }
125 pub fn get_angular_damping(&self) -> f32 {
127 return unsafe { bodydef_get_angular_damping(self.raw()) };
128 }
129 pub fn set_linear_acceleration(&mut self, val: &crate::dora::Vec2) {
131 unsafe { bodydef_set_linear_acceleration(self.raw(), val.into_i64()) };
132 }
133 pub fn get_linear_acceleration(&self) -> crate::dora::Vec2 {
135 return unsafe { crate::dora::Vec2::from(bodydef_get_linear_acceleration(self.raw())) };
136 }
137 pub fn set_fixed_rotation(&mut self, val: bool) {
139 unsafe { bodydef_set_fixed_rotation(self.raw(), if val { 1 } else { 0 }) };
140 }
141 pub fn is_fixed_rotation(&self) -> bool {
143 return unsafe { bodydef_is_fixed_rotation(self.raw()) != 0 };
144 }
145 pub fn set_bullet(&mut self, val: bool) {
148 unsafe { bodydef_set_bullet(self.raw(), if val { 1 } else { 0 }) };
149 }
150 pub fn is_bullet(&self) -> bool {
153 return unsafe { bodydef_is_bullet(self.raw()) != 0 };
154 }
155 pub fn polygon_with_center(center: &crate::dora::Vec2, width: f32, height: f32, angle: f32, density: f32, friction: f32, restitution: f32) -> crate::dora::FixtureDef {
167 unsafe { return crate::dora::FixtureDef::from(bodydef_polygon_with_center(center.into_i64(), width, height, angle, density, friction, restitution)).unwrap(); }
168 }
169 pub fn polygon(width: f32, height: f32, density: f32, friction: f32, restitution: f32) -> crate::dora::FixtureDef {
179 unsafe { return crate::dora::FixtureDef::from(bodydef_polygon(width, height, density, friction, restitution)).unwrap(); }
180 }
181 pub fn polygon_with_vertices(vertices: &Vec<crate::dora::Vec2>, density: f32, friction: f32, restitution: f32) -> crate::dora::FixtureDef {
190 unsafe { return crate::dora::FixtureDef::from(bodydef_polygon_with_vertices(crate::dora::Vector::from_vec2(vertices), density, friction, restitution)).unwrap(); }
191 }
192 pub fn attach_polygon_with_center(&mut self, center: &crate::dora::Vec2, width: f32, height: f32, angle: f32, density: f32, friction: f32, restitution: f32) {
204 unsafe { bodydef_attach_polygon_with_center(self.raw(), center.into_i64(), width, height, angle, density, friction, restitution); }
205 }
206 pub fn attach_polygon(&mut self, width: f32, height: f32, density: f32, friction: f32, restitution: f32) {
216 unsafe { bodydef_attach_polygon(self.raw(), width, height, density, friction, restitution); }
217 }
218 pub fn attach_polygon_with_vertices(&mut self, vertices: &Vec<crate::dora::Vec2>, density: f32, friction: f32, restitution: f32) {
227 unsafe { bodydef_attach_polygon_with_vertices(self.raw(), crate::dora::Vector::from_vec2(vertices), density, friction, restitution); }
228 }
229 pub fn multi(vertices: &Vec<crate::dora::Vec2>, density: f32, friction: f32, restitution: f32) -> crate::dora::FixtureDef {
242 unsafe { return crate::dora::FixtureDef::from(bodydef_multi(crate::dora::Vector::from_vec2(vertices), density, friction, restitution)).unwrap(); }
243 }
244 pub fn attach_multi(&mut self, vertices: &Vec<crate::dora::Vec2>, density: f32, friction: f32, restitution: f32) {
253 unsafe { bodydef_attach_multi(self.raw(), crate::dora::Vector::from_vec2(vertices), density, friction, restitution); }
254 }
255 pub fn disk_with_center(center: &crate::dora::Vec2, radius: f32, density: f32, friction: f32, restitution: f32) -> crate::dora::FixtureDef {
269 unsafe { return crate::dora::FixtureDef::from(bodydef_disk_with_center(center.into_i64(), radius, density, friction, restitution)).unwrap(); }
270 }
271 pub fn disk(radius: f32, density: f32, friction: f32, restitution: f32) -> crate::dora::FixtureDef {
284 unsafe { return crate::dora::FixtureDef::from(bodydef_disk(radius, density, friction, restitution)).unwrap(); }
285 }
286 pub fn attach_disk_with_center(&mut self, center: &crate::dora::Vec2, radius: f32, density: f32, friction: f32, restitution: f32) {
296 unsafe { bodydef_attach_disk_with_center(self.raw(), center.into_i64(), radius, density, friction, restitution); }
297 }
298 pub fn attach_disk(&mut self, radius: f32, density: f32, friction: f32, restitution: f32) {
307 unsafe { bodydef_attach_disk(self.raw(), radius, density, friction, restitution); }
308 }
309 pub fn chain(vertices: &Vec<crate::dora::Vec2>, friction: f32, restitution: f32) -> crate::dora::FixtureDef {
321 unsafe { return crate::dora::FixtureDef::from(bodydef_chain(crate::dora::Vector::from_vec2(vertices), friction, restitution)).unwrap(); }
322 }
323 pub fn attach_chain(&mut self, vertices: &Vec<crate::dora::Vec2>, friction: f32, restitution: f32) {
331 unsafe { bodydef_attach_chain(self.raw(), crate::dora::Vector::from_vec2(vertices), friction, restitution); }
332 }
333 pub fn attach_polygon_sensor(&mut self, tag: i32, width: f32, height: f32) {
341 unsafe { bodydef_attach_polygon_sensor(self.raw(), tag, width, height); }
342 }
343 pub fn attach_polygon_sensor_with_center(&mut self, tag: i32, center: &crate::dora::Vec2, width: f32, height: f32, angle: f32) {
353 unsafe { bodydef_attach_polygon_sensor_with_center(self.raw(), tag, center.into_i64(), width, height, angle); }
354 }
355 pub fn attach_polygon_sensor_with_vertices(&mut self, tag: i32, vertices: &Vec<crate::dora::Vec2>) {
362 unsafe { bodydef_attach_polygon_sensor_with_vertices(self.raw(), tag, crate::dora::Vector::from_vec2(vertices)); }
363 }
364 pub fn attach_disk_sensor_with_center(&mut self, tag: i32, center: &crate::dora::Vec2, radius: f32) {
372 unsafe { bodydef_attach_disk_sensor_with_center(self.raw(), tag, center.into_i64(), radius); }
373 }
374 pub fn attach_disk_sensor(&mut self, tag: i32, radius: f32) {
381 unsafe { bodydef_attach_disk_sensor(self.raw(), tag, radius); }
382 }
383 pub fn new() -> BodyDef {
389 unsafe { return BodyDef { raw: bodydef_new() }; }
390 }
391}