public bool EstimateAttraction(ProxyForceFieldPrimitivePosed other) { var centerDist = (Pose.position - other.Pose.position).magnitude; var maxRadius = (Primitive.MaxRadius + other.Primitive.MaxRadius); return(centerDist < (maxRadius * 3)); }
public static bool DecollisionVector(ProxyForceFieldPrimitivePosed a, ProxyForceFieldPrimitivePosed b, out Vector3 dir) { var colliderA = ConfigTempCollider(0, a.Primitive); var colliderB = ConfigTempCollider(1, b.Primitive); var res = UnityEngine.Physics.ComputePenetration( colliderA, a.Pose.position, a.Pose.rotation, colliderB, b.Pose.position, b.Pose.rotation, out dir, out float dist); dir *= dist; // direction is normalized until scaled by distance ReleaseTempCollider(colliderA); ReleaseTempCollider(colliderB); return(res); }
public void TestPrimitives() { ProxyForceFieldPrimitive prim = ProxyForceFieldPrimitive.Default; Assert.True(prim.primitiveType == ProxyForceFieldPrimitive.FieldPrimitiveType.Box); { var s2 = prim.SampleDistanceVectorFromPointLocal(new Vector3(1.5f, 0, 0), ProxyForceFieldPrimitive.ShapeSample.Fill); Assert.True(s2.HasSample); AssertNear(s2.Distance, 1.0f); AssertNear(s2.ToSurface, new Vector3(-1, 0, 0)); AssertNear(Mathf.Abs(s2.Distance), s2.ToSurface.magnitude); } { var s2 = prim.SampleDistanceVectorFromPointLocal(new Vector3(1.0f, 0, 0), ProxyForceFieldPrimitive.ShapeSample.Edge); Assert.True(s2.HasSample); AssertNear(s2.Distance, Mathf.Sqrt(2.0f) * 0.5f); } { var testPnt = Vector3.one * 1.5f; var s2 = prim.SampleDistanceVectorFromPointLocal(testPnt, ProxyForceFieldPrimitive.ShapeSample.Fill); Assert.True(s2.HasSample); AssertNear(Mathf.Abs(s2.Distance), s2.ToSurface.magnitude); AssertNear(s2.ToSurface, Vector3.one * -1.0f); AssertNear(s2.Distance, Vector3.one.magnitude); } { var primPose = new Pose(new Vector3(5, 0, 0), Quaternion.identity); ProxyForceFieldPrimitivePosed posed = new ProxyForceFieldPrimitivePosed(prim, primPose); var s2 = posed.SampleDistanceFieldWorld(new Vector3(6.0f, 0, 0), ProxyForceFieldPrimitive.ShapeSample.Fill); Assert.True(s2.HasSample); AssertNear(s2.Distance, 0.5f); } }
public bool TryDecollisionSample(ProxyForceFieldPrimitivePosed other, out Vector3 movement) { return(DecollisionSystem.DecollisionVector(this, other, out movement)); }