pub trait VelocitySource:
QueryData
+ Send
+ Sync
+ 'static {
type Previous: Component;
type Current: Component;
// Required methods
fn previous(start: &Self::Previous) -> Vec3;
fn current(end: &Self::Current) -> Vec3;
}
Expand description
A QueryData
type for specifying the components that store velocity for easing.
Required for TransformExtrapolationPlugin
and TransformHermiteEasingPlugin
.
§Example
use bevy::{ecs::query::QueryData, prelude::*};
use bevy_transform_interpolation::VelocitySource;
// Velocity components
#[derive(Component)]
struct LinearVelocity(Vec3);
#[derive(Component)]
struct PreviousLinearVelocity(Vec3);
#[derive(Component)]
struct AngularVelocity(Vec3);
#[derive(Component)]
struct PreviousAngularVelocity(Vec3);
// Velocity source for easing that uses linear velocity
#[derive(QueryData)]
struct LinVelSource;
impl VelocitySource for LinVelSource {
type Previous = PreviousLinearVelocity;
type Current = LinearVelocity;
fn previous(previous: &Self::Previous) -> Vec3 {
previous.0
}
fn current(current: &Self::Current) -> Vec3 {
current.0
}
}
// Velocity source for easing that uses angular velocity
#[derive(QueryData)]
struct AngVelSource;
impl VelocitySource for AngVelSource {
type Previous = PreviousAngularVelocity;
type Current = AngularVelocity;
fn previous(previous: &Self::Previous) -> Vec3 {
previous.0
}
fn current(current: &Self::Current) -> Vec3 {
current.0
}
}
Some forms of easing such as extrapolation may not require the previous velocity.
In such cases, the Previous
component can be set to ()
, and previous
can simply return Vec3::ZERO
.
Required Associated Types§
Required Methods§
Object Safety§
This trait is not object safe.