Trait crystalorb::world::DisplayState [−][src]
pub trait DisplayState: Send + Sync + Clone + Debug { fn from_interpolation(state1: &Self, state2: &Self, t: f64) -> Self; }
Expand description
The DisplayState
represents the information about how to display the World
at
its current state. For example, while a World
might contain information about
player’s position and velocities, some games may only need to know about the position to render
it (unless you’re doing some fancy motion-blur). You can think of a DisplayState
as the
“output” of a World
. There is nothing stopping you from making the DisplayState
the same structure as the World
if it makes more sense for your game, but most of
the time, the World
structure may contain things that are inefficient to copy around
(e.g. an entire physics engine)
Required methods
fn from_interpolation(state1: &Self, state2: &Self, t: f64) -> Self
[src]
fn from_interpolation(state1: &Self, state2: &Self, t: f64) -> Self
[src]CrystalOrb needs to mix different DisplayState
s from different World
s
together, as well as mix DisplayState
from two adjacent timestamps. The
from_interpolation
method tells CrystalOrb how to
perform this “mix” operation. Here, the t
parameter is the interpolation parameter that
ranges between 0.0
and 1.0
, where t = 0.0
represents the request to have 100% of
state1
and 0% of state2
, and where t = 1.0
represents the request to have 0% of
state1
and 100% of state2
.
A common operation to implement this function is through linear interpolation, which looks like this:
state1 * (1.0 - t) + state2 * t
However, for things involving rotation, you may need to use spherical linear interpolation, or circular statistics, and perhaps you may need to convert between coordinate systems before/after performing the interpolation to get the right transformations about the correct pivot points.
Implementors
Interpolate between two timestamped display states. If the two timestamps are
different, then the interpolation parameter t
must be either 0.0
or 1.0
.
Panics
Panics if the timestamps are different but the interpolation parameter is not 0.0
nor
1.0
, since timestamps are whole number values and cannot be continuously
interpolated. Interpolating between two display states of different timestamps is known
as “tweening” (i.e. animation in-betweening) and should be done using
Tweened::from_interpolation
.