Struct WorldJointFrame

Source
pub struct WorldJointFrame {
    pub anchors: [Vec3; 2],
    pub axis: Vec3,
}
Expand description

World-space pivots and hinge axis, sampled against two live body poses.

anchors[0] belongs to body A, anchors[1] to body B. axis is a world direction (Vec3 in either dimension); hinges normalize/check it at use. Other joint kinds ignore it. No local frame rotation is stored: the existing solver uses local axes and a body-relative reference quaternion instead.

This 2D recipe attaches a rotated, translated rotor without initial snap. It uses the existing insertion path, then executes an ordinary fixed tick.

use ferravex_math::Vec2;
use ferravex_physics::d2::{
    ColliderBuilder, JointBuilder, JointPoseMode, PhysicsWorld,
    RigidBodyBuilder, WorldJointFrame,
};
let mut world = PhysicsWorld::default();
let support = world.insert_body(RigidBodyBuilder::fixed()
    .translation(Vec2::new(2., 3.)).rotation(0.4)).unwrap();
let (rotor, _) = world.insert(RigidBodyBuilder::dynamic()
    .translation(Vec2::new(4., 3.)).rotation(-0.7), ColliderBuilder::ball(0.2));
let joint = world.insert_joint_from_world(support, rotor,
    JointBuilder::hinge().limits(-0.5, 0.5),
    WorldJointFrame::at_pivot(Vec2::new(3., 3.)), JointPoseMode::Preserve).unwrap();
assert!(world.joint_angle(joint).unwrap().abs() < 0.00001);
world.step(1. / 120.);
assert!((world.bodies[rotor].translation() - Vec2::new(4., 3.)).length() < 0.0001);

In 3D, a visible world axis becomes two different local hinge axes. A distance/spring can instead use at_anchors with two separated pivots. Authored retains an intentional rest length; Preserve captures separation.

use ferravex_math::Vec3;
use ferravex_physics::{JointKind, d3::{
    ColliderBuilder, JointBuilder, JointPoseMode, PhysicsWorld,
    RigidBodyBuilder, WorldJointFrame,
}};
let mut world = PhysicsWorld::default();
let support = world.insert_body(RigidBodyBuilder::fixed()
    .translation(Vec3::new(2., 3., 1.)).rotation(Vec3::X * 0.6)).unwrap();
let (rotor, _) = world.insert(RigidBodyBuilder::dynamic()
    .translation(Vec3::new(4., 3., 1.)).rotation(Vec3::Z * -0.7),
    ColliderBuilder::ball(0.2));
let pivot = WorldJointFrame::at_pivot(Vec3::new(3., 3., 1.)).with_axis(Vec3::Y * 4.);
let desc = world.joint_desc_from_world(support, rotor, JointBuilder::hinge(),
    pivot, JointPoseMode::Preserve).unwrap();
let joint = world.insert_joint(support, rotor, desc).unwrap();
world.step(1. / 120.);
assert!((world.bodies[rotor].translation() - Vec3::new(4., 3., 1.)).length() < 0.0001);
assert!(world.remove_joint(joint));
let anchors = WorldJointFrame::at_anchors([Vec3::new(2., 3., 1.), Vec3::new(4., 3., 1.)]);
let spring = world.joint_desc_from_world(support, rotor, JointBuilder::spring(0., 20., 2.),
    anchors, JointPoseMode::Preserve).unwrap();
assert_eq!(spring.kind, JointKind::Spring { length: 2., stiffness: 20., damping: 2. });
world.insert_joint(support, rotor, spring).unwrap();

Fields§

§anchors: [Vec3; 2]§axis: Vec3

Implementations§

Source§

impl WorldJointFrame

Source

pub fn at_pivot(pivot: Vec3) -> WorldJointFrame

A shared pivot with the usual +Z (2D) or +Y (3D) world hinge axis. See this type’s examples; this only stores inputs, checked at use.

Source

pub fn at_anchors(anchors: [Vec3; 2]) -> WorldJointFrame

Two world pivots, normally used by distance/spring joints. See this type’s examples; validation occurs when sampled against bodies.

Source

pub fn with_axis(self, axis: Vec3) -> WorldJointFrame

Set an unnormalized world hinge axis; non-hinges ignore it. Zero/nonfinite axes fail at use. 2D requires normalized +Z. See this type’s 3D example.

Trait Implementations§

Source§

impl Clone for WorldJointFrame

Source§

fn clone(&self) -> WorldJointFrame

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WorldJointFrame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for WorldJointFrame

Source§

fn eq(&self, other: &WorldJointFrame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for WorldJointFrame

Source§

impl StructuralPartialEq for WorldJointFrame

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.