public override void UpdateDataFromPhysicsEngine() { if (MotionType.Value == MotionTypeEnum.Dynamic && rigidBody != null) { var position = Physics2DUtility.Convert(rigidBody.Position); var rotation = -rigidBody.Rotation; var oldT = Transform.Value; Matrix3F.FromRotateByZ(rotation, out var mat3); var rot2 = mat3.ToQuaternion(); //var rot2 = new Angles( 0, 0, MathEx.RadianToDegree( rot ) ); var newT = new Transform(new Vector3(position.X, position.Y, oldT.Position.Z), rot2, oldT.Scale); try { updatePropertiesWithoutUpdatingBody = true; Transform = newT; LinearVelocity = Physics2DUtility.Convert(rigidBody.LinearVelocity); AngularVelocity = MathEx.RadianToDegree(rigidBody.AngularVelocity); } finally { updatePropertiesWithoutUpdatingBody = false; } } }
public override void UpdateDataFromPhysicsEngine() { if (ConstraintRigid != null) { Transform rigidBodyTransform; { var rigidBody = ConstraintRigid.BodyA; var position = Physics2DUtility.Convert(rigidBody.Position); var rotation = -rigidBody.Rotation; var oldT = Transform.Value; Matrix3F.FromRotateByZ(rotation, out var mat3); var rot2 = mat3.ToQuaternion(); //var rot2 = new Angles( 0, 0, MathEx.RadianToDegree( rot ) ); rigidBodyTransform = new Transform(new Vector3(position.X, position.Y, oldT.Position.Z), rot2); } { var transformA = rigidBodyTransform.ToMatrix4() * ConstraintAFrame; transformA.Decompose(out Vector3 translation, out Matrix3 rotation, out Vector3 scale); var oldT = Transform.Value; var newT = new Transform(translation, rotation.ToQuaternion(), oldT.Scale); SetTransformWithoutUpdatingConstraint(newT); } } }
public static void FromRotateByZ(RadianF angle, out QuaternionF result) { Matrix3F.FromRotateByZ(angle, out var mat); mat.ToQuaternion(out result); }
public static QuaternionF FromRotateByZ(RadianF angle) { Matrix3F.FromRotateByZ(angle, out var mat); return(mat.ToQuaternion()); }