box3d_rust/recording/write_ops/
joint.rs1use crate::id::{JointId, WorldId};
8use crate::math_functions::Transform;
9use crate::types::{
10 DistanceJointDef, FilterJointDef, MotorJointDef, ParallelJointDef, PrismaticJointDef,
11 RevoluteJointDef, SphericalJointDef, WeldJointDef, WheelJointDef,
12};
13
14use crate::recording::ops::RecOp;
15use crate::recording::session::Recording;
16
17impl Recording {
18 pub fn write_create_parallel_joint(
20 &mut self,
21 world: WorldId,
22 def: &ParallelJointDef,
23 ret_id: JointId,
24 ) {
25 self.begin_record(RecOp::CreateParallelJoint as u8);
26 self.buffer.append_world_id(world);
27 self.buffer.append_parallel_joint_def(def);
28 self.buffer.append_joint_id(ret_id);
29 self.end_record();
30 }
31
32 pub fn write_create_distance_joint(
34 &mut self,
35 world: WorldId,
36 def: &DistanceJointDef,
37 ret_id: JointId,
38 ) {
39 self.begin_record(RecOp::CreateDistanceJoint as u8);
40 self.buffer.append_world_id(world);
41 self.buffer.append_distance_joint_def(def);
42 self.buffer.append_joint_id(ret_id);
43 self.end_record();
44 }
45
46 pub fn write_create_filter_joint(
48 &mut self,
49 world: WorldId,
50 def: &FilterJointDef,
51 ret_id: JointId,
52 ) {
53 self.begin_record(RecOp::CreateFilterJoint as u8);
54 self.buffer.append_world_id(world);
55 self.buffer.append_filter_joint_def(def);
56 self.buffer.append_joint_id(ret_id);
57 self.end_record();
58 }
59
60 pub fn write_create_motor_joint(
62 &mut self,
63 world: WorldId,
64 def: &MotorJointDef,
65 ret_id: JointId,
66 ) {
67 self.begin_record(RecOp::CreateMotorJoint as u8);
68 self.buffer.append_world_id(world);
69 self.buffer.append_motor_joint_def(def);
70 self.buffer.append_joint_id(ret_id);
71 self.end_record();
72 }
73
74 pub fn write_create_prismatic_joint(
76 &mut self,
77 world: WorldId,
78 def: &PrismaticJointDef,
79 ret_id: JointId,
80 ) {
81 self.begin_record(RecOp::CreatePrismaticJoint as u8);
82 self.buffer.append_world_id(world);
83 self.buffer.append_prismatic_joint_def(def);
84 self.buffer.append_joint_id(ret_id);
85 self.end_record();
86 }
87
88 pub fn write_create_revolute_joint(
90 &mut self,
91 world: WorldId,
92 def: &RevoluteJointDef,
93 ret_id: JointId,
94 ) {
95 self.begin_record(RecOp::CreateRevoluteJoint as u8);
96 self.buffer.append_world_id(world);
97 self.buffer.append_revolute_joint_def(def);
98 self.buffer.append_joint_id(ret_id);
99 self.end_record();
100 }
101
102 pub fn write_create_spherical_joint(
104 &mut self,
105 world: WorldId,
106 def: &SphericalJointDef,
107 ret_id: JointId,
108 ) {
109 self.begin_record(RecOp::CreateSphericalJoint as u8);
110 self.buffer.append_world_id(world);
111 self.buffer.append_spherical_joint_def(def);
112 self.buffer.append_joint_id(ret_id);
113 self.end_record();
114 }
115
116 pub fn write_create_weld_joint(&mut self, world: WorldId, def: &WeldJointDef, ret_id: JointId) {
118 self.begin_record(RecOp::CreateWeldJoint as u8);
119 self.buffer.append_world_id(world);
120 self.buffer.append_weld_joint_def(def);
121 self.buffer.append_joint_id(ret_id);
122 self.end_record();
123 }
124
125 pub fn write_create_wheel_joint(
127 &mut self,
128 world: WorldId,
129 def: &WheelJointDef,
130 ret_id: JointId,
131 ) {
132 self.begin_record(RecOp::CreateWheelJoint as u8);
133 self.buffer.append_world_id(world);
134 self.buffer.append_wheel_joint_def(def);
135 self.buffer.append_joint_id(ret_id);
136 self.end_record();
137 }
138
139 pub fn write_destroy_joint(&mut self, joint: JointId, wake_attached: bool) {
141 self.begin_record(RecOp::DestroyJoint as u8);
142 self.buffer.append_joint_id(joint);
143 self.buffer.append_bool(wake_attached);
144 self.end_record();
145 }
146
147 pub fn write_joint_set_local_frame_a(&mut self, joint: JointId, local_frame: Transform) {
149 self.begin_record(RecOp::JointSetLocalFrameA as u8);
150 self.buffer.append_joint_id(joint);
151 self.buffer.append_transform(local_frame);
152 self.end_record();
153 }
154
155 pub fn write_joint_set_local_frame_b(&mut self, joint: JointId, local_frame: Transform) {
157 self.begin_record(RecOp::JointSetLocalFrameB as u8);
158 self.buffer.append_joint_id(joint);
159 self.buffer.append_transform(local_frame);
160 self.end_record();
161 }
162
163 pub fn write_joint_set_collide_connected(&mut self, joint: JointId, should_collide: bool) {
165 self.begin_record(RecOp::JointSetCollideConnected as u8);
166 self.buffer.append_joint_id(joint);
167 self.buffer.append_bool(should_collide);
168 self.end_record();
169 }
170
171 pub fn write_joint_wake_bodies(&mut self, joint: JointId) {
173 self.begin_record(RecOp::JointWakeBodies as u8);
174 self.buffer.append_joint_id(joint);
175 self.end_record();
176 }
177
178 pub fn write_joint_set_constraint_tuning(
180 &mut self,
181 joint: JointId,
182 hertz: f32,
183 damping_ratio: f32,
184 ) {
185 self.begin_record(RecOp::JointSetConstraintTuning as u8);
186 self.buffer.append_joint_id(joint);
187 self.buffer.append_f32(hertz);
188 self.buffer.append_f32(damping_ratio);
189 self.end_record();
190 }
191
192 pub fn write_joint_set_force_threshold(&mut self, joint: JointId, threshold: f32) {
194 self.begin_record(RecOp::JointSetForceThreshold as u8);
195 self.buffer.append_joint_id(joint);
196 self.buffer.append_f32(threshold);
197 self.end_record();
198 }
199
200 pub fn write_joint_set_torque_threshold(&mut self, joint: JointId, threshold: f32) {
202 self.begin_record(RecOp::JointSetTorqueThreshold as u8);
203 self.buffer.append_joint_id(joint);
204 self.buffer.append_f32(threshold);
205 self.end_record();
206 }
207}