Пример #1
0
        public void ReadTransform()
        {
            if (!this.IsEnabled)
            {
                return;
            }

            this.Position = this.ViewModel.Position;
            this.Rotation = this.ViewModel.Rotation;
            this.Scale    = this.ViewModel.Scale;

            // Convert the character-relative transform into a parent-relative transform
            Point3D    position = this.Position.ToMedia3DPoint();
            Quaternion rotation = this.Rotation.ToMedia3DQuaternion();

            if (this.Parent != null)
            {
                TransformViewModel parentTransform = this.Parent.ViewModel;
                Point3D            parentPosition  = parentTransform.Position.ToMedia3DPoint();
                Quaternion         parentRot       = parentTransform.Rotation.ToMedia3DQuaternion();
                parentRot.Invert();

                // relative position
                position = (Point3D)(position - parentPosition);

                // relative rotation
                rotation = parentRot * rotation;

                // unrotate bones, since we will transform them ourselves.
                RotateTransform3D rotTrans = new RotateTransform3D(new QuaternionRotation3D(parentRot));
                position = rotTrans.Transform(position);
            }

            // Store the new parent-relative transform info
            this.Position = position.ToCmVector();
            this.Rotation = rotation.ToCmQuaternion();

            // Set the Media3D hierarchy transforms
            this.rotation.Rotation = new QuaternionRotation3D(rotation);
            this.position.OffsetX  = position.X;
            this.position.OffsetY  = position.Y;
            this.position.OffsetZ  = position.Z;

            // Draw a line for visualization
            if (this.Parent != null && this.lineToParent != null)
            {
                Point3D p = this.lineToParent.Points[1];
                p.X = position.X;
                p.Y = position.Y;
                p.Z = position.Z;
                this.lineToParent.Points[1] = p;
            }
        }