public override void InitJoint() { var childPinNorm = m_Pin.normalized; var parentPinNorm = m_ParentPin.normalized; var refPinNorm = m_ReferencePin.normalized; NewtonBody child = GetComponent <NewtonBody>(); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; IntPtr referenceBody = (m_ReferenceBody != null) ? m_ReferenceBody.GetBody().GetBody() : IntPtr.Zero; dVector dChildPin = new dVector(childPinNorm.x, childPinNorm.y, childPinNorm.z, 0.0f); dVector dParentPin = new dVector(parentPinNorm.x, parentPinNorm.y, parentPinNorm.z, 0.0f); dVector dReferencePin = new dVector(refPinNorm.x, refPinNorm.y, refPinNorm.z, 0.0f); m_Joint = new dNewtonJointDifferentialGear(m_GearRatio, dChildPin, dParentPin, dReferencePin, child.GetBody().GetBody(), otherBody, referenceBody); EnableCollision = m_EnableCollision; }
public override void Create() { Matrix4x4 localMatrix0 = Matrix4x4.identity; Matrix4x4 localMatrix1 = Matrix4x4.identity; Matrix4x4 localMatrix2 = Matrix4x4.identity; localMatrix0.SetTRS(Vector3.zero, Quaternion.Euler(m_rotation), Vector3.one); localMatrix1.SetTRS(Vector3.zero, Quaternion.Euler(m_parentRotation), Vector3.one); localMatrix2.SetTRS(Vector3.zero, Quaternion.Euler(m_referenceRotation), Vector3.one); Vector4 childPin = localMatrix0.GetColumn(0); Vector4 parentPin = localMatrix1.GetColumn(0); Vector4 referencePin = localMatrix2.GetColumn(0); NewtonBody child = GetComponent <NewtonBody>(); IntPtr otherBody = (m_otherBody != null) ? m_otherBody.GetBody().GetBody() : new IntPtr(0); IntPtr referenceBody = (m_referenceBody != null) ? m_referenceBody.GetBody().GetBody() : new IntPtr(0); dVector dChildPin = new dVector(childPin.x, childPin.y, childPin.z, 0.0f); dVector dParentPin = new dVector(parentPin.x, parentPin.y, parentPin.z, 0.0f); dVector dReferencePin = new dVector(referencePin.x, referencePin.y, referencePin.z, 0.0f); m_joint = new dNewtonJointDifferentialGear(m_gearRatio, dChildPin, dParentPin, dReferencePin, child.GetBody().GetBody(), otherBody, referenceBody); }