Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vector2>(exp =>
Expand Down Expand Up @@ -311,4 +315,4 @@ private static IEnumerable<EParam> 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);
}
}
23 changes: 22 additions & 1 deletion VRCFaceTracking.Core/Types/Vector2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,26 @@ public float ToYaw()

public float ToPitch()
=> -(float)(Math.Atan(y) * (180 / Math.PI));

/// <summary>
/// Converts the Tobii normalized eye value to a normalized yaw value from -1 to 1, representing -45 to 45 degrees.
/// </summary>
public float ToNormalizedYaw()
=> Remap(ToYaw(), -45, 45, -1, 1);

/// <summary>
/// Converts the Tobii normalized eye value to a normalized pitch value from -1 to 1, representing -45 to 45 degrees.
/// </summary>
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);
}
}
}
}