Skip to content

Commit 03d9cff

Browse files
committed
Bind a couple simple functions used by our game
1 parent 75330c9 commit 03d9cff

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

crates/rolt/src/body_interface.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::marker::PhantomData;
22

3+
use glam::Quat;
34
use joltc_sys::*;
45

5-
use crate::{Body, BodyId, IntoJolt, IntoRolt, RVec3, Vec3};
6+
use crate::{Body, BodyId, IntoJolt, IntoRolt, ObjectLayer, RVec3, Vec3};
67

78
/// See also: Jolt's [`BodyInterface`](https://jrouwe.github.io/JoltPhysicsDocs/5.1.0/class_body_interface.html) class.
89
pub struct BodyInterface<'physics_system> {
@@ -44,6 +45,24 @@ impl<'physics_system> BodyInterface<'physics_system> {
4445
unsafe { JPC_BodyInterface_DestroyBody(self.raw, body_id.raw()) }
4546
}
4647

48+
/// # Safety
49+
/// `shape` must be a valid shape.
50+
pub unsafe fn set_shape(
51+
&self,
52+
body_id: BodyId,
53+
shape: *const JPC_Shape,
54+
update_mass_properties: bool,
55+
activation: JPC_Activation,
56+
) {
57+
JPC_BodyInterface_SetShape(
58+
self.raw,
59+
body_id.raw(),
60+
shape,
61+
update_mass_properties,
62+
activation,
63+
)
64+
}
65+
4766
pub fn is_active(&self, body_id: BodyId) -> bool {
4867
unsafe { JPC_BodyInterface_IsActive(self.raw, body_id.raw()) }
4968
}
@@ -70,6 +89,46 @@ impl<'physics_system> BodyInterface<'physics_system> {
7089
}
7190
}
7291

92+
pub fn set_object_layer(&self, body_id: BodyId, object_layer: ObjectLayer) {
93+
unsafe { JPC_BodyInterface_SetObjectLayer(self.raw, body_id.raw(), object_layer.raw()) }
94+
}
95+
96+
pub fn notify_shape_changed(
97+
&self,
98+
body_id: BodyId,
99+
old_com: Vec3,
100+
update_mass_properties: bool,
101+
activation: JPC_Activation,
102+
) {
103+
unsafe {
104+
JPC_BodyInterface_NotifyShapeChanged(
105+
self.raw,
106+
body_id.raw(),
107+
old_com.into_jolt(),
108+
update_mass_properties,
109+
activation,
110+
)
111+
}
112+
}
113+
114+
pub fn set_position_and_rotation_when_changed(
115+
&self,
116+
body_id: BodyId,
117+
pos: RVec3,
118+
rot: Quat,
119+
activation: JPC_Activation,
120+
) {
121+
unsafe {
122+
JPC_BodyInterface_SetPositionAndRotationWhenChanged(
123+
self.raw,
124+
body_id.raw(),
125+
pos.into_jolt(),
126+
rot.into_jolt(),
127+
activation,
128+
)
129+
}
130+
}
131+
73132
pub fn as_raw(&self) -> *mut JPC_BodyInterface {
74133
self.raw
75134
}

crates/rolt/src/physics_system.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ impl PhysicsSystem {
8787
}
8888

8989
/// # Safety
90-
/// definitely not
90+
///
91+
/// `temp_allocator` and `job_system` must both be valid and live for the
92+
/// duration of this function.
9193
pub unsafe fn update(
9294
&self,
9395
delta_time: f32,
@@ -106,6 +108,22 @@ impl PhysicsSystem {
106108
}
107109
}
108110

111+
/// # Safety
112+
///
113+
/// `constraint` must be constraint for the duration of the call.
114+
/// This function will add a new ref to the constraint's refcount and keep
115+
/// it alive.
116+
pub unsafe fn add_constraint(&self, constraint: *mut JPC_Constraint) {
117+
unsafe { JPC_PhysicsSystem_AddConstraint(self.raw, constraint) }
118+
}
119+
120+
/// # Safety
121+
///
122+
/// `constraint` must be valid for the duration of the call.
123+
pub unsafe fn remove_constraint(&self, constraint: *mut JPC_Constraint) {
124+
unsafe { JPC_PhysicsSystem_RemoveConstraint(self.raw, constraint) }
125+
}
126+
109127
/// # Safety
110128
/// `renderer` must be valid and non-null.
111129
pub unsafe fn draw_bodies(

0 commit comments

Comments
 (0)