public AppModel() { CubeTransform = InitializeCubeTransform(); FrontHand = LeapManager.FrameArrived .Select(f => f.Hands.Frontmost) .Select(h => h?.IsValid == true ? h : null) .ToReadOnlyReactiveProperty(); InnerProduct = FrontHand .Select(h => h != null ? h.Direction.Dot(h.PalmNormal) : double.NaN) .ToReadOnlyReactiveProperty(); EulerAngles_org = FrontHand .Select(h => h != null ? h.GetEulerAngles_org() : new EulerAngles()) .ToReadOnlyReactiveProperty(); EulerAngles = FrontHand .Select(h => h != null ? h.GetEulerAngles() : new EulerAngles()) .ToReadOnlyReactiveProperty(); //Rotation = EulerAngles_org Rotation = EulerAngles .Select(Rotation3DHelper.ToMatrix3D) .ToReadOnlyReactiveProperty(); Rotation .ObserveOn(SynchronizationContext.Current) .Subscribe(m => matrixTransform.Matrix = m); }
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; }); }