Skip to content

Commit

Permalink
add stub functions (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu authored Aug 15, 2024
1 parent f7d0381 commit aa9deba
Show file tree
Hide file tree
Showing 13 changed files with 1,025 additions and 13 deletions.
10 changes: 10 additions & 0 deletions src/bodies/rapier_collision_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl Default for CollisionObjectShape {
// TODO deserialize
#[cfg_attr(feature = "serde-serialize", derive(serde::Serialize))]
pub struct RapierCollisionObject {
user_flags: u32,
collision_object_type: CollisionObjectType,
#[cfg_attr(feature = "serde-serialize", serde(skip, default = "invalid_rid"))]
rid: Rid,
Expand Down Expand Up @@ -204,6 +205,7 @@ impl RapierCollisionObject {
.try_to()
.unwrap_or_default();
Self {
user_flags: 0,
collision_object_type,
rid,
instance_id: 0,
Expand Down Expand Up @@ -622,6 +624,14 @@ impl RapierCollisionObject {
self.body_handle = RigidBodyHandle::invalid();
}
}

pub fn set_user_flags(&mut self, p_flags: u32) {
self.user_flags = p_flags;
}

pub fn get_user_flags(&self) -> u32 {
self.user_flags
}
}
impl Drop for RapierCollisionObject {
fn drop(&mut self) {
Expand Down
6 changes: 6 additions & 0 deletions src/joints/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#[cfg(feature = "dim3")]
pub mod rapier_cone_twist_joint_3d;
#[cfg(feature = "dim2")]
pub mod rapier_damped_spring_joint_2d;
#[cfg(feature = "dim3")]
pub mod rapier_generic_6dof_joint_3d;
#[cfg(feature = "dim2")]
pub mod rapier_groove_joint_2d;
pub mod rapier_joint;
pub mod rapier_revolute_joint;
#[cfg(feature = "dim3")]
pub mod rapier_slider_joint_3d;
#[cfg(feature = "dim3")]
pub mod rapier_spherical_joint_3d;
157 changes: 157 additions & 0 deletions src/joints/rapier_cone_twist_joint_3d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
use godot::classes::*;
use godot::prelude::*;

use super::rapier_generic_6dof_joint_3d::RapierGeneric6DOFJoint3D;
use super::rapier_revolute_joint::RapierRevoluteJoint;
use super::rapier_slider_joint_3d::RapierSliderJoint3D;
use super::rapier_spherical_joint_3d::RapierSphericalJoint3D;
use crate::bodies::rapier_collision_object::IRapierCollisionObject;
use crate::joints::rapier_joint::IRapierJoint;
use crate::joints::rapier_joint::RapierJointBase;
use crate::rapier_wrapper::prelude::*;
#[cfg_attr(
feature = "serde-serialize",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct RapierConeTwistJoint3D {
anchor_a: Vector3,
anchor_b: Vector3,
base: RapierJointBase,
}
impl RapierConeTwistJoint3D {
pub fn new(
anchor_a: Vector3,
anchor_b: Vector3,
body_a: &Box<dyn IRapierCollisionObject>,
body_b: &Box<dyn IRapierCollisionObject>,
physics_engine: &mut PhysicsEngine,
) -> Self {
let invalid_joint = Self {
anchor_a,
anchor_b,
base: RapierJointBase::default(),
};
let body_a_rid = body_a.get_base().get_rid();
let body_b_rid = body_b.get_base().get_rid();
if body_a_rid == body_b_rid {
return invalid_joint;
}
if !body_a.get_base().is_valid()
|| !body_b.get_base().is_valid()
|| body_a.get_base().get_space_handle() != body_b.get_base().get_space_handle()
{
return invalid_joint;
}
let rapier_anchor_a = vector_to_rapier(anchor_a);
let rapier_anchor_b = vector_to_rapier(anchor_b);
let space_handle = body_a.get_base().get_space_handle();
let space_rid = body_a.get_base().get_space();
let handle = physics_engine.joint_create_spherical(
space_handle,
body_a.get_base().get_body_handle(),
body_b.get_base().get_body_handle(),
rapier_anchor_a,
rapier_anchor_b,
false,
false,
true,
);
Self {
anchor_a,
anchor_b,
base: RapierJointBase::new(space_handle, space_rid, handle),
}
}

pub fn set_anchor_a(&mut self, anchor_a: Vector3, physics_engine: &mut PhysicsEngine) {
self.anchor_a = anchor_a;
if !self.base.is_valid() {
return;
}
let anchor_a = vector_to_rapier(self.anchor_a);
let anchor_b = vector_to_rapier(self.anchor_a);
physics_engine.join_change_sperical_anchors(
self.base.get_space_handle(),
self.base.get_handle(),
anchor_a,
anchor_b,
);
}

pub fn set_anchor_b(&mut self, anchor_b: Vector3, physics_engine: &mut PhysicsEngine) {
self.anchor_b = anchor_b;
if !self.base.is_valid() {
return;
}
let anchor_a = vector_to_rapier(self.anchor_a);
let anchor_b = vector_to_rapier(self.anchor_a);
physics_engine.join_change_sperical_anchors(
self.base.get_space_handle(),
self.base.get_handle(),
anchor_a,
anchor_b,
);
}

pub fn get_anchor_a(&self) -> Vector3 {
self.anchor_a
}

pub fn get_anchor_b(&self) -> Vector3 {
self.anchor_b
}
}
#[cfg_attr(feature = "serde-serialize", typetag::serde)]
impl IRapierJoint for RapierConeTwistJoint3D {
fn get_base(&self) -> &RapierJointBase {
&self.base
}

fn get_mut_base(&mut self) -> &mut RapierJointBase {
&mut self.base
}

fn get_type(&self) -> physics_server_3d::JointType {
physics_server_3d::JointType::CONE_TWIST
}

fn get_spherical(&self) -> Option<&RapierSphericalJoint3D> {
None
}

fn get_cone_twist(&self) -> Option<&RapierConeTwistJoint3D> {
Some(self)
}

fn get_generic_6dof(&self) -> Option<&RapierGeneric6DOFJoint3D> {
None
}

fn get_slider(&self) -> Option<&RapierSliderJoint3D> {
None
}

fn get_revolute(&self) -> Option<&RapierRevoluteJoint> {
None
}

fn get_mut_spherical(&mut self) -> Option<&mut RapierSphericalJoint3D> {
None
}

fn get_mut_revolute(&mut self) -> Option<&mut RapierRevoluteJoint> {
None
}

fn get_mut_cone_twist(&mut self) -> Option<&mut RapierConeTwistJoint3D> {
Some(self)
}

fn get_mut_generic_6dof(&mut self) -> Option<&mut RapierGeneric6DOFJoint3D> {
None
}

fn get_mut_slider(&mut self) -> Option<&mut RapierSliderJoint3D> {
None
}
}
157 changes: 157 additions & 0 deletions src/joints/rapier_generic_6dof_joint_3d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
use godot::classes::*;
use godot::prelude::*;

use super::rapier_cone_twist_joint_3d::RapierConeTwistJoint3D;
use super::rapier_revolute_joint::RapierRevoluteJoint;
use super::rapier_slider_joint_3d::RapierSliderJoint3D;
use super::rapier_spherical_joint_3d::RapierSphericalJoint3D;
use crate::bodies::rapier_collision_object::IRapierCollisionObject;
use crate::joints::rapier_joint::IRapierJoint;
use crate::joints::rapier_joint::RapierJointBase;
use crate::rapier_wrapper::prelude::*;
#[cfg_attr(
feature = "serde-serialize",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct RapierGeneric6DOFJoint3D {
anchor_a: Vector3,
anchor_b: Vector3,
base: RapierJointBase,
}
impl RapierGeneric6DOFJoint3D {
pub fn new(
anchor_a: Vector3,
anchor_b: Vector3,
body_a: &Box<dyn IRapierCollisionObject>,
body_b: &Box<dyn IRapierCollisionObject>,
physics_engine: &mut PhysicsEngine,
) -> Self {
let invalid_joint = Self {
anchor_a,
anchor_b,
base: RapierJointBase::default(),
};
let body_a_rid = body_a.get_base().get_rid();
let body_b_rid = body_b.get_base().get_rid();
if body_a_rid == body_b_rid {
return invalid_joint;
}
if !body_a.get_base().is_valid()
|| !body_b.get_base().is_valid()
|| body_a.get_base().get_space_handle() != body_b.get_base().get_space_handle()
{
return invalid_joint;
}
let rapier_anchor_a = vector_to_rapier(anchor_a);
let rapier_anchor_b = vector_to_rapier(anchor_b);
let space_handle = body_a.get_base().get_space_handle();
let space_rid = body_a.get_base().get_space();
let handle = physics_engine.joint_create_spherical(
space_handle,
body_a.get_base().get_body_handle(),
body_b.get_base().get_body_handle(),
rapier_anchor_a,
rapier_anchor_b,
false,
false,
true,
);
Self {
anchor_a,
anchor_b,
base: RapierJointBase::new(space_handle, space_rid, handle),
}
}

pub fn set_anchor_a(&mut self, anchor_a: Vector3, physics_engine: &mut PhysicsEngine) {
self.anchor_a = anchor_a;
if !self.base.is_valid() {
return;
}
let anchor_a = vector_to_rapier(self.anchor_a);
let anchor_b = vector_to_rapier(self.anchor_a);
physics_engine.join_change_sperical_anchors(
self.base.get_space_handle(),
self.base.get_handle(),
anchor_a,
anchor_b,
);
}

pub fn set_anchor_b(&mut self, anchor_b: Vector3, physics_engine: &mut PhysicsEngine) {
self.anchor_b = anchor_b;
if !self.base.is_valid() {
return;
}
let anchor_a = vector_to_rapier(self.anchor_a);
let anchor_b = vector_to_rapier(self.anchor_a);
physics_engine.join_change_sperical_anchors(
self.base.get_space_handle(),
self.base.get_handle(),
anchor_a,
anchor_b,
);
}

pub fn get_anchor_a(&self) -> Vector3 {
self.anchor_a
}

pub fn get_anchor_b(&self) -> Vector3 {
self.anchor_b
}
}
#[cfg_attr(feature = "serde-serialize", typetag::serde)]
impl IRapierJoint for RapierGeneric6DOFJoint3D {
fn get_base(&self) -> &RapierJointBase {
&self.base
}

fn get_mut_base(&mut self) -> &mut RapierJointBase {
&mut self.base
}

fn get_type(&self) -> physics_server_3d::JointType {
physics_server_3d::JointType::TYPE_6DOF
}

fn get_spherical(&self) -> Option<&RapierSphericalJoint3D> {
None
}

fn get_cone_twist(&self) -> Option<&RapierConeTwistJoint3D> {
None
}

fn get_generic_6dof(&self) -> Option<&RapierGeneric6DOFJoint3D> {
Some(self)
}

fn get_slider(&self) -> Option<&RapierSliderJoint3D> {
None
}

fn get_revolute(&self) -> Option<&RapierRevoluteJoint> {
None
}

fn get_mut_spherical(&mut self) -> Option<&mut RapierSphericalJoint3D> {
None
}

fn get_mut_revolute(&mut self) -> Option<&mut RapierRevoluteJoint> {
None
}

fn get_mut_cone_twist(&mut self) -> Option<&mut RapierConeTwistJoint3D> {
None
}

fn get_mut_generic_6dof(&mut self) -> Option<&mut RapierGeneric6DOFJoint3D> {
Some(self)
}

fn get_mut_slider(&mut self) -> Option<&mut RapierSliderJoint3D> {
None
}
}
Loading

0 comments on commit aa9deba

Please sign in to comment.