I wrote a pretty ugly hack for the ViewCubeVisual3D

Feb 17, 2014 at 8:16 PM
It snaps to the closes 90° increment and then rotates 90° on each single click. The rotation would be nicer with arrows outside the cube. Not nice enough for a pull request, still useful imo.
        private void FaceMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!this.IsEnabled)
            {
                return;
            }

            var faceNormal = this.faceNormals[sender];
            var faceUp = this.faceUpVectors[sender];

            var lookDirection = -faceNormal;
            var upDirection = faceUp;
            lookDirection.Normalize();
            upDirection.Normalize();

            // Double-click reverses the look direction
            if (e.ClickCount == 2)
            {
                lookDirection *= -1;
                if (upDirection != this.ModelUpDirection)
                {
                    upDirection *= -1;
                }
            }

            if (this.Viewport != null)
            {
                var camera = this.Viewport.Camera as ProjectionCamera;
                if (camera != null)
                {
                    var target = camera.Position + camera.LookDirection;
                    double distance = camera.LookDirection.Length;
                    lookDirection *= distance;
                    var newPosition = target - lookDirection;
                    Vector3D crossProduct = Vector3D.CrossProduct(upDirection, lookDirection);
                    var vector3Ds = new[] { upDirection, -1*upDirection, crossProduct, -1*crossProduct };
                    double dp = 95;
                    foreach (var v in vector3Ds)
                    {
                        double tdp =Vector3D.AngleBetween(camera.UpDirection, v);
                        if (tdp < dp)
                        {
                            dp = tdp;
                            upDirection = v;
                        }
                    }
                    if (Vector3D.AngleBetween(upDirection, camera.UpDirection)  < 0.1)
                    {
                        var rot = new RotateTransform3D(new AxisAngleRotation3D(
                                  lookDirection, 90));
                        upDirection = rot.Transform(upDirection);
                    }
                    CameraHelper.AnimateTo(camera, newPosition, lookDirection, upDirection, 500);
                }
            }

            e.Handled = true;
            this.OnClicked(lookDirection, upDirection);
        }
Coordinator
Feb 18, 2014 at 7:37 AM
thanks for sharing your code - I will have a look at this when I get time :)