pub struct Physics {
pub compute_shader: ComputeShaderType,
pub collision_type: CollisionType,
pub mass: f32,
pub bounciness: f32,
pub friction: f32,
pub gravity_scale: f32,
pub linear_velocity: [f32; 3],
pub angular_velocity: [f32; 3],
}Expand description
Core physic definition that describe all possible cases in physic world.
Physic can be very lightweight and very heavy in same time, its based on
which physic shader you use ComputeShaderType
and what is your physic tickrate for example Minecraft has 20 tickrate
this engine is using 60 tickrate.
§Example
use rusting_engine::{ CollisionType, ComputeShaderType, Physics };
// Create floating cube that use maximal realistic shader
let floating_physic = &Physics::default()
.compute_shader(ComputeShaderType::FullPhysics) // FullPhysics has all possible physics cases as rotation, gravity, collisions, impulse and etc.
.mass(1.0) // equal to 1kg. More mass = more impulse when pushing other objects and etc.
.collision_type(CollisionType::Box) // Box collision
.gravity_scale(0.0); // Floating cube that is not pushed by gravity
// Create empty physic, no collision, no gravity, nothing, can be used to turn off physic or for debug
let empty_physic = &Physics::default()
.compute_shader(ComputeShaderType::Empty);Fields§
§compute_shader: ComputeShaderType§collision_type: CollisionType§mass: f32§bounciness: f32§friction: f32§gravity_scale: f32§linear_velocity: [f32; 3]§angular_velocity: [f32; 3]Implementations§
Source§impl Physics
impl Physics
Sourcepub fn bounciness(self, val: f32) -> Self
pub fn bounciness(self, val: f32) -> Self
Bounciness will describe how much speed object loses when bouncing.
0.0- No bounce (like a rock)0.5- Medium bounce (like a basketball)1.0- Perfect bounce (never stops)
Note: Values outside 0.0-1.0 are clamped automatically.
Sourcepub fn friction(self, val: f32) -> Self
pub fn friction(self, val: f32) -> Self
Friction is used to describe how good can object slide on other object Range ( 0.0 - 1.0 )
Sourcepub fn gravity_scale(self, val: f32) -> Self
pub fn gravity_scale(self, val: f32) -> Self
Gravity scale describe how strong does object effected by gravity, if 1, the gravity power will be same as World Gravity.
Gravity = 0 => floating object
Gravity < 0 => object will be pushed in opposite direction
Sourcepub fn angular_velocity(self, val: [f32; 3]) -> Self
pub fn angular_velocity(self, val: [f32; 3]) -> Self
The speed of object rotating in radians per second.
§Example
// Rotate 180 degrees per second (π radians/sec)
let spinning = Physics::default()
.angular_velocity([3.14159, 0.0, 0.0]);Sourcepub fn linear_velocity(self, v: [f32; 3]) -> Self
pub fn linear_velocity(self, v: [f32; 3]) -> Self
The speed of object displace in some amount of time
Sourcepub fn mass(self, m: f32) -> Self
pub fn mass(self, m: f32) -> Self
With bigger mass, object can create bigger push impulse, object is more hard to displace.
So mass is treated as real world mass.
Sourcepub fn collision_type(self, c: CollisionType) -> Self
pub fn collision_type(self, c: CollisionType) -> Self
This will create invisible collision around object based on chosen shape.
This Function is using CollisionType
§Example
// Invisible Box collision
let box_collision_physic = &Physics::default()
.collision_type(CollisionType::Box);
// Invisible Sphere collision
let sphere_collision_physic = &Physics::default()
.collision_type(CollisionType::Sphere); Sourcepub fn compute_shader(self, c: ComputeShaderType) -> Self
pub fn compute_shader(self, c: ComputeShaderType) -> Self
Set shaders to describe how Object will interact with physical world.
Highly recommended to read about ComputeShaderType to choose right shader for right object and never lose performance or realism.
Trait Implementations§
impl Copy for Physics
Auto Trait Implementations§
impl Freeze for Physics
impl RefUnwindSafe for Physics
impl Send for Physics
impl Sync for Physics
impl Unpin for Physics
impl UnsafeUnpin for Physics
impl UnwindSafe for Physics
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.