use nightshade::ecs::physics::joints::{
FixedJoint, JointAxisDirection, JointHandle, RevoluteJoint, RopeJoint, SpringJoint,
create_fixed_joint, create_revolute_joint, create_rope_joint, create_spring_joint,
};
use nightshade::prelude::*;
#[inline]
pub fn push(world: &mut World, entity: Entity, impulse: Vec3) {
physics_world_apply_impulse(&mut world.resources.physics, entity, impulse);
}
#[inline]
pub fn set_velocity(world: &mut World, entity: Entity, velocity: Vec3) {
physics_world_set_linear_velocity(&mut world.resources.physics, entity, velocity);
}
#[inline]
pub fn raycast(
world: &World,
origin: Vec3,
direction: Vec3,
max_distance: f32,
) -> Option<RaycastHit> {
physics_world_cast_ray(
&world.resources.physics,
origin,
direction,
max_distance,
None,
)
}
#[inline]
pub fn collisions(world: &World) -> &[CollisionEvent] {
physics_world_collision_events(&world.resources.physics)
}
#[inline]
pub fn attach_fixed(world: &mut World, parent: Entity, child: Entity) -> Option<JointHandle> {
create_fixed_joint(world, parent, child, FixedJoint::new())
}
#[inline]
pub fn attach_hinge(
world: &mut World,
parent: Entity,
child: Entity,
axis: JointAxisDirection,
) -> Option<JointHandle> {
create_revolute_joint(world, parent, child, RevoluteJoint::new(axis))
}
#[inline]
pub fn attach_spring(
world: &mut World,
parent: Entity,
child: Entity,
rest_length: f32,
stiffness: f32,
damping: f32,
) -> Option<JointHandle> {
create_spring_joint(
world,
parent,
child,
SpringJoint::new(rest_length, stiffness, damping),
)
}
#[inline]
pub fn attach_rope(
world: &mut World,
parent: Entity,
child: Entity,
max_distance: f32,
) -> Option<JointHandle> {
create_rope_joint(world, parent, child, RopeJoint::new(max_distance))
}
#[inline]
pub fn apply_force(world: &mut World, entity: Entity, force: Vec3) {
physics_world_apply_force(&mut world.resources.physics, entity, force);
}
#[inline]
pub fn apply_torque(world: &mut World, entity: Entity, torque: Vec3) {
physics_world_apply_torque(&mut world.resources.physics, entity, torque);
}
#[inline]
pub fn set_angular_velocity(world: &mut World, entity: Entity, velocity: Vec3) {
physics_world_set_angular_velocity(&mut world.resources.physics, entity, velocity);
}
#[inline]
pub fn velocity(world: &World, entity: Entity) -> Option<Vec3> {
physics_world_linear_velocity(&world.resources.physics, entity)
}
#[inline]
pub fn angular_velocity(world: &World, entity: Entity) -> Option<Vec3> {
physics_world_angular_velocity(&world.resources.physics, entity)
}
#[inline]
pub fn overlap_sphere(world: &World, center: Vec3, radius: f32) -> Vec<Entity> {
physics_world_overlap_sphere(&world.resources.physics, center, radius, None)
}
pub fn spawn_cylinder_body(
world: &mut World,
position: Vec3,
half_height: f32,
radius: f32,
mass: f32,
color: [f32; 4],
) -> Entity {
let material = nightshade::ecs::material::components::Material {
base_color: color,
..Default::default()
};
nightshade::ecs::physics::commands::spawn_dynamic_physics_cylinder_with_material(
world,
position,
half_height,
radius,
mass,
material,
)
}
pub fn set_friction(world: &mut World, entity: Entity, friction: f32) {
if let Some(collider) = world.core.get_collider_mut(entity) {
collider.friction = friction;
}
physics_world_set_friction(&mut world.resources.physics, entity, friction);
}
pub fn set_restitution(world: &mut World, entity: Entity, restitution: f32) {
if let Some(collider) = world.core.get_collider_mut(entity) {
collider.restitution = restitution;
}
physics_world_set_restitution(&mut world.resources.physics, entity, restitution);
}
pub fn set_linear_damping(world: &mut World, entity: Entity, damping: f32) {
if let Some(body) = world.core.get_rigid_body_mut(entity) {
body.linear_damping = damping;
}
physics_world_set_linear_damping(&mut world.resources.physics, entity, damping);
}
pub fn set_angular_damping(world: &mut World, entity: Entity, damping: f32) {
if let Some(body) = world.core.get_rigid_body_mut(entity) {
body.angular_damping = damping;
}
physics_world_set_angular_damping(&mut world.resources.physics, entity, damping);
}
pub fn set_mass(world: &mut World, entity: Entity, mass: f32) {
if let Some(body) = world.core.get_rigid_body_mut(entity) {
body.mass = mass;
}
physics_world_set_additional_mass(&mut world.resources.physics, entity, mass);
}
pub fn set_gravity_scale(world: &mut World, entity: Entity, scale: f32) {
if let Some(body) = world.core.get_rigid_body_mut(entity) {
body.gravity_scale = scale;
}
physics_world_set_gravity_scale(&mut world.resources.physics, entity, scale);
}
pub fn make_sensor(world: &mut World, entity: Entity) {
if let Some(collider) = world.core.get_collider_mut(entity) {
collider.is_sensor = true;
}
}
pub fn set_collision_groups(world: &mut World, entity: Entity, membership: u32, filter: u32) {
if let Some(collider) = world.core.get_collider_mut(entity) {
collider.collision_groups =
nightshade::ecs::physics::types::InteractionGroups::new(membership, filter);
}
}