mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Renamed RigidBody2D to Rigidbody2D
+ Math.normalize(Quaternion) + Position and Rotation properties for Rigidbody2D + use In, Out on beef side in ScriptGlue
This commit is contained in:
@@ -544,6 +544,8 @@ static
|
||||
public static float3 normalize(float3 value) => value / length(value);
|
||||
public static float4 normalize(float4 value) => value / length(value);
|
||||
|
||||
public static Quaternion normalize(Quaternion value) => Quaternion.Normalize(value);
|
||||
|
||||
// pow
|
||||
|
||||
#region Reflect and Refract
|
||||
|
||||
@@ -213,7 +213,7 @@ static class ScriptGlue
|
||||
#region TransformComponent
|
||||
|
||||
[RegisterCall("ScriptGlue::Transform_GetTranslation")]
|
||||
static void Transform_GetTranslation(UUID entityId, ref float3 translation)
|
||||
static void Transform_GetTranslation(UUID entityId, out float3 translation)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
@@ -222,7 +222,7 @@ static class ScriptGlue
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::Transform_SetTranslation")]
|
||||
static void Transform_SetTranslation(UUID entityId, ref float3 translation)
|
||||
static void Transform_SetTranslation(UUID entityId, in float3 translation)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
@@ -238,10 +238,10 @@ static class ScriptGlue
|
||||
|
||||
#endregion TransformComponent
|
||||
|
||||
#region RigidBody2D
|
||||
#region Rigidbody2D
|
||||
|
||||
[RegisterCall("ScriptGlue::RigidBody2D_ApplyForce")]
|
||||
static void RigidBody2D_ApplyForce(UUID entityId, ref float2 force, ref float2 point, bool wakeUp)
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_ApplyForce")]
|
||||
static void Rigidbody2D_ApplyForce(UUID entityId, in float2 force, in float2 point, bool wakeUp)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
@@ -250,8 +250,8 @@ static class ScriptGlue
|
||||
Box2D.Body.ApplyForce(rigidBody.[Friend]RuntimeBody, force, point, wakeUp);
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::RigidBody2D_ApplyForceToCenter")]
|
||||
static void RigidBody2D_ApplyForceToCenter(UUID entityId, ref float2 force, bool wakeUp)
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_ApplyForceToCenter")]
|
||||
static void Rigidbody2D_ApplyForceToCenter(UUID entityId, in float2 force, bool wakeUp)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
@@ -260,8 +260,8 @@ static class ScriptGlue
|
||||
Box2D.Body.ApplyForceToCenter(rigidBody.[Friend]RuntimeBody, force, wakeUp);
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::RigidBody2D_SetPosition")]
|
||||
static void RigidBody2D_SetPosition(UUID entityId, ref float2 position)
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_SetPosition")]
|
||||
static void Rigidbody2D_SetPosition(UUID entityId, in float2 position)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
@@ -270,8 +270,8 @@ static class ScriptGlue
|
||||
rigidBody.SetPosition(position);
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::RigidBody2D_GetPosition")]
|
||||
static void RigidBody2D_GetPosition(UUID entityId, ref float2 position)
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_GetPosition")]
|
||||
static void Rigidbody2D_GetPosition(UUID entityId, out float2 position)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
@@ -280,14 +280,34 @@ static class ScriptGlue
|
||||
position = rigidBody.GetPosition();
|
||||
}
|
||||
|
||||
#endregion RigidBody2D
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_SetRotation")]
|
||||
static void Rigidbody2D_SetRotation(UUID entityId, in float rotation)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
|
||||
var rigidBody = entity.GetComponent<Rigidbody2DComponent>();
|
||||
rigidBody.SetAngle(rotation);
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::Rigidbody2D_GetRotation")]
|
||||
static void Rigidbody2D_GetRotation(UUID entityId, out float rotation)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
Entity entity = scene.GetEntityByID(entityId);
|
||||
|
||||
var rigidBody = entity.GetComponent<Rigidbody2DComponent>();
|
||||
rotation = rigidBody.GetAngle();
|
||||
}
|
||||
|
||||
#endregion Rigidbody2D
|
||||
|
||||
#region Physics2D
|
||||
|
||||
// TODO: We need a wrapper class!
|
||||
|
||||
[RegisterCall("ScriptGlue::Physics2D_GetGravity")]
|
||||
static void Physics2D_GetGravity(ref float2 gravity)
|
||||
static void Physics2D_GetGravity(out float2 gravity)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
|
||||
@@ -296,7 +316,7 @@ static class ScriptGlue
|
||||
}
|
||||
|
||||
[RegisterCall("ScriptGlue::Physics2D_SetGravity")]
|
||||
static void Physics2D_SetGravity(ref float2 gravity)
|
||||
static void Physics2D_SetGravity(in float2 gravity)
|
||||
{
|
||||
Scene scene = ScriptEngine.Context;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Rigidbody2D : Component
|
||||
/// <param name="wakeUp">Wake up the body</param>
|
||||
public void ApplyForce(float2 force, float2 point, bool wakeUp = true)
|
||||
{
|
||||
ScriptGlue.RigidBody2D_ApplyForce(Entity._uuid, force, point, wakeUp);
|
||||
ScriptGlue.Rigidbody2D_ApplyForce(Entity._uuid, force, point, wakeUp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -25,22 +25,34 @@ public class Rigidbody2D : Component
|
||||
/// <param name="wakeUp">Wake up the body</param>
|
||||
public void ApplyForceToCenter(float2 force, bool wakeUp = true)
|
||||
{
|
||||
ScriptGlue.RigidBody2D_ApplyForceToCenter(Entity._uuid, force, wakeUp);
|
||||
ScriptGlue.Rigidbody2D_ApplyForceToCenter(Entity._uuid, force, wakeUp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the position of the rigidbody.
|
||||
/// Gets or sets the global position of the rigidbody.
|
||||
/// </summary>
|
||||
/// <param name="position">The position of the rigidbody.</param>
|
||||
public void SetPosition(float2 position)
|
||||
public float2 Position
|
||||
{
|
||||
ScriptGlue.RigidBody2D_SetPosition(Entity._uuid, position);
|
||||
get
|
||||
{
|
||||
ScriptGlue.Rigidbody2D_GetPosition(Entity._uuid, out float2 position);
|
||||
|
||||
return position;
|
||||
}
|
||||
set => ScriptGlue.Rigidbody2D_SetPosition(Entity._uuid, value);
|
||||
}
|
||||
|
||||
public float2 GetPosition()
|
||||
/// <summary>
|
||||
/// Gets or sets the global rotation of the rigidbody.
|
||||
/// </summary>
|
||||
public float Rotation
|
||||
{
|
||||
ScriptGlue.RigidBody2D_GetPosition(Entity._uuid, out float2 position);
|
||||
get
|
||||
{
|
||||
ScriptGlue.Rigidbody2D_GetRotation(Entity._uuid, out float rotation);
|
||||
|
||||
return position;
|
||||
return rotation;
|
||||
}
|
||||
set => ScriptGlue.Rigidbody2D_SetRotation(Entity._uuid, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,16 +42,22 @@ internal static class ScriptGlue
|
||||
#region RigidBody2D
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void RigidBody2D_ApplyForce(UUID entityId, in float2 force, float2 point, bool wakeUp);
|
||||
internal static extern void Rigidbody2D_ApplyForce(UUID entityId, in float2 force, float2 point, bool wakeUp);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void RigidBody2D_ApplyForceToCenter(UUID entityId, in float2 force, bool wakeUp);
|
||||
internal static extern void Rigidbody2D_ApplyForceToCenter(UUID entityId, in float2 force, bool wakeUp);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void RigidBody2D_SetPosition(UUID entityId, in float2 position);
|
||||
internal static extern void Rigidbody2D_SetPosition(UUID entityId, in float2 position);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void RigidBody2D_GetPosition(UUID entityId, out float2 position);
|
||||
internal static extern void Rigidbody2D_GetPosition(UUID entityId, out float2 position);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void Rigidbody2D_SetRotation(UUID entityId, in float rotation);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void Rigidbody2D_GetRotation(UUID entityId, out float rotation);
|
||||
|
||||
#endregion RigidBody2D
|
||||
|
||||
|
||||
Reference in New Issue
Block a user