protected override void OnEnable() { base.OnEnable(); _revoluteJointObject = _jointObject as b2RevoluteJointObject; _oldAutoConfigureAnchor = _revoluteJointObject.autoConfigureAnchor; fixAutoAnchor(); _oldLocalAnchor1.SetV(_revoluteJointObject.localAnchor1); _oldLocalAnchor2.SetV(_revoluteJointObject.localAnchor2); _oldEnableLimit = _revoluteJointObject.enableLimit; _oldReferenceAngle = _revoluteJointObject.referenceAngle; _oldLowerAngle = _revoluteJointObject.lowerAngle; _oldUpperAngle = _revoluteJointObject.upperAngle; _oldEnableMotor = _revoluteJointObject.enableMotor; _oldMotorSpeed = _revoluteJointObject.motorSpeed; _oldMaxMotorTorque = _revoluteJointObject.maxMotorTorque; //添加到链接的bodyObject关节列表 if (_revoluteJointObject.connectedB2BodyObject != null) { _revoluteJointObject.connectedB2BodyObject.addJointObject(_revoluteJointObject); } }
protected override void OnEnable() { base.OnEnable(); _ropeJointObject = _jointObject as b2RopeJointObject; _oldAutoConfigureAnchor = _ropeJointObject.autoConfigureAnchor; fixAutoAnchor(); _oldLocalAnchor1.SetV(_ropeJointObject.localAnchor1); _oldLocalAnchor2.SetV(_ropeJointObject.localAnchor2); _oldMaxLength = _ropeJointObject.maxLength; }
/** * @inheritDoc */ public override float ComputeSubmergedArea( b2Vec2 normal, float offset, b2Transform xf, b2Vec2 c) { b2Vec2 p = b2Math.MulX(xf, m_p); float l = -(b2Math.Dot(normal, p) - offset); if (l < -m_radius + float.MinValue) { //Completely dry return(0.0f); } if (l > m_radius) { //Completely wet c.SetV(p); return(Mathf.PI * m_radius * m_radius); } //Magic float r2 = m_radius * m_radius; float l2 = l * l; float area = r2 * (Mathf.Asin(l / m_radius) + Mathf.PI / 2.0f) + l * Mathf.Sqrt(r2 - l2); float com = -2.0f / 3.0f * Mathf.Pow(r2 - l2, 1.5f) / area; c.x = p.x + normal.x * com; c.y = p.y + normal.y * com; return(area); }
public void GetWitnessPoints(b2Vec2 pA, b2Vec2 pB) { switch (m_count) { case 0: b2Settings.b2Assert(false); break; case 1: pA.SetV(m_v1.wA); pB.SetV(m_v1.wB); break; case 2: pA.x = m_v1.a * m_v1.wA.x + m_v2.a * m_v2.wA.x; pA.y = m_v1.a * m_v1.wA.y + m_v2.a * m_v2.wA.y; pB.x = m_v1.a * m_v1.wB.x + m_v2.a * m_v2.wB.x; pB.y = m_v1.a * m_v1.wB.y + m_v2.a * m_v2.wB.y; break; case 3: pB.x = pA.x = m_v1.a * m_v1.wA.x + m_v2.a * m_v2.wA.x + m_v3.a * m_v3.wA.x; pB.y = pA.y = m_v1.a * m_v1.wA.y + m_v2.a * m_v2.wA.y + m_v3.a * m_v3.wA.y; break; default: b2Settings.b2Assert(false); break; } }
public void Set(b2Vec2 x1, float a1, b2Vec2 x2, float a2) { linearA.SetV(x1); angularA = a1; linearB.SetV(x2); angularB = a2; }
/** * @inheritDoc */ public override float ComputeSubmergedArea( b2Vec2 normal, float offset, b2Transform xf, b2Vec2 c) { // Transform plane into shape co-ordinates b2Vec2 normalL = b2Math.MulTMV(xf.R, normal); float offsetL = offset - b2Math.Dot(normal, xf.position); List <float> depths = new List <float>(); int diveCount = 0; int intoIndex = -1; int outoIndex = -1; bool lastSubmerged = false; int i; for (i = 0; i < m_vertexCount; ++i) { depths[i] = b2Math.Dot(normalL, m_vertices[i]) - offsetL; bool isSubmerged = depths[i] < -float.MinValue; if (i > 0) { if (isSubmerged) { if (!lastSubmerged) { intoIndex = i - 1; diveCount++; } } else { if (lastSubmerged) { outoIndex = i - 1; diveCount++; } } } lastSubmerged = isSubmerged; } switch (diveCount) { case 0: if (lastSubmerged) { // Completely submerged b2MassData md = new b2MassData(); ComputeMass(md, 1); c.SetV(b2Math.MulX(xf, md.center)); return(md.mass); } else { //Completely dry return(0); } break; case 1: if (intoIndex == -1) { intoIndex = m_vertexCount - 1; } else { outoIndex = m_vertexCount - 1; } break; } int intoIndex2 = (intoIndex + 1) % m_vertexCount; int outoIndex2 = (outoIndex + 1) % m_vertexCount; float intoLamdda = (0.0f - depths[intoIndex]) / (depths[intoIndex2] - depths[intoIndex]); float outoLamdda = (0.0f - depths[outoIndex]) / (depths[outoIndex2] - depths[outoIndex]); b2Vec2 intoVec = new b2Vec2(m_vertices[intoIndex].x * (1.0f - intoLamdda) + m_vertices[intoIndex2].x * intoLamdda, m_vertices[intoIndex].y * (1.0f - intoLamdda) + m_vertices[intoIndex2].y * intoLamdda); b2Vec2 outoVec = new b2Vec2(m_vertices[outoIndex].x * (1.0f - outoLamdda) + m_vertices[outoIndex2].x * outoLamdda, m_vertices[outoIndex].y * (1.0f - outoLamdda) + m_vertices[outoIndex2].y * outoLamdda); // Initialize accumulator float area = 0.0f; b2Vec2 center = new b2Vec2(); b2Vec2 p2 = m_vertices[intoIndex2]; b2Vec2 p3; // An awkward loop from intoIndex2+1 to outIndex2 i = intoIndex2; while (i != outoIndex2) { i = (i + 1) % m_vertexCount; if (i == outoIndex2) { p3 = outoVec; } else { p3 = m_vertices[i]; } float triangleArea = 0.5f * ((p2.x - intoVec.x) * (p3.y - intoVec.y) - (p2.y - intoVec.y) * (p3.x - intoVec.x)); area += triangleArea; // Area weighted centroid center.x += triangleArea * (intoVec.x + p2.x + p3.x) / 3.0f; center.y += triangleArea * (intoVec.y + p2.y + p3.y) / 3.0f; p2 = p3; } //Normalize and transform centroid center.Multiply(1.0f / area); c.SetV(b2Math.MulX(xf, center)); return(area); }