add PhysX SDK and some tweaks
This commit is contained in:
@ -13,6 +13,8 @@ namespace Prism
|
||||
|
||||
private List<Action<float>> m_Collision2DBeginCallbacks = new List<Action<float>>();
|
||||
private List<Action<float>> m_Collision2DEndCallbacks = new List<Action<float>>();
|
||||
private Action<float> m_CollisionBeginCallbacks;
|
||||
private Action<float> m_CollisionEndCallbacks;
|
||||
|
||||
protected Entity() { ID = 0; }
|
||||
|
||||
@ -63,6 +65,24 @@ namespace Prism
|
||||
SetTransform_Native(ID, ref transform);
|
||||
}
|
||||
|
||||
public Vec3 GetForwardDirection()
|
||||
{
|
||||
GetForwardDirection_Native(ID, out Vec3 forward);
|
||||
return forward;
|
||||
}
|
||||
|
||||
public Vec3 GetRightDirection()
|
||||
{
|
||||
GetRightDirection_Native(ID, out Vec3 right);
|
||||
return right;
|
||||
}
|
||||
|
||||
public Vec3 GetUpDirection()
|
||||
{
|
||||
GetUpDirection_Native(ID, out Vec3 up);
|
||||
return up;
|
||||
}
|
||||
|
||||
public void AddCollision2DBeginCallback(Action<float> callback)
|
||||
{
|
||||
m_Collision2DBeginCallbacks.Add(callback);
|
||||
@ -73,6 +93,28 @@ namespace Prism
|
||||
m_Collision2DEndCallbacks.Add(callback);
|
||||
}
|
||||
|
||||
public void AddCollisionBeginCallback(Action<float> callback)
|
||||
{
|
||||
m_CollisionBeginCallbacks += callback;
|
||||
}
|
||||
|
||||
public void AddCollisionEndCallback(Action<float> callback)
|
||||
{
|
||||
m_CollisionEndCallbacks += callback;
|
||||
}
|
||||
|
||||
private void OnCollisionBegin(float data)
|
||||
{
|
||||
if (m_CollisionBeginCallbacks != null)
|
||||
m_CollisionBeginCallbacks.Invoke(data);
|
||||
}
|
||||
|
||||
private void OnCollisionEnd(float data)
|
||||
{
|
||||
if (m_CollisionEndCallbacks != null)
|
||||
m_CollisionEndCallbacks.Invoke(data);
|
||||
}
|
||||
|
||||
private void OnCollision2DBegin(float data)
|
||||
{
|
||||
foreach (var callback in m_Collision2DBeginCallbacks)
|
||||
@ -96,5 +138,11 @@ namespace Prism
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
private static extern ulong FindEntityByTag_Native(string tag);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
private static extern void GetForwardDirection_Native(ulong entityID, out Vec3 forward);
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
private static extern void GetRightDirection_Native(ulong entityID, out Vec3 right);
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
private static extern void GetUpDirection_Native(ulong entityID, out Vec3 up);
|
||||
}
|
||||
}
|
||||
|
||||
15
Prism-ScriptCore/Src/Prism/Math/Mathf.cs
Normal file
15
Prism-ScriptCore/Src/Prism/Math/Mathf.cs
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
public static class Mathf
|
||||
{
|
||||
public static float Clamp(float value, float min, float max)
|
||||
{
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -33,6 +33,23 @@ namespace Prism
|
||||
Z = vec.Z;
|
||||
}
|
||||
|
||||
public void Clamp(Vec3 min, Vec3 max)
|
||||
{
|
||||
X = Mathf.Clamp(X, min.X, max.X);
|
||||
Y = Mathf.Clamp(Y, min.Y, max.Y);
|
||||
Z = Mathf.Clamp(Z, min.Z, max.Z);
|
||||
}
|
||||
|
||||
public static Vec3 operator *(Vec3 left, float scalar)
|
||||
{
|
||||
return new Vec3(left.X * scalar, left.Y * scalar, left.Z * scalar);
|
||||
}
|
||||
|
||||
public static Vec3 operator *(float scalar, Vec3 right)
|
||||
{
|
||||
return new Vec3(scalar * right.X, scalar * right.Y, scalar * right.Z);
|
||||
}
|
||||
|
||||
public Vec2 XY {
|
||||
get { return new Vec2(X, Y); }
|
||||
set { X = value.X; Y = value.Y; }
|
||||
|
||||
@ -123,4 +123,56 @@ namespace Prism
|
||||
public class BoxCollider2DComponent : Component
|
||||
{
|
||||
}
|
||||
|
||||
public class BoxColliderComponent : Component
|
||||
{
|
||||
}
|
||||
|
||||
public class SphereColliderComponent : Component
|
||||
{
|
||||
}
|
||||
|
||||
public class RigidBodyComponent : Component
|
||||
{
|
||||
public enum ForceMode
|
||||
{
|
||||
Force = 0,
|
||||
Impulse,
|
||||
VelocityChange,
|
||||
Acceleration
|
||||
}
|
||||
|
||||
public void AddForce(Vec3 force, ForceMode forceMode = ForceMode.Force)
|
||||
{
|
||||
AddForce_Native(Entity.ID, ref force, forceMode);
|
||||
}
|
||||
|
||||
public void AddTorque(Vec3 torque, ForceMode forceMode = ForceMode.Force)
|
||||
{
|
||||
AddTorque_Native(Entity.ID, ref torque, forceMode);
|
||||
}
|
||||
|
||||
public Vec3 GetLinearVelocity()
|
||||
{
|
||||
GetLinearVelocity_Native(Entity.ID, out Vec3 velocity);
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public void SetLinearVelocity(Vec3 velocity)
|
||||
{
|
||||
SetLinearVelocity_Native(Entity.ID, ref velocity);
|
||||
}
|
||||
|
||||
// TODO: Add SetMaxLinearVelocity() as well
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void AddForce_Native(ulong entityID, ref Vec3 force, ForceMode forceMode);
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void AddTorque_Native(ulong entityID, ref Vec3 torque, ForceMode forceMode);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void GetLinearVelocity_Native(ulong entityID, out Vec3 velocity);
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void SetLinearVelocity_Native(ulong entityID, ref Vec3 velocity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user