Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional groove joint 2D implementation with DOF: 1 translation + 1 rotation #775

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

legendofa
Copy link
Contributor

Implements additional GrooveJoint from to issue: #772
The joint is currently only implemented for 2d behind the feature flag "dim2".

I tested this so far with this adjusted example, my plan is to implement a more elaborate example for more testing:

use rapier2d::prelude::*;
use rapier_testbed2d::Testbed;

pub fn init_world(testbed: &mut Testbed) {
    /*
     * World
     */
    let mut bodies = RigidBodySet::new();
    let mut colliders = ColliderSet::new();
    let mut impulse_joints = ImpulseJointSet::new();
    let multibody_joints = MultibodyJointSet::new();

    /*
     * Ground
     */
    let ground_size = 0.75;
    let ground_height = 0.1;

    let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height]);
    let floor_handle = bodies.insert(rigid_body);
    let collider = ColliderBuilder::cuboid(ground_size, ground_height);
    colliders.insert_with_parent(collider, floor_handle, &mut bodies);

    let rigid_body =
        RigidBodyBuilder::fixed().translation(vector![-ground_size - ground_height, ground_size]);
    let floor_handle = bodies.insert(rigid_body);
    let collider = ColliderBuilder::cuboid(ground_height, ground_size);
    colliders.insert_with_parent(collider, floor_handle, &mut bodies);

    let rigid_body =
        RigidBodyBuilder::fixed().translation(vector![ground_size + ground_height, ground_size]);
    let floor_handle = bodies.insert(rigid_body);
    let collider = ColliderBuilder::cuboid(ground_height, ground_size);
    colliders.insert_with_parent(collider, floor_handle, &mut bodies);

    /*
     * Character we will control manually.
     */
    let rigid_body = RigidBodyBuilder::kinematic_position_based().translation(vector![0.0, 0.3]);
    let character_handle = bodies.insert(rigid_body);
    let collider = ColliderBuilder::cuboid(0.15, 0.3);
    colliders.insert_with_parent(collider, character_handle, &mut bodies);

    /*
     * Tethered cube.
     */
    let rad = 0.04;

    let rigid_body = RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(vector![1.0, 1.0]);
    let child_handle = bodies.insert(rigid_body);
    let collider = ColliderBuilder::cuboid(rad, rad);
    colliders.insert_with_parent(collider, child_handle, &mut bodies);

    let axis = UnitVector::new_normalize(vector![1.0, 1.0]);
    let prismatic_joint = GrooveJointBuilder::new(axis)
        .local_anchor1(point![0.0, 0.0])
        .local_anchor2(point![0.0, 0.0])
        .build();
    impulse_joints.insert(character_handle, child_handle, prismatic_joint, true);

    /*
     * Set up the testbed.
     */
    testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
    testbed.set_character_body(character_handle);
    testbed.look_at(point![0.0, 1.0], 100.0);
}

If there is anything that i have overlooked, let me know :)
This is still a draft as i think this needs a bit more testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant