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: Vec3Implementations§
Source§impl WorldJointFrame
impl WorldJointFrame
Sourcepub fn at_pivot(pivot: Vec3) -> WorldJointFrame
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.
Sourcepub fn at_anchors(anchors: [Vec3; 2]) -> WorldJointFrame
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.
Sourcepub fn with_axis(self, axis: Vec3) -> WorldJointFrame
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
impl Clone for WorldJointFrame
Source§fn clone(&self) -> WorldJointFrame
fn clone(&self) -> WorldJointFrame
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more