File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1379,6 +1379,33 @@ public static YPR RotationMatrixToYPR(HmdMatrix34_t m)
13791379 pitch = Math . Atan2 ( 2 * q . x * q . w - 2 * q . y * q . z , 1 - 2 * sqx - 2 * sqz ) // bank
13801380 } ;
13811381 }
1382+
1383+ #region Measurement
1384+ /// <summary>
1385+ /// Returns the angle between two matrices in degrees.
1386+ /// </summary>
1387+ /// <param name="matOrigin"></param>
1388+ /// <param name="matTarget"></param>
1389+ /// <returns></returns>
1390+ public static double AngleBetween ( HmdMatrix34_t matOrigin , HmdMatrix34_t matTarget )
1391+ {
1392+ var vecOrigin = GetUnitVec3 ( ) ;
1393+ var vecTarget = GetUnitVec3 ( ) ;
1394+ vecOrigin = MultiplyVectorWithRotationMatrix ( vecOrigin , matOrigin ) ;
1395+ vecTarget = MultiplyVectorWithRotationMatrix ( vecTarget , matTarget ) ;
1396+ var vecSize = 1.0 ;
1397+ return Math . Acos ( DotProduct ( vecOrigin , vecTarget ) / Math . Pow ( vecSize , 2 ) ) * ( 180 / Math . PI ) ;
1398+ }
1399+
1400+ private static HmdVector3_t GetUnitVec3 ( ) {
1401+ return new HmdVector3_t ( ) { v0 = 0 , v1 = 0 , v2 = 1 } ;
1402+ }
1403+
1404+ private static double DotProduct ( HmdVector3_t v1 , HmdVector3_t v2 )
1405+ {
1406+ return v1 . v0 * v2 . v0 + v1 . v1 * v2 . v1 + v1 . v2 * v2 . v2 ;
1407+ }
1408+ #endregion
13821409 }
13831410
13841411 public static class BitmapUtils
You can’t perform that action at this time.
0 commit comments