diff options
author | chai <chaifix@163.com> | 2018-09-04 22:22:08 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-09-04 22:22:08 +0800 |
commit | 9c8f80daa67b98dfa603329f29fa4fc2ddfc8403 (patch) | |
tree | f2e7648f9a59167f316bd390529600a550c66de7 /Box2d/Assets/Program |
*init
Diffstat (limited to 'Box2d/Assets/Program')
28 files changed, 495 insertions, 0 deletions
diff --git a/Box2d/Assets/Program/Box2d.meta b/Box2d/Assets/Program/Box2d.meta new file mode 100644 index 0000000..b188c26 --- /dev/null +++ b/Box2d/Assets/Program/Box2d.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2d7c6890e16551f4cbcda1b8b4312b67 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Box2d.cs b/Box2d/Assets/Program/Box2d/Box2d.cs new file mode 100644 index 0000000..308a02a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Box2d.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Box2d +{ + /////////////////////////////////// + // Box2d C# port + // author: chai + /////////////////////////////////// +} diff --git a/Box2d/Assets/Program/Box2d/Box2d.cs.meta b/Box2d/Assets/Program/Box2d/Box2d.cs.meta new file mode 100644 index 0000000..3e25ab6 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Box2d.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7d074173b374c384397568691e8bbb72 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Collision.meta b/Box2d/Assets/Program/Box2d/Collision.meta new file mode 100644 index 0000000..245ceea --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Collision.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 394557b338e480c4996d86b0b747dea4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Collision/Collision.cs b/Box2d/Assets/Program/Box2d/Collision/Collision.cs new file mode 100644 index 0000000..5b8a47a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Collision/Collision.cs @@ -0,0 +1,7 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Box2d +{ + +} diff --git a/Box2d/Assets/Program/Box2d/Collision/Collision.cs.meta b/Box2d/Assets/Program/Box2d/Collision/Collision.cs.meta new file mode 100644 index 0000000..f6efab1 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Collision/Collision.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 51a0a77685f2dad41956ee5d84760da4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Collision/Shapes.meta b/Box2d/Assets/Program/Box2d/Collision/Shapes.meta new file mode 100644 index 0000000..8dba44f --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Collision/Shapes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c1cd68701d850324ab79c060c45dc4f6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Collision/Shapes/PolygonShape.cs b/Box2d/Assets/Program/Box2d/Collision/Shapes/PolygonShape.cs new file mode 100644 index 0000000..5b8a47a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Collision/Shapes/PolygonShape.cs @@ -0,0 +1,7 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Box2d +{ + +} diff --git a/Box2d/Assets/Program/Box2d/Collision/Shapes/PolygonShape.cs.meta b/Box2d/Assets/Program/Box2d/Collision/Shapes/PolygonShape.cs.meta new file mode 100644 index 0000000..f9c2740 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Collision/Shapes/PolygonShape.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ec575ec2673d99d4e9bf74bc4cbf134a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Common.meta b/Box2d/Assets/Program/Box2d/Common.meta new file mode 100644 index 0000000..af0e496 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Common.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 643d25cec7a2c4a48abcfb9a6dd90931 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Common/Mat22.cs b/Box2d/Assets/Program/Box2d/Common/Mat22.cs new file mode 100644 index 0000000..0da59dd --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Common/Mat22.cs @@ -0,0 +1,81 @@ +using System; + +namespace Box2d +{ + class Mat22 + { + public Mat22() + { + } + + public Mat22(Vec2 c1, Vec2 c2) + { + col1.Set(c1); + col2.Set(c2); + } + + public Mat22(float a11, float a12, float a21, float a22) + { + col1.x = a11; col1.y = a21; + col2.x = a12; col2.y = a22; + } + + public void Set(Vec2 c1, Vec2 c2) + { + col1.Set(c1); + col2.Set(c2); + } + + void SetIdentity() + { + col1.x = 1.0f; col2.x = 0.0f; + col1.y = 0.0f; col2.y = 1.0f; + } + + void SetZero() + { + col1.Set(0, 0); + col2.Set(0, 0); + } + + public float GetAngle() + { + return Convert.ToSingle(System.Math.Atan2(col1.y, col1.x)); + } + + /// <summary> + /// Compute the inverse of this matrix, such that inv(A) * A = identity. + /// </summary> + /// <returns></returns> + public Mat22 GetInverse() + { + float a = col1.x; + float b = col2.x; + float c = col1.y; + float d = col2.y; + float det = a * d - b * c; + if(det != 0.0) + { + det = 1 / det; + } + Mat22 m = new Mat22(); + m.col1.x = det * d; m.col2.x = -det * b; + m.col1.y = -det * c; m.col2.y = det * a; + return m; + } + + public Vec2 Solve() + { + + } + + /* + * col1.x col2.x + * + * + * col1.y col2.y + */ + Vec2 col1 = new Vec2(); + Vec2 col2 = new Vec2(); + } +} diff --git a/Box2d/Assets/Program/Box2d/Common/Math.cs b/Box2d/Assets/Program/Box2d/Common/Math.cs new file mode 100644 index 0000000..aece85a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Common/Math.cs @@ -0,0 +1,33 @@ +using System; + +namespace Box2d +{ + + /// <summary> + /// common functions + /// </summary> + class Math + { + /// This function is used to ensure that a floating point number is not a NaN or infinity. + public static bool IsValid(float x) + { + return x != float.PositiveInfinity + && x != float.NaN + && x != float.NegativeInfinity; + } + + /// This is a approximate yet fast inverse square-root. + public static float InvSqrt(float x) + { + //float xhalf = 0.5f * x; + //int i = BitConverter.ToInt32(BitConverter.GetBytes(x), 0); + //i = 0x5f3759df - (i >> 1); + //x = BitConverter.ToSingle(BitConverter.GetBytes(i), 0); + //x = x * (1.5f - xhalf * x * x); + //return x; + return Convert.ToSingle(1 / System.Math.Sqrt(x)); + } + + } + +} diff --git a/Box2d/Assets/Program/Box2d/Common/Vec2.cs b/Box2d/Assets/Program/Box2d/Common/Vec2.cs new file mode 100644 index 0000000..01f215c --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Common/Vec2.cs @@ -0,0 +1,92 @@ +using System; + +namespace Box2d +{ + class Vec2 + { + public Vec2(float x, float y) + { + this.x = x; + this.y = y; + } + + public Vec2() + { + this.x = 0; + this.y = 0; + } + + public void SetZero() + { + x = 0; + y = 0; + } + + public void Set(float _x, float _y) + { + x = _x; + y = _y; + } + + public void Set(Vec2 v) + { + x = v.x; + y = v.y; + } + + public static Vec2 operator -(Vec2 l, Vec2 r) + { + Vec2 v = new Vec2(l.x - r.x, l.y - r.y); + return v; + } + + public static Vec2 operator +(Vec2 l, Vec2 r) + { + Vec2 v = new Vec2(l.x + r.x, l.y + r.y); + return v; + } + + public static Vec2 operator *(Vec2 l, float a) + { + return new Vec2(l.x * a, l.y * a); + } + + public float Length() + { + return Convert.ToSingle(System.Math.Sqrt(x * x + y * y)); + } + + public float LengthSquared() + { + return x * x + y * y; + } + + /// Convert this vector into a unit vector. Returns the length. + public float Normalize() + { + float length = Length(); + if(length < float.Epsilon) + { + return 0; + } + float invLength = 1 / length; + x *= invLength; + y *= invLength; + return length; + } + + /// Does this vector contain finite coordinates? + public bool IsValid() + { + return Math.IsValid(x) && Math.IsValid(y); + } + + /// Get the skew vector such that dot(skew_vec, other) == cross(vec, other) + public Vec2 Skew() + { + return new Vec2(-y, x); + } + + public float x, y; + } +} diff --git a/Box2d/Assets/Program/Box2d/Common/Vec2.cs.meta b/Box2d/Assets/Program/Box2d/Common/Vec2.cs.meta new file mode 100644 index 0000000..5b47692 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Common/Vec2.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dab092ba9a46fce4d8db5df1c3dc3ae1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Common/Vec3.cs b/Box2d/Assets/Program/Box2d/Common/Vec3.cs new file mode 100644 index 0000000..5315fab --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Common/Vec3.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Box2d +{ + class Vec3 + { + public Vec3() + { + x = 0; + y = 0; + z = 0; + } + + public Vec3(float _x, float _y, float _z) + { + x = _x; + y = _y; + z = _z; + } + + public void SetZero() + { + x = y = z = 0.0f; + } + + public void Set(float _x, float _y, float _z) + { + x = _x; + y = _y; + z = _z; + } + + public static Vec3 operator -(Vec3 l, Vec3 r) + { + Vec3 v = new Vec3(l.x - r.x, l.y - r.y, l.z - r.z); + return v; + } + + public static Vec3 operator +(Vec3 l, Vec3 r) + { + Vec3 v = new Vec3(l.x + r.x, l.y + r.y, l.z + r.z); + return v; + } + + public static Vec3 operator *(Vec3 l, float a) + { + Vec3 v = new Vec3(l.x * a, l.y * a, l.z * a); + return v; + } + + public void Add(Vec3 r) + { + x += r.x; + y += r.y; + z += r.z; + } + + public void Minus(Vec3 r) + { + x -= r.x; + y -= r.y; + z -= r.z; + } + + public void Multiply(float a) + { + x *= a; + y *= a; + z *= a; + } + + public float x, y, z; + } +} diff --git a/Box2d/Assets/Program/Box2d/Dynamics.meta b/Box2d/Assets/Program/Box2d/Dynamics.meta new file mode 100644 index 0000000..faf8ec2 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1c61dc460bde1aa408cbb67ca0228f20 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Dynamics/Body.cs b/Box2d/Assets/Program/Box2d/Dynamics/Body.cs new file mode 100644 index 0000000..5b8a47a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics/Body.cs @@ -0,0 +1,7 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Box2d +{ + +} diff --git a/Box2d/Assets/Program/Box2d/Dynamics/Body.cs.meta b/Box2d/Assets/Program/Box2d/Dynamics/Body.cs.meta new file mode 100644 index 0000000..feceb08 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics/Body.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c34ca0ac7be7cb043899014ec5224583 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Dynamics/Contacts.meta b/Box2d/Assets/Program/Box2d/Dynamics/Contacts.meta new file mode 100644 index 0000000..fa20c51 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics/Contacts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: db3aefd04de863a4d904bc5180470a7f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Dynamics/Contacts/Contact.cs b/Box2d/Assets/Program/Box2d/Dynamics/Contacts/Contact.cs new file mode 100644 index 0000000..5b8a47a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics/Contacts/Contact.cs @@ -0,0 +1,7 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Box2d +{ + +} diff --git a/Box2d/Assets/Program/Box2d/Dynamics/Contacts/Contact.cs.meta b/Box2d/Assets/Program/Box2d/Dynamics/Contacts/Contact.cs.meta new file mode 100644 index 0000000..a36c1ea --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics/Contacts/Contact.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0205d69a32ffcc54598a5888b61b92cf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Dynamics/Joints.meta b/Box2d/Assets/Program/Box2d/Dynamics/Joints.meta new file mode 100644 index 0000000..fd9c93b --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics/Joints.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 43c3d5cd2a29aa04faa935405c8d7f6e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Dynamics/Joints/Joint.cs b/Box2d/Assets/Program/Box2d/Dynamics/Joints/Joint.cs new file mode 100644 index 0000000..5b8a47a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics/Joints/Joint.cs @@ -0,0 +1,7 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Box2d +{ + +} diff --git a/Box2d/Assets/Program/Box2d/Dynamics/Joints/Joint.cs.meta b/Box2d/Assets/Program/Box2d/Dynamics/Joints/Joint.cs.meta new file mode 100644 index 0000000..873395a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Dynamics/Joints/Joint.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 253d58f9cfe34214b80a62f5afdfecf8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Rope.meta b/Box2d/Assets/Program/Box2d/Rope.meta new file mode 100644 index 0000000..5581851 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Rope.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dbd6d3a358e95ab42ade19d1fcbeed91 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Box2d/Rope/Rope.cs b/Box2d/Assets/Program/Box2d/Rope/Rope.cs new file mode 100644 index 0000000..5b8a47a --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Rope/Rope.cs @@ -0,0 +1,7 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Box2d +{ + +} diff --git a/Box2d/Assets/Program/Box2d/Rope/Rope.cs.meta b/Box2d/Assets/Program/Box2d/Rope/Rope.cs.meta new file mode 100644 index 0000000..fa9b631 --- /dev/null +++ b/Box2d/Assets/Program/Box2d/Rope/Rope.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d56353be4c8ccf942941c4bd085c71ba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Box2d/Assets/Program/Test.meta b/Box2d/Assets/Program/Test.meta new file mode 100644 index 0000000..3018498 --- /dev/null +++ b/Box2d/Assets/Program/Test.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cb44a5912cadba440b51ae5ea814a52f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: |