예제 #1
0
        public float GetRoll()
        {
            FloatVectorStruct ypr = new FloatVectorStruct();

            GetYawPitchRoll(ypr);
            return(ypr.z);
        }
예제 #2
0
        void GetYawPitchRoll(FloatVectorStruct ypr)
        {
            FloatVectorStruct gravity = new FloatVectorStruct();

            GetGravity(ypr, this);
            GetYawPitchRoll(this, gravity, ypr);
        }
예제 #3
0
 static void GetYawPitchRoll(Quaternion q, FloatVectorStruct gravity, FloatVectorStruct ypr)
 {
     // yaw: (about Z axis)
     ypr.x = (float)Math.Atan2(2 * q.x * q.y - 2 * q.w * q.z, 2 * q.w * q.w + 2 * q.x * q.x - 1);
     // pitch: (node up/down, about X axis)
     ypr.y = (float)Math.Atan(gravity.y / Math.Sqrt(gravity.x * gravity.x + gravity.z * gravity.z));
     // roll: (tilt left/right, about Y axis)
     ypr.z = (float)Math.Atan(gravity.x / Math.Sqrt(gravity.y * gravity.y + gravity.z * gravity.z));
 }
예제 #4
0
 static void GetGravity(FloatVectorStruct v, Quaternion q)
 {
     v.x = 2 * (q.x * q.z - q.w * q.y);
     v.y = 2 * (q.w * q.x + q.y * q.z);
     v.z = q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z;
 }