public void JointDataCreateHingeTest() { var positionAinA = new float3(0.0f, 1.0f, 2.0f); var positionBinB = new float3(1.0f, 0.0f, 3.0f); var axisInA = float3.zero; var axisInB = float3.zero; var jointDataRef = JointData.CreateHinge(positionAinA, positionBinB, axisInA, axisInB); var jointData = jointDataRef.Value; Assert.AreEqual(positionAinA, jointData.AFromJoint.Translation); Assert.AreEqual(positionBinB, jointData.BFromJoint.Translation); Assert.AreEqual(1, jointData.Version); Assert.AreEqual(2, jointData.NumConstraints); var hingeConstraint = jointDataRef.Value.Constraints[0]; Assert.AreEqual(new bool3(false, true, true), hingeConstraint.ConstrainedAxes); Assert.AreEqual(ConstraintType.Angular, hingeConstraint.Type); Assert.AreEqual(0.0f, hingeConstraint.Min); Assert.AreEqual(0.0f, hingeConstraint.Max); Assert.AreEqual(Constraint.DefaultSpringFrequency, hingeConstraint.SpringFrequency); Assert.AreEqual(Constraint.DefaultSpringDamping, hingeConstraint.SpringDamping); var ballAndSocketConstraint = jointDataRef.Value.Constraints[1]; Assert.AreEqual(new bool3(true, true, true), ballAndSocketConstraint.ConstrainedAxes); Assert.AreEqual(ConstraintType.Linear, ballAndSocketConstraint.Type); Assert.AreEqual(0.0f, ballAndSocketConstraint.Min); Assert.AreEqual(0.0f, ballAndSocketConstraint.Max); Assert.AreEqual(Constraint.DefaultSpringFrequency, ballAndSocketConstraint.SpringFrequency); Assert.AreEqual(Constraint.DefaultSpringDamping, ballAndSocketConstraint.SpringDamping); }
public override unsafe void Create(EntityManager entityManager) { if (autoSetConnected) { RigidTransform bFromA = math.mul(math.inverse(WorldFromB), WorldFromA); positionInConnectedEntity = math.transform(bFromA, positionLocal); hingeAxisInConnectedEntity = math.mul(bFromA.rot, hingeAxisLocal); } CreateJointEntity(JointData.CreateHinge( positionLocal, positionInConnectedEntity, hingeAxisLocal, hingeAxisInConnectedEntity), entityManager); }
public override unsafe void Create(EntityManager entityManager) { if (AutoSetConnected) { var pb = math.transform(worldFromB, PositionInConnectedEntity); PositionLocal = math.transform(math.inverse(worldFromA), pb); HingeAxisLocal = math.rotate(math.inverse(worldFromA), math.rotate(worldFromB, HingeAxisInConnectedEntity)); } CreateJointEntity(JointData.CreateHinge( PositionLocal, PositionInConnectedEntity, HingeAxisLocal, HingeAxisInConnectedEntity), entityManager); }
public override void Create(EntityManager entityManager, GameObjectConversionSystem conversionSystem) { if (AutoSetConnected) { RigidTransform bFromA = math.mul(math.inverse(worldFromB), worldFromA); PositionInConnectedEntity = math.transform(bFromA, PositionLocal); HingeAxisInConnectedEntity = math.mul(bFromA.rot, HingeAxisLocal); } CreateJointEntity( JointData.CreateHinge( new JointFrame { Axis = HingeAxisLocal, Position = PositionLocal }, new JointFrame { Axis = HingeAxisInConnectedEntity, Position = PositionInConnectedEntity } ), entityManager, conversionSystem ); }
void ConvertHingeJoint(LegacyHinge joint) { RigidTransform worldFromBodyA = Math.DecomposeRigidBodyTransform(joint.transform.localToWorldMatrix); RigidTransform worldFromBodyB = joint.connectedBody == null ? RigidTransform.identity : Math.DecomposeRigidBodyTransform(joint.connectedBody.transform.localToWorldMatrix); Math.CalculatePerpendicularNormalized(joint.axis, out float3 perpendicularA, out _); var bodyAFromJoint = new JointFrame { Axis = joint.axis, PerpendicularAxis = perpendicularA, Position = joint.anchor }; var connectedEntity = GetPrimaryEntity(joint.connectedBody); var isConnectedBodyConverted = joint.connectedBody == null || connectedEntity != Entity.Null; RigidTransform bFromA = isConnectedBodyConverted ? math.mul(math.inverse(worldFromBodyB), worldFromBodyA) : worldFromBodyA; RigidTransform bFromBSource = isConnectedBodyConverted ? RigidTransform.identity : worldFromBodyB; var bodyBFromJoint = new JointFrame { Axis = math.mul(bFromA.rot, joint.axis), PerpendicularAxis = math.mul(bFromA.rot, perpendicularA), Position = math.mul(bFromBSource, new float4(joint.connectedAnchor, 1f)).xyz }; var limits = math.radians(new FloatRange(joint.limits.min, joint.limits.max)); var jointData = joint.useLimits ? JointData.CreateLimitedHinge(bodyAFromJoint, bodyBFromJoint, limits) : JointData.CreateHinge(bodyAFromJoint, bodyBFromJoint); CreateJointEntity(joint.gameObject, jointData, GetPrimaryEntity(joint.gameObject), joint.connectedBody == null ? Entity.Null : connectedEntity, joint.enableCollision); }