private void Translation_Mouse3DMove(object sender, MouseMove3DEventArgs e)
        {
            if (!isCaptured)
            {
                return;
            }
            var hit = currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal);

            if (hit.HasValue)
            {
                var moveDir = hit.Value - currentHit;
                currentHit = hit.Value;
                switch (manipulationType)
                {
                case ManipulationType.TranslationX:
                    translationVector += new Vector3(moveDir.X, 0, 0);
                    break;

                case ManipulationType.TranslationY:
                    translationVector += new Vector3(0, moveDir.Y, 0);
                    break;

                case ManipulationType.TranslationZ:
                    translationVector += new Vector3(0, 0, moveDir.Z);
                    break;
                }
                OnUpdateSelfTransform();
                OnUpdateTargetMatrix();
            }
        }
        private void Manipulation_Mouse3DMove(object sender, MouseMove3DEventArgs e)
        {
            if (!isCaptured)
            {
                return;
            }

            Vector3 hit;

            if (currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal, out hit))
            {
                var rotationMatrix = GetRotationMatrix();

                var moveDir = hit - currentHit;
                currentHit = hit;

                moveDir = Vector3.TransformNormal(moveDir, rotationMatrix.Inverted());

                var sizeDir = Vector3.Zero;
                switch (manipulationType)
                {
                case ManipulationType.PosX:
                    moveDir  = new Vector3(moveDir.X, 0, 0);
                    sizeDir -= moveDir;
                    break;

                case ManipulationType.PosY:
                    moveDir  = new Vector3(0, moveDir.Y, 0);
                    sizeDir -= moveDir;
                    break;

                case ManipulationType.PosZ:
                    moveDir  = new Vector3(0, 0, moveDir.Z);
                    sizeDir -= moveDir;
                    break;

                case ManipulationType.SizeX:
                    sizeDir = new Vector3(moveDir.X, 0, 0);
                    moveDir = Vector3.Zero;
                    break;

                case ManipulationType.SizeY:
                    sizeDir = new Vector3(0, moveDir.Y, 0);
                    moveDir = Vector3.Zero;
                    break;

                case ManipulationType.SizeZ:
                    sizeDir = new Vector3(0, 0, moveDir.Z);
                    moveDir = Vector3.Zero;
                    break;
                }

                moveDir = Vector3.TransformNormal(moveDir, rotationMatrix);
                //dont re-transform sizeDir as it should always be axis aligned

                Position += moveDir;
                Size     += sizeDir;
            }
        }
Beispiel #3
0
 private void Viewport3DX_OnMouse3DMove(object sender, MouseMove3DEventArgs e)
 {
     if (prevPos != null && viewport3DX_IsMouseDown)
     {
     }
     prevPos = e.Position;
     throw new NotImplementedException();
 }
        private void Translation_Mouse3DMove(object sender, MouseMove3DEventArgs e)
        {
            if (!isCaptured)
            {
                return;
            }

            Vector3 hit;

            if (currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal, out hit))
            {
                var moveDir = hit - currentHit;
                currentHit = hit;

                if (LocalAxes)
                {
                    moveDir = Vector3.TransformNormal(moveDir, rotationMatrix.Inverted());
                }

                var moveVector = Vector3.Zero;
                switch (manipulationType)
                {
                case ManipulationType.TranslationX:
                    moveVector = new Vector3(moveDir.X, 0, 0);
                    break;

                case ManipulationType.TranslationY:
                    moveVector = new Vector3(0, moveDir.Y, 0);
                    break;

                case ManipulationType.TranslationZ:
                    moveVector = new Vector3(0, 0, moveDir.Z);
                    break;

                case ManipulationType.TranslationXY:
                    moveVector = new Vector3(moveDir.X, moveDir.Y, 0);
                    break;

                case ManipulationType.TranslationYZ:
                    moveVector = new Vector3(0, moveDir.Y, moveDir.Z);
                    break;

                case ManipulationType.TranslationXZ:
                    moveVector = new Vector3(moveDir.X, 0, moveDir.Z);
                    break;
                }

                if (LocalAxes)
                {
                    moveVector = Vector3.TransformNormal(moveVector, rotationMatrix);
                }

                translationVector += moveVector;

                OnUpdateSelfTransform();
                OnUpdateTargetMatrix();
            }
        }
        private void Rotation_Mouse3DMove(object sender, MouseMove3DEventArgs e)
        {
            if (!isCaptured)
            {
                return;
            }
            var hit      = currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal);
            var position = this.translationVector + centerOffset;

            if (hit.HasValue)
            {
                var v           = Vector3.Normalize(currentHit - position);
                var u           = Vector3.Normalize(hit.Value - position);
                var currentAxis = Vector3.Cross(u, v);
                var axis        = Vector3.UnitX;
                currentHit = hit.Value;
                switch (manipulationType)
                {
                case ManipulationType.RotationX:
                    axis = Vector3.UnitX;
                    break;

                case ManipulationType.RotationY:
                    axis = Vector3.UnitY;
                    break;

                case ManipulationType.RotationZ:
                    axis = Vector3.UnitZ;
                    break;
                }
                var sign  = -Vector3.Dot(axis, currentAxis);
                var theta = (float)(Math.Sign(sign) * Math.Asin(currentAxis.Length()));
                switch (manipulationType)
                {
                case ManipulationType.RotationX:
                    rotationMatrix *= Matrix.RotationX(theta);
                    break;

                case ManipulationType.RotationY:
                    rotationMatrix *= Matrix.RotationY(theta);
                    break;

                case ManipulationType.RotationZ:
                    rotationMatrix *= Matrix.RotationZ(theta);
                    break;
                }
                OnUpdateTargetMatrix();
            }
        }
        private void Scaling_Mouse3DMove(object sender, MouseMove3DEventArgs e)
        {
            if (!isCaptured)
            {
                return;
            }
            var hit = currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal);

            if (hit.HasValue)
            {
                var moveDir = hit.Value - currentHit;
                currentHit = hit.Value;
                var   orgAxis = Vector3.Zero;
                float scale   = 1;
                switch (manipulationType)
                {
                case ManipulationType.ScaleX:
                    orgAxis = Vector3.UnitX;
                    scale   = moveDir.X;
                    break;

                case ManipulationType.ScaleY:
                    orgAxis = Vector3.UnitY;
                    scale   = moveDir.Y;
                    break;

                case ManipulationType.ScaleZ:
                    orgAxis = Vector3.UnitZ;
                    scale   = moveDir.Z;
                    break;
                }
                var axisX = Vector3.TransformNormal(Vector3.UnitX, rotationMatrix);
                var axisY = Vector3.TransformNormal(Vector3.UnitY, rotationMatrix);
                var axisZ = Vector3.TransformNormal(Vector3.UnitZ, rotationMatrix);
                var dotX  = Vector3.Dot(axisX, orgAxis);
                var dotY  = Vector3.Dot(axisY, orgAxis);
                var dotZ  = Vector3.Dot(axisZ, orgAxis);
                scaleMatrix.M11 += scale * Math.Abs(dotX);
                scaleMatrix.M22 += scale * Math.Abs(dotY);
                scaleMatrix.M33 += scale * Math.Abs(dotZ);
                OnUpdateTargetMatrix();
            }
        }
        private void Scaling_Mouse3DMove(object sender, MouseMove3DEventArgs e)
        {
            if (!isCaptured)
            {
                return;
            }

            Vector3 hit;

            if (currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal, out hit))
            {
                var moveDir = hit - currentHit;
                currentHit = hit;

                if (LocalAxes)
                {
                    moveDir = Vector3.TransformNormal(moveDir, rotationMatrix.Inverted());
                }

                var   scaleVector = Vector3.Zero;
                float scale       = 1;
                switch (manipulationType)
                {
                case ManipulationType.ScaleX:
                    scaleVector = Vector3.UnitX;
                    scale       = moveDir.X;
                    break;

                case ManipulationType.ScaleY:
                    scaleVector = Vector3.UnitY;
                    scale       = moveDir.Y;
                    break;

                case ManipulationType.ScaleZ:
                    scaleVector = Vector3.UnitZ;
                    scale       = moveDir.Z;
                    break;
                }

                if ((target as IManipulatable)?.UniformScaling ?? UniformScaling)
                {
                    scaleVector = Vector3.One;
                }

                var axisX = Vector3.TransformNormal(Vector3.UnitX, rotationMatrix);
                var axisY = Vector3.TransformNormal(Vector3.UnitY, rotationMatrix);
                var axisZ = Vector3.TransformNormal(Vector3.UnitZ, rotationMatrix);
                var dotX  = Vector3.Dot(axisX, scaleVector);
                var dotY  = Vector3.Dot(axisY, scaleVector);
                var dotZ  = Vector3.Dot(axisZ, scaleVector);
                scaleMatrix.M11 += scale * Math.Abs(dotX);
                scaleMatrix.M22 += scale * Math.Abs(dotY);
                scaleMatrix.M33 += scale * Math.Abs(dotZ);

                if (AutoSizeScale)
                {
                    OnUpdateSelfTransform();
                }

                OnUpdateTargetMatrix();
            }
        }
        private void Rotation_Mouse3DMove(object sender, MouseMove3DEventArgs e)
        {
            if (!isCaptured)
            {
                return;
            }

            Vector3 hit;

            if (currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal, out hit))
            {
                var position    = translationVector + localCenterOffset;
                var v           = Vector3.Normalize(currentHit - position);
                var u           = Vector3.Normalize(hit - position);
                var currentAxis = Vector3.Cross(u, v);
                var axis        = Vector3.UnitX;
                currentHit = hit;

                if (LocalAxes)
                {
                    currentAxis = Vector3.TransformNormal(currentAxis, rotationMatrix.Inverted());
                }

                switch (manipulationType)
                {
                case ManipulationType.RotationX:
                    axis = Vector3.UnitX;
                    break;

                case ManipulationType.RotationY:
                    axis = Vector3.UnitY;
                    break;

                case ManipulationType.RotationZ:
                    axis = Vector3.UnitZ;
                    break;
                }

                var rotateAxis = axis;
                if (LocalAxes)
                {
                    rotateAxis = Vector3.TransformNormal(rotateAxis, rotationMatrix);
                }

                var sign  = -Vector3.Dot(axis, currentAxis);
                var theta = (float)(Math.Sign(sign) * Math.Asin(currentAxis.Length()));
                switch (manipulationType)
                {
                case ManipulationType.RotationX:
                    rotationMatrix *= Matrix.RotationAxis(rotateAxis, theta);
                    break;

                case ManipulationType.RotationY:
                    rotationMatrix *= Matrix.RotationAxis(rotateAxis, theta);
                    break;

                case ManipulationType.RotationZ:
                    rotationMatrix *= Matrix.RotationAxis(rotateAxis, theta);
                    break;
                }
                OnUpdateTargetMatrix();
            }
        }