コード例 #1
0
    private Quaternion calculateChangeForGyro(GyroscopeDataEventArgs prev, GyroscopeDataEventArgs effective)
    {
        TimeSpan dt = effective.Timestamp.Subtract(prev.Timestamp);

        Thalmic.Myo.Vector3 avg = (effective.Gyroscope + prev.Gyroscope) * .5f;

        double dts = dt.TotalSeconds;

        double rx = avg.X * dts;
        double ry = avg.Y * dts;
        double rz = avg.Z * dts;

        double  magnitude = Math.Sqrt(rx * rx + ry * ry + rz * rz);
        Vector3 myoAxis   = new Vector3((float)(rx / magnitude), (float)(ry / magnitude), (float)(rz / magnitude));
        Vector3 axis      = new Vector3(-myoAxis.y, myoAxis.z, myoAxis.x);
        float   angle     = (float)magnitude;

        // Unity is left handed. therefore the angle should be reversed.
        Quaternion dq = Quaternion.AngleAxis(-angle, axis);

        return(dq);
    }
コード例 #2
0
 void myo_OnGyroscopeData(object sender, Thalmic.Myo.GyroscopeDataEventArgs e)
 {
     lock (_lock) {
         _myoGyroscope = e.Gyroscope;
     }
 }
コード例 #3
0
 void myo_OnAccelerometerData(object sender, Thalmic.Myo.AccelerometerDataEventArgs e)
 {
     lock (_lock) {
         _myoAccelerometer = e.Accelerometer;
     }
 }
コード例 #4
0
 static private Vector3 myoToUnity(Thalmic.Myo.Vector3 myo)
 {
     return(new Vector3(-myo.Y, myo.Z, myo.X));
 }