add physX colliders ,add trigger, colliders now can visible, some rotation for cs and native cpp connection
This commit is contained in:
56
Prism-ScriptCore/Src/Prism/Math/Queternion.cs
Normal file
56
Prism-ScriptCore/Src/Prism/Math/Queternion.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Quaternion
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
public float W;
|
||||
|
||||
public Quaternion(float x, float y, float z, float w)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public Quaternion(float w, Vec3 xyz)
|
||||
{
|
||||
X = xyz.X;
|
||||
Y = xyz.Y;
|
||||
Z = xyz.Z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public Quaternion(Vec3 eulerAngles)
|
||||
{
|
||||
Vec3 c = Vec3.Cos(eulerAngles * 0.5F);
|
||||
Vec3 s = Vec3.Sin(eulerAngles * 0.5F);
|
||||
|
||||
W = c.X * c.Y * c.Z + s.X * s.Y * s.Z;
|
||||
X = s.X * c.Y * c.Z - c.X * s.Y * s.Z;
|
||||
Y = c.X * s.Y * c.Z + s.X * c.Y * s.Z;
|
||||
Z = c.X * c.Y * s.Z - s.X * s.Y * c.Z;
|
||||
}
|
||||
|
||||
public static Quaternion AngleAxis(float angle, Vec3 axis)
|
||||
{
|
||||
float s = (float)Math.Sin(angle * 0.5F);
|
||||
return new Quaternion(s, axis * s);
|
||||
}
|
||||
|
||||
public static Quaternion operator*(Quaternion a, Quaternion b)
|
||||
{
|
||||
float w = a.W * b.W - a.X * b.X - a.Y * b.Y - a.Z * b.Z;
|
||||
float x = a.W * b.X + a.X * b.W + a.Y * b.Z - a.Z * b.Y;
|
||||
float y = a.W * b.Y + a.Y * b.W + a.Z * b.X - a.X * b.Z;
|
||||
float z = a.W * b.Z + a.Z * b.W + a.X * b.Y - a.Y * b.X;
|
||||
return new Quaternion(x, y, z, w);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -25,20 +25,23 @@ namespace Prism
|
||||
}
|
||||
|
||||
public void Clamp(Vec2 min, Vec2 max) {
|
||||
if (X < min.X)
|
||||
X = min.X;
|
||||
if (X > max.X)
|
||||
X = max.X;
|
||||
|
||||
if (Y < min.Y)
|
||||
Y = min.Y;
|
||||
if (Y > max.Y)
|
||||
Y = max.Y;
|
||||
X = Mathf.Clamp(X, min.X, max.X);
|
||||
Y = Mathf.Clamp(Y, min.Y, max.Y);
|
||||
}
|
||||
|
||||
public static Vec2 operator -(Vec2 l, Vec2 r)
|
||||
{
|
||||
return new Vec2(l.X - r.X, l.Y - r.Y);
|
||||
}
|
||||
|
||||
public static Vec2 operator -(Vec2 vector)
|
||||
{
|
||||
return new Vec2(-vector.X, -vector.Y);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({X}, {Y})";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,12 @@ namespace Prism
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vec3
|
||||
{
|
||||
public static Vec3 Zero = new Vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
public static Vec3 Forward = new Vec3(0.0f, 0.0f, -1.0f);
|
||||
public static Vec3 Right = new Vec3(1.0f, 0.0f, 0.0f);
|
||||
public static Vec3 Up = new Vec3(0.0f, 1.0f, 0.0f);
|
||||
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
@ -40,15 +46,6 @@ namespace Prism
|
||||
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); }
|
||||
@ -66,5 +63,56 @@ namespace Prism
|
||||
set { Y = value.X; Z = value.Y; }
|
||||
}
|
||||
|
||||
|
||||
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 static Vec3 operator +(Vec3 left, Vec3 right)
|
||||
{
|
||||
return new Vec3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||
}
|
||||
|
||||
public static Vec3 operator -(Vec3 left, Vec3 right)
|
||||
{
|
||||
return new Vec3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
|
||||
}
|
||||
|
||||
public static Vec3 operator /(Vec3 left, Vec3 right)
|
||||
{
|
||||
return new Vec3(left.X / right.X, left.Y / right.Y, left.Z / right.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-(Vec3 vector)
|
||||
{
|
||||
return new Vec3(-vector.X, -vector.Y, -vector.Z);
|
||||
}
|
||||
|
||||
public static Vec3 Cos(Vec3 vector)
|
||||
{
|
||||
return new Vec3((float)Math.Cos(vector.X), (float)Math.Cos(vector.Y), (float)Math.Cos(vector.Z));
|
||||
}
|
||||
|
||||
public static Vec3 Sin(Vec3 vector)
|
||||
{
|
||||
return new Vec3((float)Math.Sin(vector.X), (float)Math.Sin(vector.Y), (float)Math.Sin(vector.Z));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({X}, {Y}, {Z})";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,13 +2,13 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vec4
|
||||
{
|
||||
[FieldOffset(0)] public float X;
|
||||
[FieldOffset(4)] public float Y;
|
||||
[FieldOffset(8)] public float Z;
|
||||
[FieldOffset(12)] public float W;
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
public float W;
|
||||
|
||||
public Vec4(float scalar)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user