示例#1
0
        public AppModel()
        {
            CubeTransform = InitializeCubeTransform();

            var inclinometer = Inclinometer.GetDefault();

            if (inclinometer != null)
            {
                inclinometer.ReportInterval  = 200;
                inclinometer.ReadingChanged += (o, e) => InclinationData.Value = e.Reading;
            }

            var orientationSensor = OrientationSensor.GetDefault();

            if (orientationSensor != null)
            {
                orientationSensor.ReportInterval  = 200;
                orientationSensor.ReadingChanged += (o, e) => OrientationData.Value = e.Reading;
            }

            RotationQuaternion       = OrientationData.Select(d => d.Quaternion.ToQuaternion()).ToReadOnlyReactiveProperty();
            RotationQuaternionString = RotationQuaternion.Select(q => $"{q.W:F2}; ({q.X:F2}, {q.Y:F2}, {q.Z:F2})").ToReadOnlyReactiveProperty();

            // Rotation is represented by a matrix, a quaternion or Euler angles (roll, pitch and yaw).
            RotationMatrix = OrientationData.Select(d => d.RotationMatrix.ToMatrix3D()).ToReadOnlyReactiveProperty();
            //RotationMatrix = RotationQuaternion.Select(q => q.ToMatrix3D()).ToReadOnlyReactiveProperty();
            //RotationMatrix = InclinationData.Select(i => i.ToMatrix3D()).ToReadOnlyReactiveProperty();

            // An inverse matrix represents the inverse rotation.
            RotationMatrix
            .ObserveOn(SynchronizationContext.Current)
            //.Subscribe(m => matrixTransform.Matrix = m);
            .Subscribe(m => { m.Invert(); matrixTransform.Matrix = m; });
        }
示例#2
0
        private void Viewport3D_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var el = (UIElement)sender;

            el.ReleaseMouseCapture();

            dragState.isTracking = false;

            var qv = RotationQuaternion.GetValue(QuaternionRotation3D.QuaternionProperty);
            var q  = (Quaternion)qv;

            MemoryManager.Instance.MemLib.writeMemory(MemoryManager.GetAddressString(CharacterDetailsViewModel.baseAddr, Settings.Instance.Character.Body.Base, Settings.Instance.Character.Body.Position.Rotation), "float", ((float)q.X).ToString());
            MemoryManager.Instance.MemLib.writeMemory(MemoryManager.GetAddressString(CharacterDetailsViewModel.baseAddr, Settings.Instance.Character.Body.Base, Settings.Instance.Character.Body.Position.Rotation2), "float", ((float)q.Y).ToString());
            MemoryManager.Instance.MemLib.writeMemory(MemoryManager.GetAddressString(CharacterDetailsViewModel.baseAddr, Settings.Instance.Character.Body.Base, Settings.Instance.Character.Body.Position.Rotation3), "float", ((float)q.Z).ToString());
            MemoryManager.Instance.MemLib.writeMemory(MemoryManager.GetAddressString(CharacterDetailsViewModel.baseAddr, Settings.Instance.Character.Body.Base, Settings.Instance.Character.Body.Position.Rotation4), "float", ((float)q.W).ToString());
        }
示例#3
0
        private void Viewport3D_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var el = (UIElement)sender;

            if (el.IsMouseCaptured)
            {
                var curPoint = e.MouseDevice.GetPosition(el);

                var delta = dragState.lastPoint - curPoint;
                var angle = Vector3D.DotProduct(new Vector3D(delta.X, -delta.Y, 0), new Vector3D(1, 1, 0));

                // Dragging the Left Mouse Button changes the pitch (facing up or down)
                // Dragging the Middle Mouse Button changes the yaw (facing left or right)
                // Dragging the Right Mouse Button changes the roll (leaning left or right)
                Vector3D axis;
                switch (dragState.mouseButton)
                {
                case MouseButton.Left:
                    axis = new Vector3D(1, 0, 0);
                    break;

                case MouseButton.Middle:
                    axis  = new Vector3D(0, 1, 0);
                    angle = -angle;
                    break;

                case MouseButton.Right:
                    axis  = new Vector3D(0, 0, 1);
                    angle = -angle;
                    break;

                default:
                    return;
                }

                // Applies the desired rotation first then the original rotation second.
                // Not the other way around (which would be rotationDelta * q). This makes it
                // more intuitive to adjust the roll, pitch, and yaw relative to the original
                // rotation.
                var rotationDelta = new Quaternion(axis, angle);
                var q             = RotationQuaternion.Quaternion * rotationDelta;
                RotationQuaternion.SetCurrentValue(QuaternionRotation3D.QuaternionProperty, q);
                dragState.lastPoint = curPoint;
            }
        }