using GlitchyEngine.Core;
using GlitchyEngine.Math;
namespace GlitchyEngine.Physics;
///
/// Rigid body component for 2D physics.
///
public class Rigidbody2D : Component
{
///
/// Apply a force at a world point.
/// If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity.
/// This wakes up the body.
///
/// The world force vector, usually in Newtons (N).
/// The world position of the point of application.
/// Wake up the body
public void ApplyForce(float2 force, float2 point, bool wakeUp = true)
{
ScriptGlue.Rigidbody2D_ApplyForce(_uuid, force, point, wakeUp);
}
///
/// Apply a force to the center of mass.
/// This wakes up the body.
///
/// The world force vector, usually in Newtons (N).
/// Wake up the body
public void ApplyForceToCenter(float2 force, bool wakeUp = true)
{
ScriptGlue.Rigidbody2D_ApplyForceToCenter(_uuid, force, wakeUp);
}
///
/// Gets or sets the global position of the rigidbody.
///
public float2 Position
{
get
{
ScriptGlue.Rigidbody2D_GetPosition(_uuid, out float2 position);
return position;
}
set => ScriptGlue.Rigidbody2D_SetPosition(_uuid, value);
}
///
/// Gets or sets the global rotation of the rigidbody.
///
public float Rotation
{
get
{
ScriptGlue.Rigidbody2D_GetRotation(_uuid, out float rotation);
return rotation;
}
set => ScriptGlue.Rigidbody2D_SetRotation(_uuid, value);
}
///
/// Gets or sets the linear velocity of the rigidbody.
///
public float2 LinearVelocity
{
get
{
ScriptGlue.Rigidbody2D_GetLinearVelocity(_uuid, out float2 velocity);
return velocity;
}
set => ScriptGlue.Rigidbody2D_SetLinearVelocity(_uuid, value);
}
///
/// Gets or sets the angulara velocity of the rigidbody.
///
public float AngularVelocity
{
get
{
ScriptGlue.Rigidbody2D_GetAngularVelocity(_uuid, out float velocity);
return velocity;
}
set => ScriptGlue.Rigidbody2D_SetAngularVelocity(_uuid, value);
}
}