Skip to content

Commit 38a7db4

Browse files
not-fl3fedor
authored and
fedor
committed
Changed destructors according to rust-lang/rust-bindgen#1133
1 parent e531fbc commit 38a7db4

File tree

6 files changed

+87
-12
lines changed

6 files changed

+87
-12
lines changed

bulletrs-sys/src/bt_bullet_dynamics_common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15507,7 +15507,7 @@ extern "C" {
1550715507
) -> *mut btPersistentManifold;
1550815508
}
1550915509
extern "C" {
15510-
#[link_name = "\u{1}_ZN21btCollisionDispatcherD0Ev"]
15510+
#[link_name = "\u{1}_ZN21btCollisionDispatcherD1Ev"]
1551115511
pub fn btCollisionDispatcher_btCollisionDispatcher_destructor(this: *mut btCollisionDispatcher);
1551215512
}
1551315513
extern "C" {
@@ -32174,7 +32174,7 @@ impl btDbvtBroadphase {
3217432174
}
3217532175
}
3217632176
extern "C" {
32177-
#[link_name = "\u{1}_ZN16btDbvtBroadphaseD0Ev"]
32177+
#[link_name = "\u{1}_ZN16btDbvtBroadphaseD1Ev"]
3217832178
pub fn btDbvtBroadphase_btDbvtBroadphase_destructor(this: *mut btDbvtBroadphase);
3217932179
}
3218032180
extern "C" {
@@ -37709,7 +37709,7 @@ impl btRigidBody {
3770937709
}
3771037710
}
3771137711
extern "C" {
37712-
#[link_name = "\u{1}_ZN11btRigidBodyD0Ev"]
37712+
#[link_name = "\u{1}_ZN11btRigidBodyD1Ev"]
3771337713
pub fn btRigidBody_btRigidBody_destructor(this: *mut btRigidBody);
3771437714
}
3771537715
extern "C" {
@@ -53755,7 +53755,7 @@ extern "C" {
5375553755
) -> btScalar;
5375653756
}
5375753757
extern "C" {
53758-
#[link_name = "\u{1}_ZN35btSequentialImpulseConstraintSolverD0Ev"]
53758+
#[link_name = "\u{1}_ZN35btSequentialImpulseConstraintSolverD1Ev"]
5375953759
pub fn btSequentialImpulseConstraintSolver_btSequentialImpulseConstraintSolver_destructor(
5376053760
this: *mut btSequentialImpulseConstraintSolver,
5376153761
);

examples/sphere.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ fn main() {
4343

4444
for _ in 0 .. 100 {
4545
dynamics_world.step(0.1, 0, 0.0);
46-
println!("{:?}", fall_rigid_body.get_world_transform());
46+
println!("{:?}", fall_rigid_body.get_world_position_and_orientation());
4747
}
4848
}

src/collision/broadphase_collision/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub enum BroadphaseInterface {
88
}
99

1010
pub enum Broadphase {
11-
DbvtBroadphase(Box<::sys::btDbvtBroadphase>),
11+
DbvtBroadphase(Box<sys::btDbvtBroadphase>),
1212
}
1313

1414
impl Broadphase {
@@ -33,7 +33,8 @@ impl Drop for Broadphase {
3333
fn drop(&mut self) {
3434
match self {
3535
&mut Broadphase::DbvtBroadphase(ref mut broadphase) => unsafe {
36-
::sys::btDbvtBroadphase_btDbvtBroadphase_destructor(&mut **broadphase as *mut _)
36+
let broadphase : &mut sys::btDbvtBroadphase = &mut **broadphase;
37+
::sys::btDbvtBroadphase_btDbvtBroadphase_destructor(broadphase as *mut _);
3738
},
3839
}
3940
}

src/dynamics/rigid_body.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,20 @@ impl RigidBody {
5656
&*self.rigid_body as *const _ as *mut _
5757
}
5858

59-
pub fn set_restitution(&self, restitution : f64) {
60-
unsafe { sys::btCollisionObject_setRestitution(self.as_ptr() as *mut _, restitution); }
59+
pub fn set_restitution(&self, restitution: f64) {
60+
unsafe {
61+
sys::btCollisionObject_setRestitution(self.as_ptr() as *mut _, restitution);
62+
}
6163
}
6264

63-
pub fn get_world_transform(&self) -> Vector3<f64> {
65+
pub fn set_gravity<T: Into<Vector3<f64>>>(&self, gravity: T) {
66+
let gravity: BulletVector3 = gravity.into().into();
67+
unsafe {
68+
sys::btRigidBody_setGravity(self.as_ptr() as *mut _, gravity.0.as_ptr() as *const _);
69+
}
70+
}
71+
72+
pub fn get_world_position_and_orientation(&self) -> (Vector3<f64>, Vector4<f64>) {
6473
unsafe {
6574
sys::btDefaultMotionState_getWorldTransform(
6675
&*self.motion_state as *const _ as *mut _,
@@ -69,6 +78,11 @@ impl RigidBody {
6978
}
7079
let origin = unsafe { self.temp_transform.getOrigin1().as_ref().unwrap() };
7180

72-
Vector3::from_slice(&origin.m_floats[0..3])
81+
let rotation = unsafe { self.temp_transform.getRotation() };
82+
83+
(
84+
Vector3::from_slice(&origin.m_floats[0..3]),
85+
Vector4::from_slice(&rotation._base.m_floats),
86+
)
7387
}
7488
}

tests/bindgen.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ extern crate bulletrs;
33
use bulletrs::sys as bt;
44

55
#[test]
6-
fn bindged_generated_test() {
6+
fn broadphase_destcutor() {
7+
unsafe {
8+
let mut broadphase = bt::btDbvtBroadphase::new(std::ptr::null_mut());
9+
bt::btDbvtBroadphase_btDbvtBroadphase_destructor(&mut broadphase as *mut _);
10+
}
11+
}
12+
#[test]
13+
fn bindgen_generated_test() {
714
unsafe {
815
let mut broadphase = bt::btDbvtBroadphase::new(std::ptr::null_mut());
916
let info = bt::btDefaultCollisionConstructionInfo::new();

tests/gravity.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
extern crate bulletrs;
2+
extern crate cgmath;
3+
4+
use cgmath::{Vector3, Vector4};
5+
6+
use bulletrs::*;
7+
8+
#[test()]
9+
fn set_gravity() {
10+
let configuration = CollisionConfiguration::new_default();
11+
12+
let dynamics_world = DynamicsWorld::new_discrete_world(
13+
CollisionDispatcher::new(&configuration),
14+
Broadphase::new(BroadphaseInterface::DbvtBroadphase),
15+
ConstraintSolver::new(),
16+
configuration,
17+
);
18+
19+
dynamics_world.set_gravity(Vector3::new(0.0, -10.0, 0.0));
20+
21+
let shape = Shape::new_sphere(2.0);
22+
let mass = 0.1;
23+
let body1 = RigidBody::new(
24+
mass,
25+
shape.calculate_local_inertia(mass),
26+
shape,
27+
Vector3::new(4.0, 2.0, 0.0),
28+
Vector4::new(0.0, 0.0, 0.0, 1.0),
29+
);
30+
dynamics_world.add_rigid_body(&body1);
31+
32+
let shape2 = Shape::new_sphere(2.0);
33+
let mass = 0.1;
34+
let body2 = RigidBody::new(
35+
mass,
36+
shape2.calculate_local_inertia(mass),
37+
shape2,
38+
Vector3::new(0.0, 2.0, 0.0),
39+
Vector4::new(0.0, 0.0, 0.0, 1.0),
40+
);
41+
dynamics_world.add_rigid_body(&body2);
42+
body2.set_gravity(Vector3::new(0.0, 0.0, 0.0));
43+
44+
for _ in 0 .. 10 {
45+
dynamics_world.step(0.1, 0, 0.0);
46+
}
47+
48+
let (position, _) = body1.get_world_position_and_orientation();
49+
assert!(position.y != 2.0);
50+
51+
let (position, _) = body2.get_world_position_and_orientation();
52+
assert_eq!(position.y, 2.0);
53+
}

0 commit comments

Comments
 (0)