Skip to content

Commit

Permalink
exposed SO fields in WR.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitGeslain committed Mar 4, 2024
1 parent 3912bfc commit 0462c93
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,12 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 7088029602675669135, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
propertyPath: _technique
value: 5
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7088029602675669135, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
propertyPath: scene.parameters
value:
objectReference: {fileID: 11400000, guid: c39097e50bc3898498d2edf378be3a21, type: 2}
- target: {fileID: 7088029602675669135, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
propertyPath: scene.virtualHead
value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public record Scene() {
[Ignore] public float previousRedirection;
[Ignore] public Vector3 strategyDirection;

[Ignore] public ParametersToolkit parameters;

/// <summary>
/// The position of the virtual limb is given by <c>physicalHand.position + Redirection</c>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static float GetRedirection(Scene scene) {
float angleToTarget = scene.GetHeadAngleToTarget();
angleToTarget = (angleToTarget > 180f)? angleToTarget - 360f : angleToTarget;

return Mathf.Abs(angleToTarget) > Toolkit.Instance.parameters.RotationalError
? Mathf.Sign(angleToTarget) * Toolkit.Instance.parameters.OverTimeRotation * Time.deltaTime
return Mathf.Abs(angleToTarget) > scene.parameters.RotationalError
? Mathf.Sign(angleToTarget) * scene.parameters.OverTimeRotation * Time.deltaTime
: 0f;
}

Expand All @@ -42,8 +42,8 @@ public static float GetRedirectionReset(Scene scene) {
angleToTarget = (angleToTarget > 180f)? angleToTarget - 360f : angleToTarget;

Debug.Log(angleToTarget);
return Mathf.Abs(angleToTarget) > Toolkit.Instance.parameters.RotationalError
? - Mathf.Sign(angleToTarget) * Toolkit.Instance.parameters.OverTimeRotation * Time.deltaTime
return Mathf.Abs(angleToTarget) > scene.parameters.RotationalError
? - Mathf.Sign(angleToTarget) * scene.parameters.OverTimeRotation * Time.deltaTime
: 0f;
}
}
Expand All @@ -62,11 +62,11 @@ public static float GetRedirection(Scene scene) {
float angleToTarget = scene.GetHeadAngleToTarget();
float instantRotation = scene.GetHeadInstantRotationY();

if (Mathf.Abs(angleToTarget) > Toolkit.Instance.parameters.RotationalError && Mathf.Abs(instantRotation) > Toolkit.Instance.parameters.RotationThreshold) {
Debug.Log($"{instantRotation} - {instantRotation * ((Mathf.Sign(scene.GetHeadAngleToTarget()) != Mathf.Sign(instantRotation))? Toolkit.Instance.parameters.GainsRotational.opposite - 1 : Toolkit.Instance.parameters.GainsRotational.same - 1)}");
if (Mathf.Abs(angleToTarget) > scene.parameters.RotationalError && Mathf.Abs(instantRotation) > scene.parameters.RotationThreshold) {
Debug.Log($"{instantRotation} - {instantRotation * ((Mathf.Sign(scene.GetHeadAngleToTarget()) != Mathf.Sign(instantRotation))? scene.parameters.GainsRotational.opposite - 1 : scene.parameters.GainsRotational.same - 1)}");
return instantRotation * ((Mathf.Sign(scene.GetHeadAngleToTarget()) != Mathf.Sign(instantRotation))
? Toolkit.Instance.parameters.GainsRotational.opposite - 1
: Toolkit.Instance.parameters.GainsRotational.same - 1);
? scene.parameters.GainsRotational.opposite - 1
: scene.parameters.GainsRotational.same - 1);
}
return 0f;
}
Expand All @@ -75,10 +75,10 @@ public static float GetRedirectionReset(Scene scene) {
float angleToTarget = scene.HeadToHeadRedirection.eulerAngles.y;
float instantRotation = scene.GetHeadInstantRotationY();

if (Mathf.Abs(instantRotation) > Toolkit.Instance.parameters.RotationThreshold && Mathf.Abs(angleToTarget) > Toolkit.Instance.parameters.RotationalError) {
if (Mathf.Abs(instantRotation) > scene.parameters.RotationThreshold && Mathf.Abs(angleToTarget) > scene.parameters.RotationalError) {
return instantRotation * ((Mathf.Sign(scene.GetHeadAngleToTarget()) != Mathf.Sign(instantRotation))
? Toolkit.Instance.parameters.GainsRotational.opposite - 1
: Toolkit.Instance.parameters.GainsRotational.same - 1);
? scene.parameters.GainsRotational.opposite - 1
: scene.parameters.GainsRotational.same - 1);
}
return 0f;
}
Expand All @@ -97,12 +97,12 @@ public override void Redirect(Scene scene) {
public static float GetRedirection(Scene scene) {
float instantTranslation = scene.GetHeadInstantTranslationForward().magnitude;

return instantTranslation > Toolkit.Instance.parameters.WalkingThreshold * Time.deltaTime
? Mathf.Sign(Vector3.Cross(scene.physicalHead.forward, scene.forwardTarget).y) * instantTranslation * CurvatureRadiusToRotationRate()
return instantTranslation > scene.parameters.WalkingThreshold * Time.deltaTime
? Mathf.Sign(Vector3.Cross(scene.physicalHead.forward, scene.forwardTarget).y) * instantTranslation * CurvatureRadiusToRotationRate(scene)
: 0f;
}

public static float CurvatureRadiusToRotationRate() => 180f / (Mathf.PI * Toolkit.Instance.parameters.CurvatureRadius);
public static float CurvatureRadiusToRotationRate(Scene scene) => 180f / (Mathf.PI * scene.parameters.CurvatureRadius);
}


Expand Down Expand Up @@ -169,12 +169,12 @@ public float GetRedirection(Scene scene) {
}

private float ApplyDampening(Scene scene, float angle) {
float dampenedAngle = angle * Mathf.Sin(Mathf.Min(scene.GetHeadAngleToTarget() / Toolkit.Instance.parameters.DampeningRange, 1f) * Mathf.PI/2);
float dampenedAngleDistance = dampenedAngle * Mathf.Min(scene.GetHeadToTargetDistance() / Toolkit.Instance.parameters.DampeningDistanceThreshold, 1f);
return (scene.GetHeadToTargetDistance() < Toolkit.Instance.parameters.DampeningDistanceThreshold)? dampenedAngleDistance : dampenedAngle;
float dampenedAngle = angle * Mathf.Sin(Mathf.Min(scene.GetHeadAngleToTarget() / scene.parameters.DampeningRange, 1f) * Mathf.PI/2);
float dampenedAngleDistance = dampenedAngle * Mathf.Min(scene.GetHeadToTargetDistance() / scene.parameters.DampeningDistanceThreshold, 1f);
return (scene.GetHeadToTargetDistance() < scene.parameters.DampeningDistanceThreshold)? dampenedAngleDistance : dampenedAngle;
}

public float ApplySmoothing(Scene scene, float angle) => (1 - Toolkit.Instance.parameters.SmoothingFactor) * scene.previousRedirection + Toolkit.Instance.parameters.SmoothingFactor * angle;
public float ApplySmoothing(Scene scene, float angle) => (1 - scene.parameters.SmoothingFactor) * scene.previousRedirection + scene.parameters.SmoothingFactor * angle;
}

/// <summary>
Expand All @@ -183,7 +183,7 @@ private float ApplyDampening(Scene scene, float angle) {
/// </summary>
public class Steinicke2008Translational: WorldRedirectionTechnique {
public override void Redirect(Scene scene) {
scene.virtualHead.Translate(Vector3.Scale(scene.GetHeadInstantTranslation(), Toolkit.Instance.parameters.GainsTranslational - Vector3.one), relativeTo: Space.World);
scene.virtualHead.Translate(Vector3.Scale(scene.GetHeadInstantTranslation(), scene.parameters.GainsTranslational - Vector3.one), relativeTo: Space.World);
CopyHeadAndLimbTransform(scene);
}
}
Expand All @@ -203,12 +203,12 @@ public static float GetRedirection(Scene scene) {
float angleBetweenTargets = Vector3.SignedAngle(Vector3.ProjectOnPlane(scene.physicalTarget.position - scene.origin.position, Vector3.up), scene.virtualTarget.position - scene.origin.position, Vector3.up);
float angleBetweenHeads = Vector3.SignedAngle(Vector3.ProjectOnPlane(scene.physicalHead.forward, Vector3.up), scene.virtualHead.forward, Vector3.up);

if (Mathf.Abs(angleBetweenTargets - angleBetweenHeads) > Toolkit.Instance.parameters.RotationalError) {
if (Mathf.Abs(angleBetweenTargets - angleBetweenHeads) > scene.parameters.RotationalError) {
float angle = angleBetweenTargets - angleBetweenHeads;
float instantRotation = scene.GetHeadInstantRotationY();

if (Mathf.Abs(instantRotation) > Toolkit.Instance.parameters.RotationThreshold && Mathf.Abs(angle) > Toolkit.Instance.parameters.RotationalError) {
var gain = (Mathf.Sign(angle) != Mathf.Sign(instantRotation)) ? Toolkit.Instance.parameters.GainsRotational.same : Toolkit.Instance.parameters.GainsRotational.opposite;
if (Mathf.Abs(instantRotation) > scene.parameters.RotationThreshold && Mathf.Abs(angle) > scene.parameters.RotationalError) {
var gain = (Mathf.Sign(angle) != Mathf.Sign(instantRotation)) ? scene.parameters.GainsRotational.same : scene.parameters.GainsRotational.opposite;
var bound = Mathf.Abs(gain * instantRotation);
return Mathf.Clamp(angle, -bound, bound);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class WorldRedirectionEditor : Editor {
SerializedProperty applySmoothing;
SerializedProperty redirect;
SerializedProperty direction;
SerializedProperty parameters;
SerializedObject parametersObject;

readonly string[] strategyTechniques = { "Razzaque2001OverTimeRotation", "Razzaque2001Rotational", "Razzaque2001Curvature", "Razzaque2001Hybrid" };
readonly string[] targetsStrategies = { "SteerToCenter", "SteerToMultipleTargets" };
Expand All @@ -46,6 +48,9 @@ private void OnEnable() {
applySmoothing = serializedObject.FindProperty("scene.applySmoothing");
redirect = serializedObject.FindProperty("redirect");
direction = serializedObject.FindProperty("scene.strategyDirection");

parameters = serializedObject.FindProperty("scene.parameters");
parametersObject = new SerializedObject(parameters.objectReferenceValue);
}

public override void OnInspectorGUI() {
Expand All @@ -54,6 +59,7 @@ public override void OnInspectorGUI() {
GUI.enabled = true;

serializedObject.Update();
parametersObject.Update();

EditorGUILayout.PropertyField(technique, new GUIContent ("Technique"));
if (strategyTechniques.Contains(technique.enumNames[technique.enumValueIndex])) {
Expand All @@ -77,21 +83,54 @@ public override void OnInspectorGUI() {
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Technique Parameters", EditorStyles.boldLabel);

EditorGUILayout.PropertyField(parameters, new GUIContent("Parameters"));

// WorldRedirection someComponent = target as WorldRedirection;
// // if (someComponent == null)
// // someComponent = CreateInstance<ParametersToolkit>();
// Debug.Log(someComponent.scene);
// Debug.Log(someComponent.scene.parameters);
// Debug.Log(someComponent.scene.parameters.OverTimeRotation);

if (new string[] {"Razzaque2001OverTimeRotation", "Razzaque2001Hybrid"}.Contains(technique.enumNames[technique.enumValueIndex])) {
EditorGUILayout.PropertyField(parametersObject.FindProperty("OverTimeRotation"), new GUIContent("Over Time Rotation Rate"));
}
if (new string[] { "Razzaque2001Rotational", "Razzaque2001Hybrid" }.Contains(technique.enumNames[technique.enumValueIndex])) {
EditorGUILayout.PropertyField(parametersObject.FindProperty("GainsRotational"), new GUIContent("Rotational Gains"));
}
if (new string[] { "Razzaque2001Curvature", "Razzaque2001Hybrid" }.Contains(technique.enumNames[technique.enumValueIndex])) {
EditorGUILayout.PropertyField(parametersObject.FindProperty("CurvatureRadius"), new GUIContent("Curvature Radius"));
}
if (technique.enumNames[technique.enumValueIndex] == "Razzaque2001Hybrid") {
// TODO: Radio list to choose which techniques to activate
}
// if (technique.enumNames[technique.enumValueIndex] == "Azmandian2016World") {
// EditorGUILayout.PropertyField(parametersObject.FindProperty("GainsRotational"), new GUIContent("Gains Rotational"));
// }
if (technique.enumNames[technique.enumValueIndex] == "Steinicke2008Translational") {
EditorGUILayout.PropertyField(parametersObject.FindProperty("GainsTranslational"), new GUIContent("Translational Gains"));
}

EditorGUILayout.PropertyField(redirect, new GUIContent("Redirect"));

// Hides targets, dampening and smoothing if
if (strategyTechniques.Contains(technique.enumNames[technique.enumValueIndex])) {
if (targetsStrategies.Contains(strategy.enumNames[strategy.enumValueIndex])) {
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Strategy Parameters", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(targetsScene, new GUIContent ("Targets"));
EditorGUILayout.PropertyField(applyDampening, new GUIContent("Apply Dampening"));
EditorGUILayout.PropertyField(applySmoothing, new GUIContent("Apply Smoothing"));
} else if (strategy.enumNames[strategy.enumValueIndex] == "SteerInDirection") {
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Strategy Parameters", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(direction, new GUIContent ("Direction"));
}

}

serializedObject.ApplyModifiedProperties();
parametersObject.ApplyModifiedProperties();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e581f0f440a7c904aa70c37c0de08866, type: 3}
m_Name: Literature Parameters
m_Name: High Parameters (Literature)
m_EditorClassIdentifier:
HorizontalAngles:
left: -4.38
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e581f0f440a7c904aa70c37c0de08866, type: 3}
m_Name: Recommended Parameters
m_Name: Low Parameters
m_EditorClassIdentifier:
HorizontalAngles:
left: -4.38
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e581f0f440a7c904aa70c37c0de08866, type: 3}
m_Name: Medium Parameters (Recommended)
m_EditorClassIdentifier:
HorizontalAngles:
left: -4.38
right: 3.81
VerticalAngles:
up: 4.48
down: -4.4
Gain:
faster: 1.07
slower: 0.88
RedirectionBuffer: 0.1
MaxRedirectionThreshold: 0.5
GoGoCoefficient: 1
GoGoActivationDistance: 0.167
ResetRedirectionCoeff: 0.087
RotationalError: 0.5
RotationThreshold: 0
WalkingThreshold: 0.2
DampeningDistanceThreshold: 1.25
DampeningRange: 1.57
SmoothingFactor: 0.2
OverTimeRotation: 1
GainsTranslational: {x: 1, y: 1, z: 1}
GainsRotational:
same: 1.05
opposite: 0.975
CurvatureRadius: 15
a: {x: 0, y: 0, z: 0}
SwampSquareLength: 0.25
SwampCDRatio: 0.75
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ParametersToolkit: ScriptableObject {
[Tooltip("Coefficient that controls the amount of redirection to remove according to the real hand translation when selecting the ResetRedirection technique. Value is in XXXX.")] // TODO check this
public float ResetRedirectionCoeff = 0.087f;



[Header("World Warping")]
[Tooltip("The error in rotation where users are considered to be in the correct direction. Value is in °.")]
public float RotationalError = 0.5f;
Expand All @@ -47,12 +49,16 @@ public class ParametersToolkit: ScriptableObject {
[Tooltip("The maximum gain in rotation that can be applied to the user's point of view in rotation. Value has no unit and is not a percentage. [Steinicke et al., 2010]")]
public Vector2Rotation GainsRotational;
[Tooltip("The maximum gain in translation that can be applied to the user's point of view in rotation. Value is in °/m and is not a percentage.")]
public float CurvatureRadius = 7.5f;
public float CurvatureRadius = 15f;



[Header("3D Interpolation")]
[Tooltip("")]
public Vector3 a;



[Header("Pseudo-Haptic")]
[Tooltip("The size of the area around the origin where the Swamp illusion defined by [Lécuyer et al., 2000] is applied. Value is in m.")]
public float SwampSquareLength = 0.25f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ private void Start() {
private void StartSendingMessages() {
if (client == null || !client.Connected) {
try {
client = new TcpClient("localhost", 13000) {
ReceiveTimeout = 500
};
client = new TcpClient("localhost", 13000);
startTime = DateTime.Now;
}
catch (SocketException) {}
Expand Down

0 comments on commit 0462c93

Please sign in to comment.