Struct bevy::math::cubic_splines::CubicCurve
pub struct CubicCurve<P>where
P: VectorSpace,{ /* private fields */ }
Expand description
A collection of CubicSegment
s chained into a single parametric curve. Has domain [0, N)
where N
is the number of attached segments.
Use any struct that implements the CubicGenerator
trait to create a new curve, such as
CubicBezier
.
Implementations§
§impl<P> CubicCurve<P>where
P: VectorSpace,
impl<P> CubicCurve<P>where
P: VectorSpace,
pub fn position(&self, t: f32) -> P
pub fn position(&self, t: f32) -> P
Compute the position of a point on the cubic curve at the parametric value t
.
Note that t
varies from 0..=(n_points - 3)
.
Examples found in repository?
99 100 101 102 103 104 105 106 107 108 109 110 111
fn animate_curve<T: CurveColor>(
time: Res<Time>,
mut query: Query<(&mut Transform, &mut Sprite, &Curve<T>)>,
) {
let t = (time.elapsed_seconds().sin() + 1.) / 2.;
for (mut transform, mut sprite, cubic_curve) in &mut query {
// position takes a point from the curve where 0 is the initial point
// and 1 is the last point
sprite.color = cubic_curve.0.position(t).into();
transform.translation.x = 600. * (t - 0.5);
}
}
More examples
pub fn velocity(&self, t: f32) -> P
pub fn velocity(&self, t: f32) -> P
Compute the first derivative with respect to t at t
. This is the instantaneous velocity of
a point on the cubic curve at t
.
Note that t
varies from 0..=(n_points - 3)
.
pub fn acceleration(&self, t: f32) -> P
pub fn acceleration(&self, t: f32) -> P
Compute the second derivative with respect to t at t
. This is the instantaneous
acceleration of a point on the cubic curve at t
.
Note that t
varies from 0..=(n_points - 3)
.
pub fn iter_samples<'a, 'b>(
&'b self,
subdivisions: usize,
sample_function: impl FnMut(&CubicCurve<P>, f32) -> P + 'a
) -> impl Iterator<Item = P> + 'awhere
'b: 'a,
pub fn iter_samples<'a, 'b>(
&'b self,
subdivisions: usize,
sample_function: impl FnMut(&CubicCurve<P>, f32) -> P + 'a
) -> impl Iterator<Item = P> + 'awhere
'b: 'a,
A flexible iterator used to sample curves with arbitrary functions.
This splits the curve into subdivisions
of evenly spaced t
values across the
length of the curve from start (t = 0) to end (t = n), where n = self.segment_count()
,
returning an iterator evaluating the curve with the supplied sample_function
at each t
.
For subdivisions = 2
, this will split the curve into two lines, or three points, and
return an iterator with 3 items, the three points, one at the start, middle, and end.
pub fn segments(&self) -> &[CubicSegment<P>]
pub fn segments(&self) -> &[CubicSegment<P>]
The list of segments contained in this CubicCurve
.
This spline’s global t
value is equal to how many segments it has.
All method accepting t
on CubicCurve
depends on the global t
.
When sampling over the entire curve, you should either use one of the
iter_*
methods or account for the segment count using curve.segments().len()
.
pub fn iter_positions(&self, subdivisions: usize) -> impl Iterator<Item = P>
pub fn iter_positions(&self, subdivisions: usize) -> impl Iterator<Item = P>
Iterate over the curve split into subdivisions
, sampling the position at each step.
pub fn iter_velocities(&self, subdivisions: usize) -> impl Iterator<Item = P>
pub fn iter_velocities(&self, subdivisions: usize) -> impl Iterator<Item = P>
Iterate over the curve split into subdivisions
, sampling the velocity at each step.
pub fn iter_accelerations(&self, subdivisions: usize) -> impl Iterator<Item = P>
pub fn iter_accelerations(&self, subdivisions: usize) -> impl Iterator<Item = P>
Iterate over the curve split into subdivisions
, sampling the acceleration at each step.
pub fn push_segment(&mut self, segment: CubicSegment<P>)
pub fn push_segment(&mut self, segment: CubicSegment<P>)
Adds a segment to the curve
Trait Implementations§
§impl<P> Clone for CubicCurve<P>where
P: Clone + VectorSpace,
impl<P> Clone for CubicCurve<P>where
P: Clone + VectorSpace,
§fn clone(&self) -> CubicCurve<P>
fn clone(&self) -> CubicCurve<P>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<P> Debug for CubicCurve<P>where
P: Debug + VectorSpace,
impl<P> Debug for CubicCurve<P>where
P: Debug + VectorSpace,
§impl<P> Extend<CubicSegment<P>> for CubicCurve<P>where
P: VectorSpace,
impl<P> Extend<CubicSegment<P>> for CubicCurve<P>where
P: VectorSpace,
§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = CubicSegment<P>>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = CubicSegment<P>>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)§impl<P> From<CubicCurve<P>> for RationalCurve<P>where
P: VectorSpace,
impl<P> From<CubicCurve<P>> for RationalCurve<P>where
P: VectorSpace,
§fn from(value: CubicCurve<P>) -> RationalCurve<P>
fn from(value: CubicCurve<P>) -> RationalCurve<P>
§impl<P> IntoIterator for CubicCurve<P>where
P: VectorSpace,
impl<P> IntoIterator for CubicCurve<P>where
P: VectorSpace,
§type IntoIter = <Vec<CubicSegment<P>> as IntoIterator>::IntoIter
type IntoIter = <Vec<CubicSegment<P>> as IntoIterator>::IntoIter
§type Item = CubicSegment<P>
type Item = CubicSegment<P>
§fn into_iter(self) -> <CubicCurve<P> as IntoIterator>::IntoIter
fn into_iter(self) -> <CubicCurve<P> as IntoIterator>::IntoIter
§impl<P> PartialEq for CubicCurve<P>where
P: PartialEq + VectorSpace,
impl<P> PartialEq for CubicCurve<P>where
P: PartialEq + VectorSpace,
§fn eq(&self, other: &CubicCurve<P>) -> bool
fn eq(&self, other: &CubicCurve<P>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<P> StructuralPartialEq for CubicCurve<P>where
P: VectorSpace,
Auto Trait Implementations§
impl<P> Freeze for CubicCurve<P>
impl<P> RefUnwindSafe for CubicCurve<P>where
P: RefUnwindSafe,
impl<P> Send for CubicCurve<P>where
P: Send,
impl<P> Sync for CubicCurve<P>where
P: Sync,
impl<P> Unpin for CubicCurve<P>where
P: Unpin,
impl<P> UnwindSafe for CubicCurve<P>where
P: UnwindSafe,
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more