public Partial(Entity e1, Entity e2, Position pos1, Position pos2, Geometry.Manifold m, bool useContact1) { this.e1 = e1; this.e2 = e2; var contactWithId = useContact1 ? m.contact1 : (Geometry.Contact)m.contact2; float2 contact = contactWithId.point; id = contactWithId.id.GetHashCode(); { // Normal precomputation J_n = new Float6( new float3(-m.normal, -Lin.Cross(contact - pos1.pos, m.normal)), new float3(m.normal, Lin.Cross(contact - pos2.pos, m.normal)) ); delta = -m.overlap; } { // Tangent precomputation (friction) float2 tangent = Lin.Cross(m.normal, -1); J_t = new Float6( new float3(tangent, Lin.Cross(contact - pos1.pos, tangent)), new float3(-tangent, -Lin.Cross(contact - pos2.pos, tangent))); } }
public OneWayOneDOFConstraint(TargetVelocityManifold m, Float3 M_inv, float dt) { e = m.e; id = m.id; this.M_inv = M_inv; constraint = new OneDOFConstraint <Float3>( J: new float3(m.normal, Lin.Cross(m.r, m.normal)), M_inv: M_inv, bias: -m.targetSpeed, softness: m.softness ); lambdaAccum = 0; }
public TwoWayTwoDOFConstraint(RevoluteJointManifold m, Float6 M_inv, float dt) { e1 = m.e1; e2 = m.e2; id = m.id; float2 oneCrossR1 = Lin.Cross(1, m.r1); float2 oneCrossR2 = Lin.Cross(1, m.r2); this.M_inv = M_inv; constraint = new TwoDOFConstraint <Float6>( J1: new Float6(-1, 0, -oneCrossR1.x, 1, 0, oneCrossR2.x), J2: new Float6(0, -1, -oneCrossR1.y, 0, 1, oneCrossR2.y), M_inv: M_inv, bias: m.delta * m.beta / dt, softness: m.softness ); lambdaAccum = float2.zero; }
static SnapInfo[] GetSnapInfo(Transform transform, float snapRadius) { var snapInfos = new List <SnapInfo>(); void Search(Transform t) { foreach (var child in t.GetComponentsInChildren <BoxAuthoring>()) { var closestPoint = child.GetRect().ClosestPoint((Vector2)transform.position, ccwVec: out var ccwVec, cwVec: out var cwVec); if (math.distance(closestPoint, (Vector2)transform.position) < snapRadius) { Vector2 WorldToLocalVec(float2 vec) { return(child.transform.InverseTransformDirection((Vector2)math.normalize(vec))); } ccwVec = WorldToLocalVec(ccwVec); cwVec = WorldToLocalVec(cwVec); snapInfos.Add(new SnapInfo { pos = (Vector2)child.transform.InverseTransformPoint((Vector2)closestPoint) + (Vector2)math.normalize(Lin.Cross(ccwVec, 1)) * .1f, ccw = ccwVec, cw = cwVec, mount = child.gameObject }); } } } if (transform.parent == null) { foreach (var root in SceneManager.GetActiveScene().GetRootGameObjects()) { Search(root.transform); } } else { Search(transform.parent); } return(snapInfos.ToArray()); }