pub struct PhysicsStateV3<T: MyFloat> {}Expand description
Physics solver v3
§Overview (check Self::step for details)
Store simulation parameters (m,g)
Track the state of the particle (position, velocity, u(curve parameter))
Compute intermediate values like normal acceleration, and
delta_t(time step).
Determines cost based off of z direction (eyes down) g-forces measured at
the heart, and rate of rotation.
Fields§
§m: T§g: MyVector3<T>§o: T§rot_inertia: T§mu: T§i: u64§prev_u: T§u: T§x: ComPos<T>§v: ComVel<T>§hl_normal: MyVector3<T>§w: MyVector3<T>§additional_info: PhysicsAdditionalInfo<T>§cost: FptImplementations§
Source§impl<T: MyFloat> PhysicsStateV3<T>
impl<T: MyFloat> PhysicsStateV3<T>
pub fn m(&self) -> &T
pub fn g(&self) -> &MyVector3<T>
pub fn o(&self) -> &T
pub fn rot_inertia(&self) -> &T
pub fn mu(&self) -> &T
pub fn i(&self) -> &u64
pub fn prev_u(&self) -> &T
pub fn u(&self) -> &T
pub fn x(&self) -> &ComPos<T>
pub fn v(&self) -> &ComVel<T>
pub fn hl_normal(&self) -> &MyVector3<T>
pub fn w(&self) -> &MyVector3<T>
pub fn additional_info(&self) -> &PhysicsAdditionalInfo<T>
pub fn cost(&self) -> &Fpt
Source§impl<T: MyFloat> PhysicsStateV3<T>
impl<T: MyFloat> PhysicsStateV3<T>
Sourcepub fn new(m: Fpt, g_: Fpt, curve: &Spline<T>, o: Fpt, mu: Fpt) -> Self
pub fn new(m: Fpt, g_: Fpt, curve: &Spline<T>, o: Fpt, mu: Fpt) -> Self
Initialize the physics state: m mass, g Gravity vector,
curve.curve_at(0.0): Starting position of the curve at u=0
pub fn set_v(&mut self, v: &MyVector3<T>)
fn hl_normal_err_at_u_manual_pos( &self, u: &T, step: &T, curve: &Spline<T>, pos: &ComPos<T>, ) -> T
fn hl_normal_errs_at_u(&self, u: &T, curve: &Spline<T>, step: &T) -> (T, T)
pub fn determine_future_u_pos_norm_maxu_err( &self, step: &T, curve: &Spline<T>, ) -> Option<(T, ComPos<T>, MyVector3<T>, T, Fpt)>
Sourcepub fn step(&mut self, step: &T, curve: &Spline<T>) -> Option<()>
pub fn step(&mut self, step: &T, curve: &Spline<T>) -> Option<()>
Steps forward in time by step, may choose to perform smaller step(s)
§Implementation Details
The physics is based off semi-implicit euler integration, with corrective forces choosen to keep the position perfectly correct at all times (assuming such is possible while conserving energy).
The basic rule would be:
v_next = v_curr + a * dt
x_next = x_curr + v_next * dt
Acceleration would be from gravity and normal force. The normal force
can be expressed as a rotation of v_curr, this ensures F_N doesn’t
add any energy to the system.
Thus, we rewrite the update rules as:
v_next = rot(v_curr, R) + a * dt
x_next = x_curr + v_next * dt
Give a target x_tar, we subsitute x_next = x_tar:
x_tar = x_curr + v_next * dt
x_tar = x_curr + (rot(v_curr, R) + a * dt) * dt
x_tar = x_curr + rot(v_curr, R) * dt + a * dt^2
x_tar - (x_curr + a * dt^2) = rot(v_curr, R) * dt
From the “no velocity” position of x_curr + a * dt^2, adding velocity
forms a sphere with radius v_curr * dt. The intersection of this
sphere with a thick line of radius o about the curve is the domain of
future possible positions.
We search for where on this domain we most closely match an ideal hl-normal.
fn new_ang_vel(&self, step: &T, tgt_norm: &MyVector3<T>) -> MyVector3<T>
fn correct_v_to_reduce_energy_by( &self, change_in_angular_energy: T, vel_to_correct: &ComVel<T>, ) -> ComVel<T>
fn updated_v(&self, step: &T, target_pos: &ComPos<T>) -> ComVel<T>
pub fn next_hl_normal( &self, u: &T, curve: &Spline<T>, vel: &ComVel<T>, ) -> MyVector3<T>
pub fn future_pos_no_vel(&self, delta_t: &T, curr_pos: &ComPos<T>) -> ComPos<T>
pub fn possible_positions( &self, curve: &Spline<T>, delta_t: &T, u: &T, ) -> Option<[ComPos<T>; 2]>
fn energy(&self) -> T
pub fn kinetic_energy(&self) -> T
fn potential_energy(&self) -> T
pub fn rot_energy(&self, w_mag: T) -> T
pub fn description(&self) -> String
Trait Implementations§
Source§impl<T: Clone + MyFloat> Clone for PhysicsStateV3<T>
impl<T: Clone + MyFloat> Clone for PhysicsStateV3<T>
Source§fn clone(&self) -> PhysicsStateV3<T>
fn clone(&self) -> PhysicsStateV3<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T> Freeze for PhysicsStateV3<T>where
T: Freeze,
impl<T> RefUnwindSafe for PhysicsStateV3<T>where
T: RefUnwindSafe,
impl<T> Send for PhysicsStateV3<T>
impl<T> Sync for PhysicsStateV3<T>
impl<T> Unpin for PhysicsStateV3<T>where
T: Unpin,
impl<T> UnwindSafe for PhysicsStateV3<T>where
T: UnwindSafe,
Blanket Implementations§
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.