예제 #1
0
        public Point GetPixelPosition(Myo myo)
        {
            var orientation = myo.Orientation;
            var eulerAngles = Math3D.FromQuaternion(orientation) - absoluteTL[myo];
            eulerAngles = new Vector3F(eulerAngles.X, eulerAngles.Y, eulerAngles.Z);
            var vect = Math3D.DirectionalVector(eulerAngles);
            var position = Math3D.PixelFromVector(vect);

            if (position.X < 0)
            {
                position.X = 0;
            }
            else if (position.X > clientRes.Width)
            {
                position.X = clientRes.Width;
            }
            if (position.Y < 0)
            {
                position.Y = 0;
            }
            else if (position.Y > clientRes.Height)
            {
                position.Y = clientRes.Height;
            }
            return position;
        }
예제 #2
0
 public static Vector3F DirectionalVector(Vector3F v)
 {
     var vect = new Vector3F(0, 0, 1);
     var pitched = Pitch(vect, v.X);
     var yawed = Yaw(pitched, v.Z);
     return yawed;
 }
예제 #3
0
 public static Vector3F RotateY(Vector3F v1, double rad)
 {
     double x = (v1.Z * Math.Sin(rad)) + (v1.X * Math.Cos(rad));
     double y = v1.Y;
     double z = (v1.Z * Math.Cos(rad)) - (v1.X * Math.Sin(rad));
     return new Vector3F((float)x, (float)y, (float)z);
 }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GyroscopeDataEventArgs"/> class.
        /// </summary>
        /// <param name="myo">The Myo that raised the event. Cannot be <c>null</c>.</param>
        /// <param name="timestamp">The timestamp of the event.</param>
        /// <param name="gyroscopeData">The gyroscope data. Cannot be <c>null</c>.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The exception that is thrown when <paramref name="myo"/> or <paramref name="gyroscopeData"/> is null.
        /// </exception>
        public GyroscopeDataEventArgs(IMyo myo, DateTime timestamp, Vector3F gyroscopeData)
            : base(myo, timestamp)
        {
            Contract.Requires<ArgumentNullException>(myo != null, "myo");
            Contract.Requires<ArgumentNullException>(gyroscopeData != null, "gyroscopeData");

            this.Gyroscope = gyroscopeData;
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccelerometerDataEventArgs"/> class.
        /// </summary>
        /// <param name="myo">The Myo that raised the event. Cannot be <c>null</c>.</param>
        /// <param name="timestamp">The timestamp of the event.</param>
        /// <param name="accelerometerData">The accelerometer data. Cannot be <c>null</c>.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The exception that is thrown when <paramref name="myo"/> or <paramref name="accelerometerData"/> is null.
        /// </exception>
        public AccelerometerDataEventArgs(IMyo myo, DateTime timestamp, Vector3F accelerometerData)
            : base(myo, timestamp)
        {
            Contract.Requires<ArgumentNullException>(myo != null, "myo");
            Contract.Requires<ArgumentNullException>(accelerometerData != null, "accelerometerData");

            this.Accelerometer = accelerometerData;
        }
예제 #6
0
 public static Point PixelFromVector(Vector3F v)
 {
     var inverted = new Vector3F(0 - v.X, v.Y, v.Z);
     var distFromScreen = 4000;
     var ratio = (distFromScreen / inverted.Z);
     var screenX = ratio * inverted.X;
     var screenY = ratio * inverted.Y;
     return new Point((int)Math.Round(screenX), (int)Math.Round(screenY));
 }
예제 #7
0
 public void PointCenter()
 {
     float distFromScreen = -30f;
     Vector3F vec = new Vector3F(0, 0, 100);
     var ratio = (distFromScreen / vec.Z);
     var screenX = ratio * vec.X;
     var screenY = ratio * vec.Y;
     Expect(screenX, Is.EqualTo(0));
     Expect(screenY, Is.EqualTo(0));
 }
예제 #8
0
 public void PointTopLeft()
 {
     float distFromScreen = 30f;
     Vector3F vec = new Vector3F(3840, 2160, 60);
     var ratio = (distFromScreen / vec.Z);
     var screenX = ratio * vec.X;
     var screenY = ratio * vec.Y;
     Expect(screenX, Is.EqualTo(1920));
     Expect(screenY, Is.EqualTo(1080));
 }
예제 #9
0
 public void PointTopLeftFromLeft()
 {
     Point position = new Point(-960, 0);
     float distFromScreen = 50f;
     Vector3F vec = new Vector3F(0, 1080, 100);
     var ratio = (distFromScreen/vec.Z);
     var screenX = ratio * vec.X + position.X;
     var screenY = ratio * vec.Y + position.Y;
     Expect(screenX, Is.EqualTo(-960));
     Expect(screenY, Is.EqualTo(540));
 }
예제 #10
0
 public void PointCenterFromBottomRight()
 {
     Point position = new Point(960, -540);
     float distFromScreen = 300f;
     Vector3F vec = new Vector3F(-320, 180, 100);
     var ratio = (distFromScreen / vec.Z);
     var screenX = ratio * vec.X + position.X;
     var screenY = ratio * vec.Y + position.Y;
     Expect(screenX, Is.EqualTo(0));
     Expect(screenY, Is.EqualTo(0));
 }
예제 #11
0
 public void First()
 {
     Vector3F angles = new Vector3F(45, 45, 0);
     var pitchOp = Math.Sin(DegreeToRadian(angles.X));
     var pitchAdj = Math.Cos(DegreeToRadian(angles.X));
     var yawOp = Math.Sin(DegreeToRadian(angles.Y));
     var yawAdj = Math.Cos(DegreeToRadian(angles.Y));
     var vX = yawOp;
     var vY = pitchOp;
     var vZ = pitchAdj;
     var vect = new Vector3F((float)vX, (float)vY, (float)vZ);
     Expect(vect, Is.EqualTo(new Vector3F(0.5f, 0.5f, 0.5f)));
 }
        public void GetAccelerometer_ValidState_EqualsConstructorParameter()
        {
            // Setup
            var accelerometerData = new Vector3F(1, 2, 3);

            var args = new AccelerometerDataEventArgs(
                new Mock<IMyo>().Object,
                DateTime.UtcNow,
                accelerometerData);

            // Execute
            var result = args.Accelerometer;

            // Assert
            Assert.Equal(accelerometerData, result);
        }
예제 #13
0
        public void GetGyroscope_ValidState_EqualsConstructorParameter()
        {
            // Setup
            var gyroscopeData = new Vector3F(1, 2, 3);

            var args = new GyroscopeDataEventArgs(
                new Mock<IMyo>().Object,
                DateTime.UtcNow,
                gyroscopeData);

            // Execute
            var result = args.Gyroscope;

            // Assert
            Assert.Equal(gyroscopeData, result);
        }
예제 #14
0
        public void GetGyroscope_ValidParameters_ExpectedBridgeCalls()
        {
            // Setup
            var myoHandle = new IntPtr(123);
            var eventHandle = new IntPtr(789);

            var expectedResult = new Vector3F(10, 20, 30);

            var bridge = new Mock<IMyoDeviceBridge>(MockBehavior.Strict);
            bridge
                .Setup(x => x.EventGetGyroscope32(eventHandle, 0))
                .Returns(expectedResult.X);
            bridge
                .Setup(x => x.EventGetGyroscope32(eventHandle, 1))
                .Returns(expectedResult.Y);
            bridge
                .Setup(x => x.EventGetGyroscope32(eventHandle, 2))
                .Returns(expectedResult.Z);
            bridge
                .Setup(x => x.EventGetGyroscope64(eventHandle, 0))
                .Returns(expectedResult.X);
            bridge
                .Setup(x => x.EventGetGyroscope64(eventHandle, 1))
                .Returns(expectedResult.Y);
            bridge
                .Setup(x => x.EventGetGyroscope64(eventHandle, 2))
                .Returns(expectedResult.Z);

            var myoErrorHandlerDriver = new Mock<IMyoErrorHandlerDriver>(MockBehavior.Strict);

            var driver = MyoDeviceDriver.Create(
                myoHandle,
                bridge.Object,
                myoErrorHandlerDriver.Object);

            // Execute
            var result = driver.GetGyroscope(eventHandle);

            // Assert
            Assert.Equal(expectedResult.X, result.X);
            Assert.Equal(expectedResult.Y, result.Y);
            Assert.Equal(expectedResult.Z, result.Z);

            bridge.Verify(x => x.EventGetGyroscope32(eventHandle, 0), PlatformInvocation.Running32Bit ? Times.Once() : Times.Never());
            bridge.Verify(x => x.EventGetGyroscope32(eventHandle, 1), PlatformInvocation.Running32Bit ? Times.Once() : Times.Never());
            bridge.Verify(x => x.EventGetGyroscope32(eventHandle, 2), PlatformInvocation.Running32Bit ? Times.Once() : Times.Never());

            bridge.Verify(x => x.EventGetGyroscope64(eventHandle, 0), PlatformInvocation.Running32Bit ? Times.Never() : Times.Once());
            bridge.Verify(x => x.EventGetGyroscope64(eventHandle, 1), PlatformInvocation.Running32Bit ? Times.Never() : Times.Once());
            bridge.Verify(x => x.EventGetGyroscope64(eventHandle, 2), PlatformInvocation.Running32Bit ? Times.Never() : Times.Once());
        }
예제 #15
0
 public static Vector3F Pitch(Vector3F v1, double rad)
 {
     return RotateX(v1, rad);
 }
예제 #16
0
 public void PointTopLeftFuther()
 {
     float distFromScreen = 60f;
     Vector3F vec = new Vector3F(960, 540, 30);
     var ratio = (distFromScreen / vec.Z);
     var screenX = ratio * vec.X;
     var screenY = ratio * vec.Y;
     Expect(screenX, Is.EqualTo(1920));
     Expect(screenY, Is.EqualTo(1080));
 }
예제 #17
0
 public static Vector3F RoundTo90(Vector3F v)
 {
     return new Vector3F(RoundTo90(v.X), RoundTo90(v.Y), RoundTo90(v.Z));
 }
예제 #18
0
 public static Vector3F Yaw(Vector3F v1, double rad)
 {
     return RotateY(v1, rad);
 }