diff --git a/VRCFaceTracking.Core/Params/Expressions/UnifiedExpressionsParameters.cs b/VRCFaceTracking.Core/Params/Expressions/UnifiedExpressionsParameters.cs index 6dd683f4..24e13618 100644 --- a/VRCFaceTracking.Core/Params/Expressions/UnifiedExpressionsParameters.cs +++ b/VRCFaceTracking.Core/Params/Expressions/UnifiedExpressionsParameters.cs @@ -28,6 +28,10 @@ private static (string paramName, Parameter paramLiteral)[] IsEyeParameter(IPara new EParam("v2/Eye", exp => exp.Eye.Combined().Gaze), new EParam("v2/EyeLeft", exp => exp.Eye.Left.Gaze), new EParam("v2/EyeRight", exp => exp.Eye.Right.Gaze), + + new EParam("v2/EyeLinear", exp => exp.Eye.Combined().Gaze.ToNormalized()), + new EParam("v2/EyeLeftLinear", exp => exp.Eye.Left.Gaze.ToNormalized()), + new EParam("v2/EyeRightLinear", exp => exp.Eye.Right.Gaze.ToNormalized()), // Use when tracking interface is sending verbose gaze data. new NativeParameter(exp => @@ -311,4 +315,4 @@ private static IEnumerable GetAllBaseSimpleExpressions() => new EParam("v2/" + simple.ToString(), exp => GetSimpleShape(exp, simple), 0.0f)); private static float GetSimpleShape(UnifiedTrackingData data, UnifiedSimpleExpressions expression) => UnifiedSimplifier.ExpressionMap[expression].Invoke(data); -} \ No newline at end of file +} diff --git a/VRCFaceTracking.Core/Types/Vector2.cs b/VRCFaceTracking.Core/Types/Vector2.cs index d327bf13..a600584f 100644 --- a/VRCFaceTracking.Core/Types/Vector2.cs +++ b/VRCFaceTracking.Core/Types/Vector2.cs @@ -48,5 +48,26 @@ public float ToYaw() public float ToPitch() => -(float)(Math.Atan(y) * (180 / Math.PI)); + + /// + /// Converts the Tobii normalized eye value to a normalized yaw value from -1 to 1, representing -45 to 45 degrees. + /// + public float ToNormalizedYaw() + => Remap(ToYaw(), -45, 45, -1, 1); + + /// + /// Converts the Tobii normalized eye value to a normalized pitch value from -1 to 1, representing -45 to 45 degrees. + /// + public float ToNormalizedPitch() + => Remap(ToPitch(), -45, 45, -1, 1); + + //return a remade vector2 that represents the remapped values + public Vector2 ToNormalized() + => new Vector2(ToNormalizedYaw(), ToNormalizedPitch()); + + private float Remap(float source, float sourceFrom, float sourceTo, float targetFrom, float targetTo) + { + return targetFrom + (source-sourceFrom)*(targetTo-targetFrom)/(sourceTo-sourceFrom); + } } -} \ No newline at end of file +}