TechbloxModdingAPI/GamecraftModdingAPI/SimBody.cs

88 lines
2.3 KiB
C#

using RobocraftX.Common;
using RobocraftX.Physics;
using Svelto.ECS;
using Unity.Mathematics;
using Unity.Physics;
using UnityEngine;
namespace GamecraftModdingAPI
{
/// <summary>
/// A rigid body (like a cluster of connected blocks) during simulation.
/// </summary>
public class SimBody
{
public EGID Id { get; }
public SimBody(EGID id)
{
Id = id;
}
public SimBody(uint id) : this(new EGID(id, CommonExclusiveGroups.SIMULATION_BODIES_GROUP))
{
}
public float3 Position
{
get => GetStruct().position;
set => GetStruct().position = value;
}
public float3 Velocity
{
get => GetStruct().velocity;
set => GetStruct().velocity = value;
}
public float3 AngularVelocity
{
get => GetStruct().angularVelocity;
set => GetStruct().angularVelocity = value;
}
public float3 DeltaVelocity
{
get => GetStruct().deltaVelocity;
set => GetStruct().deltaVelocity = value;
}
public float3 DeltaAngularVelocity
{
get => GetStruct().deltaAngularVelocity;
set => GetStruct().deltaAngularVelocity = value;
}
public float3 Rotation
{
get => ((Quaternion) GetStruct().rotation).eulerAngles;
set
{
ref var str = ref GetStruct();
Quaternion quaternion = str.rotation;
quaternion.eulerAngles = value;
str.rotation = quaternion;
}
}
public float Mass
{
get => math.rcp(GetStruct().physicsMass.InverseMass);
set => GetStruct().physicsMass.InverseMass = math.rcp(value);
}
/// <summary>
/// Whether the body can be moved or static
/// </summary>
public bool Static
{
get => Block.BlockEngine.GetBlockInfo<MassEntityStruct>(Id).isStatic;
set => Block.BlockEngine.GetBlockInfo<MassEntityStruct>(Id).isStatic = value;
}
private ref RigidBodyEntityStruct GetStruct()
{
return ref Block.BlockEngine.GetBlockInfo<RigidBodyEntityStruct>(Id);
}
}
}