bevy_transform_interpolation

Trait VelocitySource

source
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§

source

type Previous: Component

The component that stores the previous velocity.

This is not required for all easing backends, such as extrapolation. In such cases, this can be set to ().

source

type Current: Component

The component that stores the current velocity.

Required Methods§

source

fn previous(start: &Self::Previous) -> Vec3

Returns the previous velocity.

This is not required for all easing backends, such as extrapolation. In such cases, this can return Vec3::ZERO.

source

fn current(end: &Self::Current) -> Vec3

Returns the current velocity.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl VelocitySource for ()

source§

type Previous = DummyComponent

source§

type Current = DummyComponent

source§

fn previous(_: &Self::Previous) -> Vec3

source§

fn current(_: &Self::Current) -> Vec3

Implementors§