コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
 public static void FromRotateByZ(RadianF angle, out QuaternionF result)
 {
     Matrix3F.FromRotateByZ(angle, out var mat);
     mat.ToQuaternion(out result);
 }
コード例 #4
0
 public static QuaternionF FromRotateByZ(RadianF angle)
 {
     Matrix3F.FromRotateByZ(angle, out var mat);
     return(mat.ToQuaternion());
 }