Esempio n. 1
0
        public override void OnMouseUp(MouseEventArgs mouseEvent)
        {
            base.OnMouseUp(mouseEvent);

            trackballTumbleWidgetExtended.EndRotateAroundOrigin();

            if (mouseEvent.Button != MouseButtons.Left)
            {
                return;
            }

            // Make sure we don't use the trace data before it is ready
            if (mouseDownPosition == mouseEvent.Position &&
                cubeTraceData != null)
            {
                Ray           ray  = world.GetRayForLocalBounds(mouseEvent.Position);
                IntersectInfo info = cubeTraceData.GetClosestIntersection(ray);

                if (info != null)
                {
                    var hitData     = GetHitData(info.HitPosition);
                    var normalAndUp = GetDirectionForFace(hitData);

                    var look = Matrix4X4.LookAt(Vector3.Zero, normalAndUp.normal, normalAndUp.up);

                    trackballTumbleWidgetExtended.AnimateRotation(look);
                }
            }

            object3DControlLayer.Focus();
        }
        public override void OnMouseUp(MouseEventArgs mouseEvent)
        {
            base.OnMouseUp(mouseEvent);

            if (mouseEvent.Button != MouseButtons.Left)
            {
                return;
            }

            // Make sure we don't use the trace data before it is ready
            if (mouseDownPosition == mouseEvent.Position &&
                cubeTraceData != null)
            {
                Ray           ray  = world.GetRayForLocalBounds(mouseEvent.Position);
                IntersectInfo info = cubeTraceData.GetClosestIntersection(ray);

                if (info != null)
                {
                    var hitData     = GetHitData(info.HitPosition);
                    var normalAndUp = GetDirectionForFace(hitData);

                    var look = Matrix4X4.LookAt(Vector3.Zero, normalAndUp.normal, normalAndUp.up);

                    var start = new Quaternion(object3DControlLayer.World.RotationMatrix);
                    var end   = new Quaternion(look);

                    Task.Run(() =>
                    {
                        // TODO: stop any spinning happening in the view
                        double duration = .25;
                        var timer       = Stopwatch.StartNew();
                        var time        = timer.Elapsed.TotalSeconds;

                        while (time < duration)
                        {
                            var current = Quaternion.Slerp(start, end, time / duration);
                            UiThread.RunOnIdle(() =>
                            {
                                object3DControlLayer.World.RotationMatrix = Matrix4X4.CreateRotation(current);
                                Invalidate();
                            });
                            time = timer.Elapsed.TotalSeconds;
                            Thread.Sleep(10);
                        }

                        object3DControlLayer.World.RotationMatrix = Matrix4X4.CreateRotation(end);
                        Invalidate();
                    });
                }
            }

            object3DControlLayer.Focus();
        }