Exemple #1
0
        void mouseZone_MouseMove(object sender, MouseEventArgs e)
        {
            if (IsActive)
            {
                _viewport.Cursor = Cursors.None;

                var centerOfViewport  = _viewport.PointToScreen(new Point(_viewport.ActualWidth / 2, _viewport.ActualHeight / 2));
                var relativePos       = e.MouseDevice.GetPosition(_viewport);
                var actualRelativePos = new Point(relativePos.X - _viewport.ActualWidth / 2, _viewport.ActualHeight / 2 - relativePos.Y);
                var dx = actualRelativePos.X;
                var dy = actualRelativePos.Y;
                _yaw   += dx;
                _pitch += dy;

                // Rotate
                RawRotation = QuaternionHelper.EulerAnglesInDegToQuaternion(_pitch * Sensitivity * 0.1, _yaw * Sensitivity * 0.1, 0);
                UpdatePositionAndRotation();

                // Set mouse position back to the center of the viewport in screen coordinates
                MouseUtilities.SetPosition(centerOfViewport);
            }
            else
            {
                _viewport.Cursor = Cursors.Arrow;
            }
        }
        public void AngleIntegrity()
        {
            var q      = QuaternionHelper.EulerAnglesInDegToQuaternion(30, 0, 0);
            var angles = QuaternionHelper.QuaternionToEulerAnglesInDeg(q);

            Assert.That(angles.X, Is.EqualTo(30));
        }
        public void VerifyQuaternionToEulerIntegrity()
        {
            var q1 = QuaternionHelper.EulerAnglesInDegToQuaternion(30, 10, 25);
            var e  = QuaternionHelper.QuaternionToEulerAnglesInDeg(q1);
            var q2 = QuaternionHelper.EulerAnglesInDegToQuaternion(e.Y, e.X, e.Z);

            Assert.That(q1, Is.EqualTo(q2));
        }
        public YEI3SpacePlugin()
        {
            Name = "YEI 3-Space";
            var tracker = new YEI3SpaceTracker()
            {
                PositionScaleFactor = ConfigHelper.ParseDouble(Config.AppSettings.Settings["PositionScaleFactor"].Value),
                RotationOffset      = QuaternionHelper.EulerAnglesInDegToQuaternion(ConfigHelper.ParseVector3D(Config.AppSettings.Settings["RotationOffset"].Value)),
            };

            Content = tracker;
            Panel   = new YEI3SpacePanel(tracker);
        }
        public RazerHydraPlugin()
        {
            Name = "Razer Hydra";
            var tracker = new RazerHydraTracker
            {
                PositionScaleFactor = ConfigHelper.ParseDouble(Config.AppSettings.Settings["PositionScaleFactor"].Value),
                RotationOffset      = QuaternionHelper.EulerAnglesInDegToQuaternion(ConfigHelper.ParseVector3D(Config.AppSettings.Settings["RotationOffset"].Value)),
                FilterEnabled       = bool.Parse(Config.AppSettings.Settings["FilterEnabled"].Value),
            };

            Content = tracker;
            Panel   = new RazerHydraPanel(tracker);
        }
        public VrpnPlugin()
        {
            Name = "VRPN";
            var tracker = new VrpnTracker(
                Config.AppSettings.Settings["TrackerAddress"].Value,
                Config.AppSettings.Settings["ButtonAddress"].Value)
            {
                PositionScaleFactor = ConfigHelper.ParseDouble(Config.AppSettings.Settings["PositionScaleFactor"].Value),
                RotationOffset      = QuaternionHelper.EulerAnglesInDegToQuaternion(ConfigHelper.ParseVector3D(Config.AppSettings.Settings["RotationOffset"].Value)),
            };

            Content = tracker;
            Panel   = new VrpnPanel(tracker);
        }
        void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            RawRotation = QuaternionHelper.EulerAnglesInDegToQuaternion(
                e.WiimoteState.MotionPlusState.Values.Y,
                e.WiimoteState.MotionPlusState.Values.X,
                e.WiimoteState.MotionPlusState.Values.Z);

            if (e.WiimoteState.ButtonState.Plus)
            {
                Dispatcher.Invoke((Action)(Calibrate));
            }

            Dispatcher.Invoke((Action)(UpdatePositionAndRotation));
        }
        public override void UpdateCurrentFrame(int frame)
        {
            var data = DeshakerData.FirstOrDefault(d => d.FrameNumber == frame);

            if (data == null)
            {
                return;
            }

            var scaledTranslation = new Vector3D(-data.PanX, -data.PanY, -data.Zoom) / 10000;

            Logger.Instance.Info(string.Format("Translation: ({0},{1},{2})", scaledTranslation.X, scaledTranslation.Y, scaledTranslation.Z));
            Translation = new Vector3D(scaledTranslation.X * TranslationFactor, scaledTranslation.Y * TranslationFactor, scaledTranslation.Z * ZoomFactor);
            Rotation    = QuaternionHelper.EulerAnglesInDegToQuaternion(0, 0, data.Rotation * RotationFactor);
        }
        void data_timer_Tick(object sender, EventArgs e)
        {
            try
            {
                float x, y, z, pitch, yaw, roll;
                var   result = TIR_Update(&x, &y, &z, &pitch, &yaw, &roll);
                ThrowErrorOnResult(result, "Error while getting data from the Track IR");

                RawPosition = new Vector3D(-x, -y, z);
                RawRotation = QuaternionHelper.EulerAnglesInDegToQuaternion(
                    -(yaw - Int16.MaxValue) / UnitsByDeg,
                    -(pitch - Int16.MaxValue) / UnitsByDeg,
                    (roll - Int16.MaxValue) / UnitsByDeg);

                UpdatePositionAndRotation();
            }
            catch (Exception exc)
            {
                Logger.Instance.Error(exc.Message, exc);
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var coord = (double)value;

            var axis = parameter.ToString().ToLower();

            switch (axis)
            {
            case "x":
                return(QuaternionHelper.EulerAnglesInDegToQuaternion(coord, 0, 0));

            case "y":
                return(QuaternionHelper.EulerAnglesInDegToQuaternion(0, coord, 0));

            case "z":
                return(QuaternionHelper.EulerAnglesInDegToQuaternion(0, 0, coord));

            default:
                throw new Exception("Invalid parameter in QuaternionToCoordConverter.");
            }
        }