Struct k::node::Node

source ·
pub struct Node<T: RealField>(_);
Expand description

Parts of Chain

It contains joint, joint (transform), and parent/children.

Implementations§

iter from the end to root, it contains nodes[id] itself

iter to the end, it contains nodes[id] itself

Set parent and child relations at same time

Remove parent and child relations at same time

Examples
use k::*;

let l0 = k::NodeBuilder::<f32>::new().into_node();
let l1 = k::NodeBuilder::new().into_node();
l1.set_parent(&l0);
assert!(l0.is_root());
assert!(!l1.is_root());
Examples
let l0 = k::NodeBuilder::<f64>::new().into_node();
let l1 = k::NodeBuilder::new().into_node();
l1.set_parent(&l0);
assert!(!l0.is_end());
assert!(l1.is_end());

Set the origin transform of the joint

Get the origin transform of the joint

Set the position (angle) of the joint

If position is out of limit, it returns Err.

Examples
use k::*;
let l0 = NodeBuilder::new()
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .limits(Some((0.0..=2.0).into()))
    .into_node();
assert!(l0.set_joint_position(1.0).is_ok());
assert!(l0.set_joint_position(-1.0).is_err());

Setting position for Fixed joint is error.

use k::*;
let l0 = NodeBuilder::new()
    .joint_type(JointType::Fixed)
    .into_node();
assert!(l0.set_joint_position(0.0).is_err());

k::joint::Mimic can be used to copy other joint’s position.

use k::*;
let j0 = NodeBuilder::new()
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .limits(Some((0.0..=2.0).into()))
    .into_node();
let j1 = NodeBuilder::new()
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .limits(Some((0.0..=2.0).into()))
    .into_node();
j1.set_mimic_parent(&j0, k::joint::Mimic::new(1.5, 0.1));
assert_eq!(j0.joint_position().unwrap(), 0.0);
assert_eq!(j1.joint_position().unwrap(), 0.0);
assert!(j0.set_joint_position(1.0).is_ok());
assert_eq!(j0.joint_position().unwrap(), 1.0);
assert_eq!(j1.joint_position().unwrap(), 1.6);

Set the clamped position (angle) of the joint

It refers to the joint limit and clamps the argument. This function does nothing if this is fixed joint.

Examples
use k::*;
let l0 = NodeBuilder::new()
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .limits(Some((-1.0..=1.0).into()))
    .into_node();
l0.set_joint_position_clamped(2.0);
assert_eq!(l0.joint().joint_position(), Some(1.0));
l0.set_joint_position_clamped(-2.0);
assert_eq!(l0.joint().joint_position(), Some(-1.0));

Get the calculated world transform. Call Chain::update_transforms() before using this method.

Examples
use k::*;
use k::prelude::*;

let l0 = NodeBuilder::new()
    .translation(Translation3::new(0.0, 0.0, 0.2))
    .joint_type(JointType::Rotational{axis: Vector3::y_axis()})
    .into_node();
let l1 = NodeBuilder::new()
    .translation(Translation3::new(0.0, 0.0, 1.0))
    .joint_type(JointType::Linear{axis: Vector3::z_axis()})
    .into_node();
l1.set_parent(&l0);
let tree = Chain::<f64>::from_root(l0);
tree.set_joint_positions(&vec![3.141592 * 0.5, 0.1]).unwrap();
assert!(l1.world_transform().is_none());
assert!(l1.world_transform().is_none());
let _poses = tree.update_transforms();
assert!((l1.world_transform().unwrap().translation.vector.x - 1.1).abs() < 0.0001);
assert!((l1.world_transform().unwrap().translation.vector.z - 0.2).abs() < 0.0001);

// _poses[0] is as same as l0.world_transform()
// _poses[1] is as same as l1.world_transform()

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more