(61d00a474) v0.9.7.1

This commit is contained in:
Regalis
2020-03-04 13:04:10 +01:00
parent 3c50efa5c9
commit 3c09ebe02f
5086 changed files with 786063 additions and 295871 deletions
@@ -1,3 +1,8 @@
/* Original source Farseer Physics Engine:
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com
* Microsoft Permissive License (Ms-PL) v1.1
*/
/*
* Farseer Physics Engine:
* Copyright (c) 2012 Ian Qvist
@@ -63,8 +68,8 @@ namespace FarseerPhysics.Collision.Shapes
{
ShapeType = ShapeType.Chain;
_radius = Settings.PolygonRadius;
Debug.Assert(vertices != null && vertices.Count >= 2);
Debug.Assert(vertices != null && vertices.Count >= 3);
Debug.Assert(vertices[0] != vertices[vertices.Count - 1]); // FPE. See http://www.box2d.org/forum/viewtopic.php?f=4&t=7973&p=35363
for (int i = 1; i < vertices.Count; ++i)
@@ -73,7 +78,6 @@ namespace FarseerPhysics.Collision.Shapes
Vector2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
Debug.Assert(Vector2.DistanceSquared(v1, v2) > Settings.LinearSlop * Settings.LinearSlop);
}
@@ -208,11 +212,11 @@ namespace FarseerPhysics.Collision.Shapes
i2 = 0;
}
Vector2 v1 = MathUtils.Mul(ref transform, Vertices[i1]);
Vector2 v2 = MathUtils.Mul(ref transform, Vertices[i2]);
Vector2 v1 = Transform.Multiply(Vertices[i1], ref transform);
Vector2 v2 = Transform.Multiply(Vertices[i2], ref transform);
aabb.LowerBound = Vector2.Min(v1, v2);
aabb.UpperBound = Vector2.Max(v1, v2);
Vector2.Min(ref v1, ref v2, out aabb.LowerBound);
Vector2.Max(ref v1, ref v2, out aabb.UpperBound);
}
protected override void ComputeProperties()
@@ -1,4 +1,9 @@
/*
/* Original source Farseer Physics Engine:
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com
* Microsoft Permissive License (Ms-PL) v1.1
*/
/*
* Farseer Physics Engine:
* Copyright (c) 2012 Ian Qvist
*
@@ -23,6 +28,7 @@
using System;
using System.Diagnostics;
using FarseerPhysics.Common;
using FarseerPhysics.Common.Maths;
using Microsoft.Xna.Framework;
namespace FarseerPhysics.Collision.Shapes
@@ -78,7 +84,7 @@ namespace FarseerPhysics.Collision.Shapes
public override bool TestPoint(ref Transform transform, ref Vector2 point)
{
Vector2 center = transform.p + MathUtils.Mul(transform.q, Position);
Vector2 center = transform.p + Complex.Multiply(ref _position, ref transform.q);
Vector2 d = point - center;
return Vector2.Dot(d, d) <= _2radius;
}
@@ -92,7 +98,7 @@ namespace FarseerPhysics.Collision.Shapes
output = new RayCastOutput();
Vector2 position = transform.p + MathUtils.Mul(transform.q, Position);
Vector2 position = transform.p + Complex.Multiply(ref _position, ref transform.q);
Vector2 s = input.Point1 - position;
float b = Vector2.Dot(s, s) - _2radius;
@@ -128,14 +134,21 @@ namespace FarseerPhysics.Collision.Shapes
public override void ComputeAABB(out AABB aabb, ref Transform transform, int childIndex)
{
Vector2 p = transform.p + MathUtils.Mul(transform.q, Position);
aabb.LowerBound = new Vector2(p.X - Radius, p.Y - Radius);
aabb.UpperBound = new Vector2(p.X + Radius, p.Y + Radius);
// OPT: Vector2 p = transform.p + Complex.Multiply(ref _position, ref transform.q);
var pX = (_position.X * transform.q.Real - _position.Y * transform.q.Imaginary) + transform.p.X;
var pY = (_position.Y * transform.q.Real + _position.X * transform.q.Imaginary) + transform.p.Y;
// OPT: aabb.LowerBound = new Vector2(p.X - Radius, p.Y - Radius);
// OPT: aabb.UpperBound = new Vector2(p.X + Radius, p.Y + Radius);
aabb.LowerBound.X = pX - Radius;
aabb.LowerBound.Y = pY - Radius;
aabb.UpperBound.X = pX + Radius;
aabb.UpperBound.Y = pY + Radius;
}
protected override sealed void ComputeProperties()
{
float area = Settings.Pi * _2radius;
float area = MathHelper.Pi * _2radius;
MassData.Area = area;
MassData.Mass = Density * area;
MassData.Centroid = Position;
@@ -148,7 +161,7 @@ namespace FarseerPhysics.Collision.Shapes
{
sc = Vector2.Zero;
Vector2 p = MathUtils.Mul(ref xf, Position);
Vector2 p = Transform.Multiply(ref _position, ref xf);
float l = -(Vector2.Dot(normal, p) - offset);
if (l < -Radius + Settings.Epsilon)
{
@@ -159,12 +172,12 @@ namespace FarseerPhysics.Collision.Shapes
{
//Completely wet
sc = p;
return Settings.Pi * _2radius;
return MathHelper.Pi * _2radius;
}
//Magic
float l2 = l * l;
float area = _2radius * (float)((Math.Asin(l / Radius) + Settings.Pi / 2) + l * Math.Sqrt(_2radius - l2));
float area = _2radius * (float)((Math.Asin(l / Radius) + MathHelper.Pi / 2) + l * Math.Sqrt(_2radius - l2));
float com = -2.0f / 3.0f * (float)Math.Pow(_2radius - l2, 1.5f) / area;
sc.X = p.X + normal.X * com;
@@ -1,3 +1,8 @@
/* Original source Farseer Physics Engine:
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com
* Microsoft Permissive License (Ms-PL) v1.1
*/
/*
* Farseer Physics Engine:
* Copyright (c) 2012 Ian Qvist
@@ -21,6 +26,7 @@
*/
using FarseerPhysics.Common;
using FarseerPhysics.Common.Maths;
using Microsoft.Xna.Framework;
namespace FarseerPhysics.Collision.Shapes
@@ -143,8 +149,8 @@ namespace FarseerPhysics.Collision.Shapes
output = new RayCastOutput();
// Put the ray into the edge's frame of reference.
Vector2 p1 = MathUtils.MulT(transform.q, input.Point1 - transform.p);
Vector2 p2 = MathUtils.MulT(transform.q, input.Point2 - transform.p);
Vector2 p1 = Complex.Divide(input.Point1 - transform.p, ref transform.q);
Vector2 p2 = Complex.Divide(input.Point2 - transform.p, ref transform.q);
Vector2 d = p2 - p1;
Vector2 v1 = _vertex1;
@@ -201,15 +207,43 @@ namespace FarseerPhysics.Collision.Shapes
public override void ComputeAABB(out AABB aabb, ref Transform transform, int childIndex)
{
Vector2 v1 = MathUtils.Mul(ref transform, _vertex1);
Vector2 v2 = MathUtils.Mul(ref transform, _vertex2);
// OPT: Vector2 v1 = Transform.Multiply(ref _vertex1, ref transform);
float v1X = (_vertex1.X * transform.q.Real - _vertex1.Y * transform.q.Imaginary) + transform.p.X;
float v1Y = (_vertex1.Y * transform.q.Real + _vertex1.X * transform.q.Imaginary) + transform.p.Y;
// OPT: Vector2 v2 = Transform.Multiply(ref _vertex2, ref transform);
float v2X = (_vertex2.X * transform.q.Real - _vertex2.Y * transform.q.Imaginary) + transform.p.X;
float v2Y = (_vertex2.Y * transform.q.Real + _vertex2.X * transform.q.Imaginary) + transform.p.Y;
Vector2 lower = Vector2.Min(v1, v2);
Vector2 upper = Vector2.Max(v1, v2);
// OPT: aabb.LowerBound = Vector2.Min(v1, v2);
// OPT: aabb.UpperBound = Vector2.Max(v1, v2);
if (v1X < v2X)
{
aabb.LowerBound.X = v1X;
aabb.UpperBound.X = v2X;
}
else
{
aabb.LowerBound.X = v2X;
aabb.UpperBound.X = v1X;
}
if (v1Y < v2Y)
{
aabb.LowerBound.Y = v1Y;
aabb.UpperBound.Y = v2Y;
}
else
{
aabb.LowerBound.Y = v2Y;
aabb.UpperBound.Y = v1Y;
}
Vector2 r = new Vector2(Radius, Radius);
aabb.LowerBound = lower - r;
aabb.UpperBound = upper + r;
// OPT: Vector2 r = new Vector2(Radius, Radius);
// OPT: aabb.LowerBound = aabb.LowerBound - r;
// OPT: aabb.UpperBound = aabb.LowerBound + r;
aabb.LowerBound.X -= Radius;
aabb.LowerBound.Y -= Radius;
aabb.UpperBound.X += Radius;
aabb.UpperBound.Y += Radius;
}
protected override void ComputeProperties()
@@ -1,3 +1,8 @@
/* Original source Farseer Physics Engine:
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com
* Microsoft Permissive License (Ms-PL) v1.1
*/
/*
* Farseer Physics Engine:
* Copyright (c) 2012 Ian Qvist
@@ -23,6 +28,7 @@
using System.Diagnostics;
using FarseerPhysics.Common;
using FarseerPhysics.Common.ConvexHull;
using FarseerPhysics.Common.Maths;
using Microsoft.Xna.Framework;
namespace FarseerPhysics.Collision.Shapes
@@ -87,7 +93,7 @@ namespace FarseerPhysics.Collision.Shapes
{
_vertices = new Vertices(value);
//Debug.Assert(_vertices.Count >= 3 && _vertices.Count <= Settings.MaxPolygonVertices);
Debug.Assert(_vertices.Count >= 3 && _vertices.Count <= Settings.MaxPolygonVertices);
if (Settings.UseConvexHullPolygons)
{
@@ -179,7 +185,7 @@ namespace FarseerPhysics.Collision.Shapes
Vector2 e1 = Vertices[i] - s;
Vector2 e2 = i + 1 < Vertices.Count ? Vertices[i + 1] - s : Vertices[0] - s;
float D = MathUtils.Cross(e1, e2);
float D = MathUtils.Cross(ref e1, ref e2);
float triangleArea = 0.5f * D;
area += triangleArea;
@@ -218,7 +224,7 @@ namespace FarseerPhysics.Collision.Shapes
public override bool TestPoint(ref Transform transform, ref Vector2 point)
{
Vector2 pLocal = MathUtils.MulT(transform.q, point - transform.p);
Vector2 pLocal = Complex.Divide(point - transform.p, ref transform.q);
for (int i = 0; i < Vertices.Count; ++i)
{
@@ -237,8 +243,8 @@ namespace FarseerPhysics.Collision.Shapes
output = new RayCastOutput();
// Put the ray into the polygon's frame of reference.
Vector2 p1 = MathUtils.MulT(transform.q, input.Point1 - transform.p);
Vector2 p2 = MathUtils.MulT(transform.q, input.Point2 - transform.p);
Vector2 p1 = Complex.Divide(input.Point1 - transform.p, ref transform.q);
Vector2 p2 = Complex.Divide(input.Point2 - transform.p, ref transform.q);
Vector2 d = p2 - p1;
float lower = 0.0f, upper = input.MaxFraction;
@@ -296,7 +302,7 @@ namespace FarseerPhysics.Collision.Shapes
if (index >= 0)
{
output.Fraction = lower;
output.Normal = MathUtils.Mul(transform.q, Normals[index]);
output.Normal = Complex.Multiply(Normals[index], ref transform.q);
return true;
}
@@ -311,19 +317,36 @@ namespace FarseerPhysics.Collision.Shapes
/// <param name="childIndex">The child shape index.</param>
public override void ComputeAABB(out AABB aabb, ref Transform transform, int childIndex)
{
Vector2 lower = MathUtils.Mul(ref transform, Vertices[0]);
Vector2 upper = lower;
// OPT: aabb.LowerBound = Transform.Multiply(Vertices[0], ref transform);
var vert = Vertices[0];
aabb.LowerBound.X = (vert.X * transform.q.Real - vert.Y * transform.q.Imaginary) + transform.p.X;
aabb.LowerBound.Y = (vert.Y * transform.q.Real + vert.X * transform.q.Imaginary) + transform.p.Y;
aabb.UpperBound = aabb.LowerBound;
for (int i = 1; i < Vertices.Count; ++i)
{
Vector2 v = MathUtils.Mul(ref transform, Vertices[i]);
lower = Vector2.Min(lower, v);
upper = Vector2.Max(upper, v);
// OPT: Vector2 v = Transform.Multiply(Vertices[i], ref transform);
vert = Vertices[i];
float vX = (vert.X * transform.q.Real - vert.Y * transform.q.Imaginary) + transform.p.X;
float vY = (vert.Y * transform.q.Real + vert.X * transform.q.Imaginary) + transform.p.Y;
// OPT: Vector2.Min(ref aabb.LowerBound, ref v, out aabb.LowerBound);
// OPT: Vector2.Max(ref aabb.UpperBound, ref v, out aabb.UpperBound);
Debug.Assert(aabb.LowerBound.X <= aabb.UpperBound.X);
if (vX < aabb.LowerBound.X) aabb.LowerBound.X = vX;
else if (vX > aabb.UpperBound.X) aabb.UpperBound.X = vX;
Debug.Assert(aabb.LowerBound.Y <= aabb.UpperBound.Y);
if (vY < aabb.LowerBound.Y) aabb.LowerBound.Y = vY;
else if (vY > aabb.UpperBound.Y) aabb.UpperBound.Y = vY;
}
Vector2 r = new Vector2(Radius, Radius);
aabb.LowerBound = lower - r;
aabb.UpperBound = upper + r;
// OPT: Vector2 r = new Vector2(Radius, Radius);
// OPT: aabb.LowerBound = aabb.LowerBound - r;
// OPT: aabb.UpperBound = aabb.UpperBound + r;
aabb.LowerBound.X -= Radius;
aabb.LowerBound.Y -= Radius;
aabb.UpperBound.X += Radius;
aabb.UpperBound.Y += Radius;
}
public override float ComputeSubmergedArea(ref Vector2 normal, float offset, ref Transform xf, out Vector2 sc)
@@ -331,7 +354,7 @@ namespace FarseerPhysics.Collision.Shapes
sc = Vector2.Zero;
//Transform plane into shape co-ordinates
Vector2 normalL = MathUtils.MulT(xf.q, normal);
Vector2 normalL = Complex.Divide(ref normal, ref xf.q);
float offsetL = offset - Vector2.Dot(normal, xf.p);
float[] depths = new float[Settings.MaxPolygonVertices];
@@ -372,7 +395,7 @@ namespace FarseerPhysics.Collision.Shapes
if (lastSubmerged)
{
//Completely submerged
sc = MathUtils.Mul(ref xf, MassData.Centroid);
sc = Transform.Multiply(MassData.Centroid, ref xf);
return MassData.Mass / Density;
}
@@ -421,7 +444,7 @@ namespace FarseerPhysics.Collision.Shapes
Vector2 e1 = p2 - intoVec;
Vector2 e2 = p3 - intoVec;
float D = MathUtils.Cross(e1, e2);
float D = MathUtils.Cross(ref e1, ref e2);
float triangleArea = 0.5f * D;
@@ -437,7 +460,7 @@ namespace FarseerPhysics.Collision.Shapes
//Normalize and transform centroid
center *= 1.0f / area;
sc = MathUtils.Mul(ref xf, center);
sc = Transform.Multiply(ref center, ref xf);
return area;
}
@@ -1,4 +1,9 @@
/*
/* Original source Farseer Physics Engine:
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com
* Microsoft Permissive License (Ms-PL) v1.1
*/
/*
* Farseer Physics Engine:
* Copyright (c) 2012 Ian Qvist
*
@@ -225,28 +230,6 @@ namespace FarseerPhysics.Collision.Shapes
/// </summary>
protected abstract void ComputeProperties();
/// <summary>
/// Compare this shape to another shape based on type and properties.
/// </summary>
/// <param name="shape">The other shape</param>
/// <returns>True if the two shapes are the same.</returns>
public bool CompareTo(Shape shape)
{
if (shape is PolygonShape && this is PolygonShape)
return ((PolygonShape)this).CompareTo((PolygonShape)shape);
if (shape is CircleShape && this is CircleShape)
return ((CircleShape)this).CompareTo((CircleShape)shape);
if (shape is EdgeShape && this is EdgeShape)
return ((EdgeShape)this).CompareTo((EdgeShape)shape);
if (shape is ChainShape && this is ChainShape)
return ((ChainShape)this).CompareTo((ChainShape)shape);
return false;
}
/// <summary>
/// Used for the buoyancy controller
/// </summary>