From 6d97722e9063778113d75aea35d8794b4bc1ec1c Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Fri, 17 Dec 2021 14:53:56 -0600 Subject: [PATCH 01/17] WIP: attempt to fix world-pulling by making transforms global --- .../Assets/IMPRESS/Scene/Main.unity | 25 +++++ .../Assets/IMPRESS/Scripts/WorldPulling.cs | 100 ++++++++++++++---- .../ProjectSettings/ProjectSettings.asset | 1 + .../UnityConnectSettings.asset | 1 + 4 files changed, 105 insertions(+), 22 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity index 96da4627..20b37c3c 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity @@ -3433,6 +3433,11 @@ PrefabInstance: propertyPath: physicalFloor value: objectReference: {fileID: 6308719959967395149} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: showDebugAxes + value: 1 + objectReference: {fileID: 0} - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, type: 3} propertyPath: teleportPlayer @@ -3448,6 +3453,26 @@ PrefabInstance: propertyPath: hands.Array.data[1] value: objectReference: {fileID: 8472804883547595920} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: debugAxesMaterials.Array.size + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: debugAxesMaterials.Array.data[0] + value: + objectReference: {fileID: 2100000, guid: 7e237e86216b037488af65c67187dc08, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: debugAxesMaterials.Array.data[1] + value: + objectReference: {fileID: 2100000, guid: 8e3029c485da38b46b52bcdb96b9de7a, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: debugAxesMaterials.Array.data[2] + value: + objectReference: {fileID: 2100000, guid: 02fef1dbd624dcc4d9c9ab88a7e922d4, type: 2} - target: {fileID: 4935357643860465854, guid: 85334d0d9069bb546bb3379686af011c, type: 3} propertyPath: m_Name diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 7e8b9cca..bb62df61 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -16,6 +16,8 @@ public class WorldPulling : MonoBehaviour, IUpdatable public GameObject debugAxes; + public Material[] debugAxesMaterials; + public bool showDebugAxes; /* @@ -78,7 +80,7 @@ public UpdatingValue(T initial) public Transform pivotPointsParent; - public Transform pivotPoint0; + public Transform pivotPoint; // Connect this action as a callback in Unity. public Action onDoubleTriggerPress; @@ -94,18 +96,13 @@ public UpdatingValue(T initial) public TeleportPlayer teleportPlayer; - public Quaternion initialPlayerRotation; + public Quaternion initialPlayspaceRotation; public float initialScale = 1; public void Awake() { - //create hierarchy to rotate double grab objects appropriately - //create root parent and share it through scripts by setting it to a static field - pivotPointsParent = new GameObject("PivotPoints").transform; - - //construct coordinate system to reference for tilting double grab object - pivotPoint0 = new GameObject("PivotPoint1").transform; + pivotPoint = new GameObject("WorldPullingPivotPoint").transform; if (!physicalFloor) { @@ -194,13 +191,33 @@ private void InitializeDebugAxes() return; } - var _debugAxes = Instantiate(debugAxes); + var _updatingPivotPointAxes = Instantiate(debugAxes); + + _updatingPivotPointAxes.transform.parent = pivotPoint; + + _updatingPivotPointAxes.transform.localPosition = Vector3.zero; + + _updatingPivotPointAxes.transform.localRotation = Quaternion.identity; + + _updatingPivotPointAxes.transform.GetChild(0).GetComponent().material = debugAxesMaterials[0]; + + _updatingPivotPointAxes.transform.GetChild(1).GetComponent().material = debugAxesMaterials[0]; + + _updatingPivotPointAxes.transform.GetChild(2).GetComponent().material = debugAxesMaterials[0]; + + var _playspaceAxes = Instantiate(debugAxes); + + _playspaceAxes.transform.parent = playspace; + + _playspaceAxes.transform.localPosition = Vector3.zero; + + _playspaceAxes.transform.localRotation = Quaternion.identity; - _debugAxes.transform.parent = pivotPoint0; + _updatingPivotPointAxes.transform.GetChild(0).GetComponent().material = debugAxesMaterials[1]; - _debugAxes.transform.localPosition = Vector3.zero; + _updatingPivotPointAxes.transform.GetChild(1).GetComponent().material = debugAxesMaterials[1]; - _debugAxes.transform.localRotation = Quaternion.identity; + _updatingPivotPointAxes.transform.GetChild(2).GetComponent().material = debugAxesMaterials[1]; } [ContextMenu("Start World Pulling")] @@ -278,7 +295,7 @@ public void UpdatePivotPoint (Transform pivotPoint, Vector3 hand0Position, Vecto Vector3 deltaHandPositionsXZLocal = playspace.InverseTransformDirection(deltaHandPositionsXZ); - pivotPoint.localRotation = Quaternion.LookRotation(deltaHandPositionsXZLocal, Vector3.up); + pivotPoint.rotation = Quaternion.LookRotation(deltaHandPositionsXZ, Vector3.up); } public void UpdatePlayerPosition (Vector3 teleportLocation) @@ -294,7 +311,7 @@ public void UpdatePlayerPosition (Vector3 teleportLocation) public void UpdatePlayerRotation (float rotateAmount) { - playspace.localRotation = initialPlayerRotation * Quaternion.AngleAxis(rotateAmount, Vector3.up); + playspace.rotation = Quaternion.AngleAxis(rotateAmount, Vector3.up) * initialPlayspaceRotation; } public void UpdateRulerPose (Vector3 hand0Position, Vector3 hand1Position, float scale) @@ -329,7 +346,7 @@ public void UpdateRulerValue (float newScaleRatio) protected void UpdateInitialValues () { - UpdatePivotPoint(pivotPoint0, hands[0].transform.position, hands[1].transform.position); + UpdatePivotPoint(pivotPoint, hands[0].transform.position, hands[1].transform.position); // Scale @@ -339,18 +356,18 @@ protected void UpdateInitialValues () // Rotation - initialPlayerRotation = playspace.localRotation * Quaternion.Inverse(playspace.localRotation); + initialPlayspaceRotation = playspace.rotation; // TODO REMOVE Quaternion.Inverse(playspace.localRotation) * playspace.localRotation; - handsRotationY = new UpdatingValue(pivotPoint0.localEulerAngles.y); + handsRotationY = new UpdatingValue(pivotPoint.eulerAngles.y); // Position initialLeftEyePosition = leftEye.position; - handsAverageLocalPosition = new UpdatingValue(pivotPoint0.position - playspace.position); + handsAverageLocalPosition = new UpdatingValue(pivotPoint.position - playspace.position); } - public void OnUpdate(float realltime) + public void OnUpdateOld(float realltime) { // Scale @@ -368,9 +385,9 @@ public void OnUpdate(float realltime) // Rotation - UpdatePivotPoint(pivotPoint0, hands[0].transform.position, hands[1].transform.position); + UpdatePivotPoint(pivotPoint, hands[0].transform.position, hands[1].transform.position); - handsRotationY.Current = pivotPoint0.localEulerAngles.y; + handsRotationY.Current = pivotPoint.eulerAngles.y; float rotateAmount = ComputeRotationDifference(handsRotationY); @@ -382,12 +399,51 @@ public void OnUpdate(float realltime) // Position - handsAverageLocalPosition.Current = pivotPoint0.position - playspace.position; + handsAverageLocalPosition.Current = pivotPoint.position - playspace.position; Vector3 newPosition = ComputePositionDifference(handsAverageLocalPosition) + initialLeftEyePosition; UpdatePlayerPosition(newPosition); } + + public void OnUpdate(float realltime) + { + // Scale + + handDistance.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position); + + playerLocalScaleX.Current = playspace.localScale.x; + + float newScale = ComputeScale(handDistance, playerLocalScaleX); + + newScale = Mathf.Clamp(newScale, scaleMin, scaleMax); + + UpdateRulerValue(newScale); + + //TODO put back teleportPlayer.UpdatePlayerScale(newScale); + + // Rotation + + UpdatePivotPoint(pivotPoint, hands[0].transform.position, hands[1].transform.position); + + handsRotationY.Current = pivotPoint.eulerAngles.y; + + float rotateAmount = ComputeRotationDifference(handsRotationY); + + UpdatePlayerRotation(rotateAmount); + + UpdateRulerPose(hands[0].transform.position, hands[1].transform.position, newScale); + + UpdateHandToHandLineEndpoints(hands[0].transform.position, hands[1].transform.position); + + // Position + + handsAverageLocalPosition.Current = pivotPoint.position - playspace.position; + + Vector3 newPosition = ComputePositionDifference(handsAverageLocalPosition) + initialLeftEyePosition; + + //TODO put back UpdatePlayerPosition(newPosition); + } } } diff --git a/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset b/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset index e5a6566b..4d3ed88b 100644 --- a/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset +++ b/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset @@ -168,6 +168,7 @@ PlayerSettings: - {fileID: 0} - {fileID: 0} - {fileID: 0} + - {fileID: 0} - {fileID: 11400000, guid: 6145319c34f440441bbabe329561f17c, type: 2} - {fileID: 0} - {fileID: 2910771567588298596, guid: ac933aa07b1097d47a08984d469dccfc, type: 2} diff --git a/KOMODO-IMPRESS/ProjectSettings/UnityConnectSettings.asset b/KOMODO-IMPRESS/ProjectSettings/UnityConnectSettings.asset index fa0b1465..6125b308 100644 --- a/KOMODO-IMPRESS/ProjectSettings/UnityConnectSettings.asset +++ b/KOMODO-IMPRESS/ProjectSettings/UnityConnectSettings.asset @@ -9,6 +9,7 @@ UnityConnectSettings: m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events m_EventUrl: https://cdp.cloud.unity3d.com/v1/events m_ConfigUrl: https://config.uca.cloud.unity3d.com + m_DashboardUrl: https://dashboard.unity3d.com m_TestInitMode: 0 CrashReportingSettings: m_EventUrl: https://perf-events.cloud.unity3d.com From dab06e0f5da5d3f521b35715f0f6a7204410f7bd Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Fri, 17 Dec 2021 19:11:10 -0600 Subject: [PATCH 02/17] WIP: got world pulling (rotateAround only) to work up to 180 degrees --- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 101 +++++++++++++----- 1 file changed, 73 insertions(+), 28 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 7e8b9cca..ce5ed0eb 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -59,7 +59,7 @@ public UpdatingValue(T initial) private UpdatingValue handsAverageLocalPosition; [SerializeField] - private UpdatingValue handsRotationY; + private UpdatingValue rotationInInitialPlayspace; private LineRenderer handToHandLine; @@ -78,7 +78,7 @@ public UpdatingValue(T initial) public Transform pivotPointsParent; - public Transform pivotPoint0; + public Transform pivotPoint; // Connect this action as a callback in Unity. public Action onDoubleTriggerPress; @@ -94,10 +94,14 @@ public UpdatingValue(T initial) public TeleportPlayer teleportPlayer; - public Quaternion initialPlayerRotation; + public Vector3 initialPlayspacePosition; + + public Quaternion initialPlayspaceRotation; public float initialScale = 1; + private GameObject currentPlayspaceObject; + public void Awake() { //create hierarchy to rotate double grab objects appropriately @@ -105,12 +109,18 @@ public void Awake() pivotPointsParent = new GameObject("PivotPoints").transform; //construct coordinate system to reference for tilting double grab object - pivotPoint0 = new GameObject("PivotPoint1").transform; + pivotPoint = new GameObject("PivotPoint1").transform; if (!physicalFloor) { throw new UnassignedReferenceException("physicalFloorReference"); } + + currentPlayspaceObject = new GameObject(); + + initialPlayspacePosition = new Vector3(); + + initialPlayspaceRotation = new Quaternion(); } public void Start() @@ -196,7 +206,7 @@ private void InitializeDebugAxes() var _debugAxes = Instantiate(debugAxes); - _debugAxes.transform.parent = pivotPoint0; + _debugAxes.transform.parent = pivotPoint; _debugAxes.transform.localPosition = Vector3.zero; @@ -261,9 +271,11 @@ public float ComputeScale (UpdatingValue handDistance, UpdatingValue handsRotationY) + public float ComputeRotationDifferenceY (UpdatingValue rotation) { - return handsRotationY.Initial - handsRotationY.Current; + Quaternion diffRotation = Quaternion.Inverse(rotation.Initial) * rotation.Current; + + return diffRotation.eulerAngles.y; } public void UpdatePivotPoint (Transform pivotPoint, Vector3 hand0Position, Vector3 hand1Position) @@ -276,9 +288,7 @@ public void UpdatePivotPoint (Transform pivotPoint, Vector3 hand0Position, Vecto (hand1Position - hand0Position).z ); - Vector3 deltaHandPositionsXZLocal = playspace.InverseTransformDirection(deltaHandPositionsXZ); - - pivotPoint.localRotation = Quaternion.LookRotation(deltaHandPositionsXZLocal, Vector3.up); + pivotPoint.rotation = Quaternion.LookRotation(deltaHandPositionsXZ, Vector3.up); } public void UpdatePlayerPosition (Vector3 teleportLocation) @@ -292,9 +302,23 @@ public void UpdatePlayerPosition (Vector3 teleportLocation) playspace.position = finalPlayspacePosition; } - public void UpdatePlayerRotation (float rotateAmount) + public void UpdatePlayspaceRotation (float amount) { - playspace.localRotation = initialPlayerRotation * Quaternion.AngleAxis(rotateAmount, Vector3.up); + // Copy the transform to a new gameObject. + + Transform currentPlayspace = currentPlayspaceObject.transform; + + currentPlayspace.position = initialPlayspacePosition; + + currentPlayspace.rotation = initialPlayspaceRotation; + + amount *= -1; // Make our own client rotate in the opposite direction that our hands did + + currentPlayspace.RotateAround(pivotPoint.position, Vector3.up, amount); + + playspace.position = currentPlayspace.position; + + playspace.rotation = currentPlayspace.rotation; } public void UpdateRulerPose (Vector3 hand0Position, Vector3 hand1Position, float scale) @@ -329,7 +353,7 @@ public void UpdateRulerValue (float newScaleRatio) protected void UpdateInitialValues () { - UpdatePivotPoint(pivotPoint0, hands[0].transform.position, hands[1].transform.position); + UpdatePivotPoint(pivotPoint, hands[0].transform.position, hands[1].transform.position); // Scale @@ -339,19 +363,41 @@ protected void UpdateInitialValues () // Rotation - initialPlayerRotation = playspace.localRotation * Quaternion.Inverse(playspace.localRotation); + initialPlayspacePosition = playspace.position; - handsRotationY = new UpdatingValue(pivotPoint0.localEulerAngles.y); + initialPlayspaceRotation = playspace.rotation; + + rotationInInitialPlayspace = new UpdatingValue(Quaternion.Inverse(initialPlayspaceRotation) * pivotPoint.rotation); // Position initialLeftEyePosition = leftEye.position; - handsAverageLocalPosition = new UpdatingValue(pivotPoint0.position - playspace.position); + handsAverageLocalPosition = new UpdatingValue(pivotPoint.position - playspace.position); + } + + public void UpdatePlayspaceScale (float scale) + { + // TODO: scale around a point here + } + + public void UpdateLineRenderersScale (float scale) + { + // TODO: update size of drawing strokes here } public void OnUpdate(float realltime) { + // Rotation + + UpdatePivotPoint(pivotPoint, hands[0].transform.position, hands[1].transform.position); + + rotationInInitialPlayspace.Current = Quaternion.Inverse(initialPlayspaceRotation) * pivotPoint.rotation; + + float rotateAmount = ComputeRotationDifferenceY(rotationInInitialPlayspace); + + UpdatePlayspaceRotation(rotateAmount); + // Scale handDistance.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position); @@ -362,19 +408,13 @@ public void OnUpdate(float realltime) newScale = Mathf.Clamp(newScale, scaleMin, scaleMax); - UpdateRulerValue(newScale); - - teleportPlayer.UpdatePlayerScale(newScale); - - // Rotation - - UpdatePivotPoint(pivotPoint0, hands[0].transform.position, hands[1].transform.position); + //TODO put back UpdatePlayspaceScale(newScale); - handsRotationY.Current = pivotPoint0.localEulerAngles.y; + //TODO put back UpdateLineRenderersScale(newScale); - float rotateAmount = ComputeRotationDifference(handsRotationY); + // Ruler - UpdatePlayerRotation(rotateAmount); + UpdateRulerValue(newScale); UpdateRulerPose(hands[0].transform.position, hands[1].transform.position, newScale); @@ -382,11 +422,16 @@ public void OnUpdate(float realltime) // Position - handsAverageLocalPosition.Current = pivotPoint0.position - playspace.position; + handsAverageLocalPosition.Current = pivotPoint.position - playspace.position; Vector3 newPosition = ComputePositionDifference(handsAverageLocalPosition) + initialLeftEyePosition; - UpdatePlayerPosition(newPosition); + //TODO put back UpdatePlayerPosition(newPosition); + } + + public void OnDestroy () + { + Destroy(currentPlayspaceObject); } } } From d95642a2f951774e253dbb8be7871892757fbffb Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Fri, 17 Dec 2021 19:53:03 -0600 Subject: [PATCH 03/17] WIP: failed attempt: using euler angles in Y rotation calculation only --- KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index ce5ed0eb..8a5a0579 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -271,11 +271,11 @@ public float ComputeScale (UpdatingValue handDistance, UpdatingValue rotation) + public float ComputeDiffYRotationInInitialPlayspace (UpdatingValue rotation) { - Quaternion diffRotation = Quaternion.Inverse(rotation.Initial) * rotation.Current; + Vector3 diffRotation = rotation.Current.eulerAngles - rotation.Initial.eulerAngles; - return diffRotation.eulerAngles.y; + return diffRotation.y; } public void UpdatePivotPoint (Transform pivotPoint, Vector3 hand0Position, Vector3 hand1Position) @@ -394,7 +394,7 @@ public void OnUpdate(float realltime) rotationInInitialPlayspace.Current = Quaternion.Inverse(initialPlayspaceRotation) * pivotPoint.rotation; - float rotateAmount = ComputeRotationDifferenceY(rotationInInitialPlayspace); + float rotateAmount = ComputeDiffYRotationInInitialPlayspace(rotationInInitialPlayspace); UpdatePlayspaceRotation(rotateAmount); From 3fb85fc5606ec5f5c3f69518b08dee8dcf0c16f0 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Sat, 18 Dec 2021 00:53:52 -0600 Subject: [PATCH 04/17] WIP: got rotation to work up to 90 degrees --- .../Assets/IMPRESS/Scene/Main.unity | 45 +++++ .../Assets/IMPRESS/Scripts/WorldPulling.cs | 161 +++++++++++++++--- 2 files changed, 178 insertions(+), 28 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity index 96da4627..fea88df0 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity @@ -3433,6 +3433,11 @@ PrefabInstance: propertyPath: physicalFloor value: objectReference: {fileID: 6308719959967395149} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: showDebugAxes + value: 1 + objectReference: {fileID: 0} - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, type: 3} propertyPath: teleportPlayer @@ -3448,6 +3453,46 @@ PrefabInstance: propertyPath: hands.Array.data[1] value: objectReference: {fileID: 8472804883547595920} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.size + value: 6 + objectReference: {fileID: 0} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[0] + value: + objectReference: {fileID: 2100000, guid: e23af2a5280618c49a2340fdfba771e6, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[1] + value: + objectReference: {fileID: 2100000, guid: 8e3029c485da38b46b52bcdb96b9de7a, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[2] + value: + objectReference: {fileID: 2100000, guid: 02fef1dbd624dcc4d9c9ab88a7e922d4, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[3] + value: + objectReference: {fileID: 2100000, guid: d7589b41c4f527c44af461d54cf01d52, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[4] + value: + objectReference: {fileID: 2100000, guid: 093e7be84ebdb7940ba941aee252cbf9, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[5] + value: + objectReference: {fileID: 2100000, guid: 1bf2a636382de314d883fcb85d081587, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[6] + value: + objectReference: {fileID: 0} - target: {fileID: 4935357643860465854, guid: 85334d0d9069bb546bb3379686af011c, type: 3} propertyPath: m_Name diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 8a5a0579..5c567520 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -76,9 +76,9 @@ public UpdatingValue(T initial) public Transform[] hands = new Transform[2]; - public Transform pivotPointsParent; + private Transform initialPivotPointInPlayspace; - public Transform pivotPoint; + public Transform currentPivotPointInPlayspace; // Connect this action as a callback in Unity. public Action onDoubleTriggerPress; @@ -102,14 +102,21 @@ public UpdatingValue(T initial) private GameObject currentPlayspaceObject; + public Material[] materials; + + private GameObject initialPlayspaceAxes; + + private GameObject currentPlayspaceAxes; + public void Awake() { - //create hierarchy to rotate double grab objects appropriately - //create root parent and share it through scripts by setting it to a static field - pivotPointsParent = new GameObject("PivotPoints").transform; + initialPivotPointInPlayspace = new GameObject("InitialPivotPoint").transform; + + initialPivotPointInPlayspace.parent = playspace; - //construct coordinate system to reference for tilting double grab object - pivotPoint = new GameObject("PivotPoint1").transform; + currentPivotPointInPlayspace = new GameObject("CurrentPivotPoint").transform; + + currentPivotPointInPlayspace.parent = playspace; if (!physicalFloor) { @@ -204,19 +211,103 @@ private void InitializeDebugAxes() return; } - var _debugAxes = Instantiate(debugAxes); + var initialPivotPointAxes = Instantiate(debugAxes); + + initialPivotPointAxes.transform.parent = initialPivotPointInPlayspace; + + initialPivotPointAxes.transform.localPosition = Vector3.zero; + + initialPivotPointAxes.transform.localRotation = Quaternion.identity; + + initialPivotPointAxes.transform.GetChild(0).GetComponent().material = materials[0]; + + initialPivotPointAxes.transform.GetChild(1).GetComponent().material = materials[0]; + + initialPivotPointAxes.transform.GetChild(2).GetComponent().material = materials[0]; + + var currentPivotPointAxes = Instantiate(debugAxes); + + currentPivotPointAxes.transform.parent = currentPivotPointInPlayspace; + + currentPivotPointAxes.transform.localPosition = Vector3.zero; + + currentPivotPointAxes.transform.localRotation = Quaternion.identity; + + currentPivotPointAxes.transform.GetChild(0).GetComponent().material = materials[1]; + + currentPivotPointAxes.transform.GetChild(1).GetComponent().material = materials[1]; + + currentPivotPointAxes.transform.GetChild(2).GetComponent().material = materials[1]; + + initialPlayspaceAxes = Instantiate(debugAxes); + + initialPlayspaceAxes.transform.GetChild(0).GetComponent().material = materials[2]; + + initialPlayspaceAxes.transform.GetChild(1).GetComponent().material = materials[2]; + + initialPlayspaceAxes.transform.GetChild(2).GetComponent().material = materials[2]; + + currentPlayspaceAxes = Instantiate(debugAxes); + + currentPlayspaceAxes.transform.parent = playspace; + + currentPlayspaceAxes.transform.GetChild(0).GetComponent().material = materials[3]; + + currentPlayspaceAxes.transform.GetChild(1).GetComponent().material = materials[3]; + + currentPlayspaceAxes.transform.GetChild(2).GetComponent().material = materials[3]; + + var hand0Axes = Instantiate(debugAxes); + + hand0Axes.transform.parent = hands[0]; - _debugAxes.transform.parent = pivotPoint; + hand0Axes.transform.localPosition = Vector3.zero; - _debugAxes.transform.localPosition = Vector3.zero; + hand0Axes.transform.localRotation = Quaternion.identity; - _debugAxes.transform.localRotation = Quaternion.identity; + hand0Axes.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); + + hand0Axes.transform.GetChild(0).GetComponent().material = materials[4]; + + hand0Axes.transform.GetChild(1).GetComponent().material = materials[4]; + + hand0Axes.transform.GetChild(2).GetComponent().material = materials[4]; + + var hand1Axes = Instantiate(debugAxes); + + hand1Axes.transform.parent = hands[1]; + + hand1Axes.transform.localPosition = Vector3.zero; + + hand1Axes.transform.localRotation = Quaternion.identity; + + hand1Axes.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); + + hand1Axes.transform.GetChild(0).GetComponent().material = materials[5]; + + hand1Axes.transform.GetChild(1).GetComponent().material = materials[5]; + + hand1Axes.transform.GetChild(2).GetComponent().material = materials[5]; + } + + private void UpdateDebugAxes () + { + if (!showDebugAxes) + { + return; + } + + initialPlayspaceAxes.transform.position = initialPlayspacePosition; + + initialPlayspaceAxes.transform.rotation = initialPlayspaceRotation; } [ContextMenu("Start World Pulling")] public void StartWorldPulling() { - UpdateInitialValues(); + Debug.Log("started world pulling"); //TODO Remove + + SetInitialValues(); animalRuler.gameObject.SetActive(true); @@ -249,6 +340,8 @@ public void StopWorldPulling() { GameStateManager.Instance.DeRegisterUpdatableObject(this); } + + Debug.Log("stopped world pulling"); //TODO Remove } private void ShowPhysicalFloor () @@ -271,16 +364,26 @@ public float ComputeScale (UpdatingValue handDistance, UpdatingValue rotation) + public float ComputeDiffRotationY (Quaternion initial, Quaternion current) { - Vector3 diffRotation = rotation.Current.eulerAngles - rotation.Initial.eulerAngles; + float result = (Quaternion.Inverse(initial) * current).eulerAngles.y; - return diffRotation.y; + if (result > 360) + { + Debug.Log($"WOrld pulling diffroty was greater than 360 {result}"); + } + + if (result < -360) + { + Debug.Log($"WOrld pulling diffroty was less than -360 {result}"); + } + + return result; } - public void UpdatePivotPoint (Transform pivotPoint, Vector3 hand0Position, Vector3 hand1Position) + public void UpdateLocalPivotPoint (Transform pivotPointInPlayspace, Vector3 hand0Position, Vector3 hand1Position) { - pivotPoint.position = (hand0Position + hand1Position) / 2; + pivotPointInPlayspace.localPosition = playspace.InverseTransformPoint((hand0Position + hand1Position) / 2); Vector3 deltaHandPositionsXZ = new Vector3( (hand1Position - hand0Position).x, @@ -288,7 +391,7 @@ public void UpdatePivotPoint (Transform pivotPoint, Vector3 hand0Position, Vecto (hand1Position - hand0Position).z ); - pivotPoint.rotation = Quaternion.LookRotation(deltaHandPositionsXZ, Vector3.up); + pivotPointInPlayspace.localRotation = Quaternion.Inverse(playspace.rotation) * Quaternion.LookRotation(deltaHandPositionsXZ, Vector3.up); } public void UpdatePlayerPosition (Vector3 teleportLocation) @@ -312,9 +415,9 @@ public void UpdatePlayspaceRotation (float amount) currentPlayspace.rotation = initialPlayspaceRotation; - amount *= -1; // Make our own client rotate in the opposite direction that our hands did + amount *= -1.0f; // Make our own client rotate in the opposite direction that our hands did - currentPlayspace.RotateAround(pivotPoint.position, Vector3.up, amount); + currentPlayspace.RotateAround(initialPivotPointInPlayspace.position, Vector3.up, amount); playspace.position = currentPlayspace.position; @@ -351,9 +454,11 @@ public void UpdateRulerValue (float newScaleRatio) animalRulerMesh.material.SetTextureOffset("_MainTex", new Vector2(Mathf.Clamp(rulerValue, min, max), 0)); } - protected void UpdateInitialValues () + protected void SetInitialValues () { - UpdatePivotPoint(pivotPoint, hands[0].transform.position, hands[1].transform.position); + UpdateLocalPivotPoint(initialPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); + + UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); // Scale @@ -367,13 +472,13 @@ protected void UpdateInitialValues () initialPlayspaceRotation = playspace.rotation; - rotationInInitialPlayspace = new UpdatingValue(Quaternion.Inverse(initialPlayspaceRotation) * pivotPoint.rotation); + UpdateDebugAxes(); // Position initialLeftEyePosition = leftEye.position; - handsAverageLocalPosition = new UpdatingValue(pivotPoint.position - playspace.position); + handsAverageLocalPosition = new UpdatingValue(currentPivotPointInPlayspace.position - playspace.position); } public void UpdatePlayspaceScale (float scale) @@ -390,11 +495,11 @@ public void OnUpdate(float realltime) { // Rotation - UpdatePivotPoint(pivotPoint, hands[0].transform.position, hands[1].transform.position); + UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); - rotationInInitialPlayspace.Current = Quaternion.Inverse(initialPlayspaceRotation) * pivotPoint.rotation; + float rotateAmount = ComputeDiffRotationY(initialPivotPointInPlayspace.rotation, currentPivotPointInPlayspace.rotation); - float rotateAmount = ComputeDiffYRotationInInitialPlayspace(rotationInInitialPlayspace); + UpdateDebugAxes(); UpdatePlayspaceRotation(rotateAmount); @@ -422,7 +527,7 @@ public void OnUpdate(float realltime) // Position - handsAverageLocalPosition.Current = pivotPoint.position - playspace.position; + handsAverageLocalPosition.Current = currentPivotPointInPlayspace.position - playspace.position; Vector3 newPosition = ComputePositionDifference(handsAverageLocalPosition) + initialLeftEyePosition; From 66438849d02f106ca48124f3e73ea46c5f17a384 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Sat, 18 Dec 2021 01:41:37 -0600 Subject: [PATCH 05/17] successfully got rotateAround initialPivotPoint to work --- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 5c567520..50d5ed12 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -108,6 +108,8 @@ public UpdatingValue(T initial) private GameObject currentPlayspaceAxes; + private Vector3 copyOfInitialPivotPointPosition; + public void Awake() { initialPivotPointInPlayspace = new GameObject("InitialPivotPoint").transform; @@ -366,16 +368,11 @@ public float ComputeScale (UpdatingValue handDistance, UpdatingValue 360) + if (result > -0.001f && result < 0.001f) { - Debug.Log($"WOrld pulling diffroty was greater than 360 {result}"); - } - - if (result < -360) - { - Debug.Log($"WOrld pulling diffroty was less than -360 {result}"); + result = 0.0f; } return result; @@ -417,7 +414,8 @@ public void UpdatePlayspaceRotation (float amount) amount *= -1.0f; // Make our own client rotate in the opposite direction that our hands did - currentPlayspace.RotateAround(initialPivotPointInPlayspace.position, Vector3.up, amount); + currentPlayspace.RotateAround( + copyOfInitialPivotPointPosition, Vector3.up, amount); playspace.position = currentPlayspace.position; @@ -458,6 +456,8 @@ protected void SetInitialValues () { UpdateLocalPivotPoint(initialPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); + copyOfInitialPivotPointPosition = initialPivotPointInPlayspace.position; + UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); // Scale @@ -491,7 +491,7 @@ public void UpdateLineRenderersScale (float scale) // TODO: update size of drawing strokes here } - public void OnUpdate(float realltime) + public void OnUpdate (float realltime) { // Rotation From cd841594830ad39684142097d5e65046d6bbacce Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Mon, 3 Jan 2022 21:44:43 -0600 Subject: [PATCH 06/17] WIP: scaling mostly works; offset is very incorrect --- .../Assets/IMPRESS/Scene/Main.unity | 5 + .../IMPRESS/Scene/OutsideTheMilkyWay.unity | 192 +++++++++++++++++- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 51 +++-- 3 files changed, 228 insertions(+), 20 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity index 72f5eca2..20b37c3c 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity @@ -3433,6 +3433,11 @@ PrefabInstance: propertyPath: physicalFloor value: objectReference: {fileID: 6308719959967395149} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: showDebugAxes + value: 1 + objectReference: {fileID: 0} - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, type: 3} propertyPath: teleportPlayer diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity index 8f5da202..4b424a9b 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity @@ -218,6 +218,196 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &1186417695 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1186417699} + - component: {fileID: 1186417698} + - component: {fileID: 1186417697} + - component: {fileID: 1186417696} + m_Layer: 0 + m_Name: Sphere_Test (2) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!135 &1186417696 +SphereCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1186417695} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: 0.5 + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1186417697 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1186417695} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 3ee727b154ed24e44812c316bb01ef90, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1186417698 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1186417695} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1186417699 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1186417695} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -1.78, y: 1.02, z: 1.03} + m_LocalScale: {x: 0.5, y: 0.17, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1275368507 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1275368511} + - component: {fileID: 1275368510} + - component: {fileID: 1275368509} + - component: {fileID: 1275368508} + m_Layer: 0 + m_Name: Sphere_Test (1) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!135 &1275368508 +SphereCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1275368507} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: 0.5 + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1275368509 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1275368507} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 3ee727b154ed24e44812c316bb01ef90, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1275368510 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1275368507} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1275368511 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1275368507} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 1.29, y: 1.08, z: 1.85} + m_LocalScale: {x: 1, y: 0.39, z: 1.69} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1531216788 GameObject: m_ObjectHideFlags: 0 @@ -307,7 +497,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1531216788} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 2.35, y: -0.89, z: -1.89} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index e67cc821..9d696540 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -48,8 +48,10 @@ public UpdatingValue(T initial) [SerializeField] private UpdatingValue playerLocalScaleX; + private float initialPlayspaceScale; + [SerializeField] - private UpdatingValue handDistance; + private UpdatingValue handDistanceInPlayspace; [SerializeField] private Vector3 initialLeftEyePosition; @@ -358,7 +360,9 @@ public Vector3 ComputePositionDifference (UpdatingValue handsAveragePos return handsAveragePosition.Initial - handsAveragePosition.Current; } - public float ComputeScale (UpdatingValue handDistance, UpdatingValue playerLocalScaleX) + // Computes the dif + + public float ComputeScaleRatio (UpdatingValue handDistance, UpdatingValue playerLocalScaleX) { return handDistance.Initial / handDistance.Current * (playerLocalScaleX.Initial * playerLocalScaleX.Current); } @@ -399,7 +403,7 @@ public void UpdatePlayerPosition (Vector3 teleportLocation) playspace.position = finalPlayspacePosition; } - public void UpdatePlayspaceRotation (float amount) + public void RotatePlayspaceAroundPoint (float amount) { // Copy the transform to a new gameObject. @@ -438,9 +442,9 @@ public float ComputeRulerValue (float playerScale) return (playerScale - 0.9f) / 1.3f; } - public void UpdateRulerValue (float newScaleRatio) + public void UpdateRulerValue (float newScale) { - var rulerValue = ComputeRulerValue(newScaleRatio); + var rulerValue = ComputeRulerValue(newScale); float min = ComputeRulerValue(scaleMin); @@ -459,9 +463,9 @@ protected void SetInitialValues () // Scale - playerLocalScaleX = new UpdatingValue(playspace.localScale.x * initialScale); + handDistanceInPlayspace = new UpdatingValue(Vector3.Distance(hands[0].position, hands[1].position) / playspace.localScale.x); - handDistance = new UpdatingValue(Vector3.Distance(hands[0].position, hands[1].position)); + initialPlayspaceScale = playspace.localScale.x; // Rotation @@ -478,16 +482,23 @@ protected void SetInitialValues () handsAverageLocalPosition = new UpdatingValue(currentPivotPointInPlayspace.position - playspace.position); } - public void UpdatePlayspaceScale (float scale) + public void ScalePlayspaceAroundPoint (float scaleRatio, float newScale) { - // TODO: scale around a point here + playspace.localScale = new Vector3(newScale, newScale, newScale); + + playspace.position = ((initialPlayspacePosition - initialPivotPointInPlayspace.position) * scaleRatio) + initialPivotPointInPlayspace.position; } - public void UpdateLineRenderersScale (float scale) + public void UpdateLineRenderersScale (float newScale) { // TODO: update size of drawing strokes here } + public void SendAvatarScaleUpdate (float newScale) + { + //TODO: send message that avatar scale changed to other clients + } + public void OnUpdate (float realltime) { // Rotation @@ -498,27 +509,29 @@ public void OnUpdate (float realltime) UpdateDebugAxes(); - UpdatePlayspaceRotation(rotateAmount); + RotatePlayspaceAroundPoint(rotateAmount); // Scale - handDistance.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position); + handDistanceInPlayspace.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position) / playspace.localScale.x; + + float unclampedScaleRatio = 1.0f / (handDistanceInPlayspace.Current / handDistanceInPlayspace.Initial); - playerLocalScaleX.Current = playspace.localScale.x; + float clampedNewScale = Mathf.Clamp(unclampedScaleRatio * initialPlayspaceScale, scaleMin, scaleMax); - float newScale = ComputeScale(handDistance, playerLocalScaleX); + float clampedScaleRatio = clampedNewScale / initialPlayspaceScale; - newScale = Mathf.Clamp(newScale, scaleMin, scaleMax); + ScalePlayspaceAroundPoint(clampedScaleRatio, clampedNewScale); - //TODO put back UpdatePlayspaceScale(newScale); + UpdateLineRenderersScale(clampedNewScale); - //TODO put back UpdateLineRenderersScale(newScale); + SendAvatarScaleUpdate(clampedNewScale); // Ruler - UpdateRulerValue(newScale); + UpdateRulerValue(clampedNewScale); - UpdateRulerPose(hands[0].transform.position, hands[1].transform.position, newScale); + UpdateRulerPose(hands[0].transform.position, hands[1].transform.position, clampedNewScale); UpdateHandToHandLineEndpoints(hands[0].transform.position, hands[1].transform.position); From 12c56b2c00b87a1b73ea13d2c7649d7d206d56d6 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Sat, 8 Jan 2022 19:00:14 -0600 Subject: [PATCH 07/17] WIP: fixed floating value error with scaling; offset is still incorrect --- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 9d696540..4af42e96 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -415,8 +415,7 @@ public void RotatePlayspaceAroundPoint (float amount) amount *= -1.0f; // Make our own client rotate in the opposite direction that our hands did - currentPlayspace.RotateAround( - copyOfInitialPivotPointPosition, Vector3.up, amount); + currentPlayspace.RotateAround(copyOfInitialPivotPointPosition, Vector3.up, amount); playspace.position = currentPlayspace.position; @@ -486,7 +485,7 @@ public void ScalePlayspaceAroundPoint (float scaleRatio, float newScale) { playspace.localScale = new Vector3(newScale, newScale, newScale); - playspace.position = ((initialPlayspacePosition - initialPivotPointInPlayspace.position) * scaleRatio) + initialPivotPointInPlayspace.position; + playspace.position = ((playspace.position - initialPivotPointInPlayspace.position) * scaleRatio) + initialPivotPointInPlayspace.position; } public void UpdateLineRenderersScale (float newScale) @@ -501,16 +500,6 @@ public void SendAvatarScaleUpdate (float newScale) public void OnUpdate (float realltime) { - // Rotation - - UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); - - float rotateAmount = ComputeDiffRotationY(initialPivotPointInPlayspace.rotation, currentPivotPointInPlayspace.rotation); - - UpdateDebugAxes(); - - RotatePlayspaceAroundPoint(rotateAmount); - // Scale handDistanceInPlayspace.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position) / playspace.localScale.x; @@ -519,6 +508,11 @@ public void OnUpdate (float realltime) float clampedNewScale = Mathf.Clamp(unclampedScaleRatio * initialPlayspaceScale, scaleMin, scaleMax); + if (clampedNewScale > -0.001f && clampedNewScale < 0.001f) + { + clampedNewScale = 0.0f; + } + float clampedScaleRatio = clampedNewScale / initialPlayspaceScale; ScalePlayspaceAroundPoint(clampedScaleRatio, clampedNewScale); @@ -527,6 +521,16 @@ public void OnUpdate (float realltime) SendAvatarScaleUpdate(clampedNewScale); + // Rotation + + UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); + + float rotateAmount = ComputeDiffRotationY(initialPivotPointInPlayspace.rotation, currentPivotPointInPlayspace.rotation); + + UpdateDebugAxes(); + + RotatePlayspaceAroundPoint(rotateAmount); + // Ruler UpdateRulerValue(clampedNewScale); From 5a603020a4cad0205be581c971ae77c221941f2e Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Mon, 10 Jan 2022 13:01:00 -0600 Subject: [PATCH 08/17] WIP: scaling and rotation are interleaved but the effects accumulate --- .../Assets/IMPRESS/Scene/Main.unity | 15 ++++ .../Assets/IMPRESS/Scripts/WorldPulling.cs | 73 ++++++++++++------- 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity index 20b37c3c..01d63125 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity @@ -3453,6 +3453,21 @@ PrefabInstance: propertyPath: hands.Array.data[1] value: objectReference: {fileID: 8472804883547595920} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.size + value: 7 + objectReference: {fileID: 0} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[5] + value: + objectReference: {fileID: 2100000, guid: 1bf2a636382de314d883fcb85d081587, type: 2} + - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, + type: 3} + propertyPath: materials.Array.data[6] + value: + objectReference: {fileID: 2100000, guid: 381fb7f0084fa1d4982d467aa0d80e0a, type: 2} - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, type: 3} propertyPath: debugAxesMaterials.Array.size diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 4af42e96..f990e775 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -99,7 +99,7 @@ public UpdatingValue(T initial) public float initialScale = 1; - private GameObject currentPlayspaceObject; + private GameObject initialPlayspace; public Material[] materials; @@ -109,6 +109,8 @@ public UpdatingValue(T initial) private Vector3 copyOfInitialPivotPointPosition; + private GameObject copyOfInitialPivotPointPositionAxes; + public void Awake() { initialPivotPointInPlayspace = new GameObject("InitialPivotPoint").transform; @@ -124,7 +126,7 @@ public void Awake() throw new UnassignedReferenceException("physicalFloorReference"); } - currentPlayspaceObject = new GameObject(); + initialPlayspace = new GameObject(); initialPlayspacePosition = new Vector3(); @@ -289,6 +291,18 @@ private void InitializeDebugAxes() hand1Axes.transform.GetChild(1).GetComponent().material = materials[5]; hand1Axes.transform.GetChild(2).GetComponent().material = materials[5]; + + copyOfInitialPivotPointPositionAxes = Instantiate(debugAxes); + + copyOfInitialPivotPointPositionAxes.transform.localPosition = Vector3.zero; + + copyOfInitialPivotPointPositionAxes.transform.localRotation = Quaternion.identity; + + copyOfInitialPivotPointPositionAxes.transform.GetChild(0).GetComponent().material = materials[6]; + + copyOfInitialPivotPointPositionAxes.transform.GetChild(1).GetComponent().material = materials[6]; + + copyOfInitialPivotPointPositionAxes.transform.GetChild(2).GetComponent().material = materials[6]; } private void UpdateDebugAxes () @@ -301,6 +315,8 @@ private void UpdateDebugAxes () initialPlayspaceAxes.transform.position = initialPlayspacePosition; initialPlayspaceAxes.transform.rotation = initialPlayspaceRotation; + + copyOfInitialPivotPointPositionAxes.transform.position = copyOfInitialPivotPointPosition; } [ContextMenu("Start World Pulling")] @@ -403,23 +419,20 @@ public void UpdatePlayerPosition (Vector3 teleportLocation) playspace.position = finalPlayspacePosition; } - public void RotatePlayspaceAroundPoint (float amount) + public void RotateAndScalePlayspaceAroundPoint (float amount, float scaleRatio, float newScale) { - // Copy the transform to a new gameObject. - - Transform currentPlayspace = currentPlayspaceObject.transform; - - currentPlayspace.position = initialPlayspacePosition; - - currentPlayspace.rotation = initialPlayspaceRotation; + // Make our own client rotate in the opposite direction that our hands did + amount *= -1.0f; - amount *= -1.0f; // Make our own client rotate in the opposite direction that our hands did + // Compute position and rotation as if not scaling + initialPlayspace.transform.RotateAround(copyOfInitialPivotPointPosition, Vector3.up, amount); - currentPlayspace.RotateAround(copyOfInitialPivotPointPosition, Vector3.up, amount); + // Find position after scaling and rotation and apply it + playspace.position = ((initialPlayspace.transform.position - copyOfInitialPivotPointPosition) * scaleRatio) + copyOfInitialPivotPointPosition; - playspace.position = currentPlayspace.position; + playspace.rotation = initialPlayspace.transform.rotation; - playspace.rotation = currentPlayspace.rotation; + playspace.localScale = new Vector3(newScale, newScale, newScale); } public void UpdateRulerPose (Vector3 hand0Position, Vector3 hand1Position, float scale) @@ -466,6 +479,14 @@ protected void SetInitialValues () initialPlayspaceScale = playspace.localScale.x; + // Copy the transform to a new gameObject. + + initialPlayspace.transform.position = playspace.position; + + initialPlayspace.transform.rotation = playspace.rotation; + + initialPlayspace.transform.localScale = playspace.localScale; + // Rotation initialPlayspacePosition = playspace.position; @@ -483,9 +504,7 @@ protected void SetInitialValues () public void ScalePlayspaceAroundPoint (float scaleRatio, float newScale) { - playspace.localScale = new Vector3(newScale, newScale, newScale); - - playspace.position = ((playspace.position - initialPivotPointInPlayspace.position) * scaleRatio) + initialPivotPointInPlayspace.position; + } public void UpdateLineRenderersScale (float newScale) @@ -500,7 +519,7 @@ public void SendAvatarScaleUpdate (float newScale) public void OnUpdate (float realltime) { - // Scale + // Compute Scale handDistanceInPlayspace.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position) / playspace.localScale.x; @@ -515,13 +534,7 @@ public void OnUpdate (float realltime) float clampedScaleRatio = clampedNewScale / initialPlayspaceScale; - ScalePlayspaceAroundPoint(clampedScaleRatio, clampedNewScale); - - UpdateLineRenderersScale(clampedNewScale); - - SendAvatarScaleUpdate(clampedNewScale); - - // Rotation + // Compute Rotation UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); @@ -529,7 +542,13 @@ public void OnUpdate (float realltime) UpdateDebugAxes(); - RotatePlayspaceAroundPoint(rotateAmount); + // Apply Scale and Rotation + + RotateAndScalePlayspaceAroundPoint(rotateAmount, clampedScaleRatio, clampedNewScale); + + UpdateLineRenderersScale(clampedNewScale); + + SendAvatarScaleUpdate(clampedNewScale); // Ruler @@ -550,7 +569,7 @@ public void OnUpdate (float realltime) public void OnDestroy () { - Destroy(currentPlayspaceObject); + Destroy(initialPlayspace); } } } From 881bd0033be1e4101fd4008e125a971753804468 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Mon, 10 Jan 2022 16:45:00 -0600 Subject: [PATCH 09/17] WIP: successfully got rotateAround and scaleAround to work; need to add translate --- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index f990e775..87c23c07 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -424,15 +424,28 @@ public void RotateAndScalePlayspaceAroundPoint (float amount, float scaleRatio, // Make our own client rotate in the opposite direction that our hands did amount *= -1.0f; - // Compute position and rotation as if not scaling - initialPlayspace.transform.RotateAround(copyOfInitialPivotPointPosition, Vector3.up, amount); + // Update rotation and position -- temporarily store new transform values inside of initialPlayspace itself + Vector3 actualInitialPlayspacePosition = initialPlayspace.transform.position; - // Find position after scaling and rotation and apply it - playspace.position = ((initialPlayspace.transform.position - copyOfInitialPivotPointPosition) * scaleRatio) + copyOfInitialPivotPointPosition; + Quaternion actualInitialPlayspaceRotation = initialPlayspace.transform.rotation; + + // This is because RotateAround does not return a new transform, so we must operate on an existing object + // We don't want to rotate the playspace itself because we want to rotate from some constant initial direction + // Rather than rotating from the last frame's playspace's orientation + initialPlayspace.transform.RotateAround(copyOfInitialPivotPointPosition, Vector3.up, amount); playspace.rotation = initialPlayspace.transform.rotation; + // Scale around a point: move to new position + playspace.position = ((initialPlayspace.transform.position - copyOfInitialPivotPointPosition) * scaleRatio) + copyOfInitialPivotPointPosition; + + // Scale around a point: update scale playspace.localScale = new Vector3(newScale, newScale, newScale); + + // Reset initialPlayspace + initialPlayspace.transform.position = actualInitialPlayspacePosition; + + initialPlayspace.transform.rotation = actualInitialPlayspaceRotation; } public void UpdateRulerPose (Vector3 hand0Position, Vector3 hand1Position, float scale) @@ -519,6 +532,8 @@ public void SendAvatarScaleUpdate (float newScale) public void OnUpdate (float realltime) { + UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); + // Compute Scale handDistanceInPlayspace.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position) / playspace.localScale.x; @@ -536,8 +551,6 @@ public void OnUpdate (float realltime) // Compute Rotation - UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); - float rotateAmount = ComputeDiffRotationY(initialPivotPointInPlayspace.rotation, currentPivotPointInPlayspace.rotation); UpdateDebugAxes(); From 3b42ae2ce5152286eba11c596dff8941eaa1459a Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Mon, 10 Jan 2022 18:18:56 -0600 Subject: [PATCH 10/17] Successfully implemented basic world pulling with limited scale range --- .../Assets/IMPRESS/Prefab/WorldPulling.prefab | 3 ++- .../Assets/IMPRESS/Scene/Main.unity | 20 ---------------- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 24 ++++++++++++++----- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Prefab/WorldPulling.prefab b/KOMODO-IMPRESS/Assets/IMPRESS/Prefab/WorldPulling.prefab index 270b5bbb..45172e70 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Prefab/WorldPulling.prefab +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Prefab/WorldPulling.prefab @@ -127,7 +127,8 @@ MonoBehaviour: - {fileID: 2100000, guid: 02fef1dbd624dcc4d9c9ab88a7e922d4, type: 2} - {fileID: 2100000, guid: d7589b41c4f527c44af461d54cf01d52, type: 2} - {fileID: 2100000, guid: 093e7be84ebdb7940ba941aee252cbf9, type: 2} - - {fileID: 2100000, guid: 093e7be84ebdb7940ba941aee252cbf9, type: 2} + - {fileID: 2100000, guid: 1bf2a636382de314d883fcb85d081587, type: 2} + - {fileID: 2100000, guid: 381fb7f0084fa1d4982d467aa0d80e0a, type: 2} --- !u!120 &4935357643860465841 LineRenderer: m_ObjectHideFlags: 0 diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity index 01d63125..72f5eca2 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/Main.unity @@ -3433,11 +3433,6 @@ PrefabInstance: propertyPath: physicalFloor value: objectReference: {fileID: 6308719959967395149} - - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, - type: 3} - propertyPath: showDebugAxes - value: 1 - objectReference: {fileID: 0} - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, type: 3} propertyPath: teleportPlayer @@ -3453,21 +3448,6 @@ PrefabInstance: propertyPath: hands.Array.data[1] value: objectReference: {fileID: 8472804883547595920} - - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, - type: 3} - propertyPath: materials.Array.size - value: 7 - objectReference: {fileID: 0} - - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, - type: 3} - propertyPath: materials.Array.data[5] - value: - objectReference: {fileID: 2100000, guid: 1bf2a636382de314d883fcb85d081587, type: 2} - - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, - type: 3} - propertyPath: materials.Array.data[6] - value: - objectReference: {fileID: 2100000, guid: 381fb7f0084fa1d4982d467aa0d80e0a, type: 2} - target: {fileID: 4935357643860465840, guid: 85334d0d9069bb546bb3379686af011c, type: 3} propertyPath: debugAxesMaterials.Array.size diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 87c23c07..df8b7a64 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -424,25 +424,37 @@ public void RotateAndScalePlayspaceAroundPoint (float amount, float scaleRatio, // Make our own client rotate in the opposite direction that our hands did amount *= -1.0f; - // Update rotation and position -- temporarily store new transform values inside of initialPlayspace itself + // Temporarily store initialPlayspace's values Vector3 actualInitialPlayspacePosition = initialPlayspace.transform.position; Quaternion actualInitialPlayspaceRotation = initialPlayspace.transform.rotation; - // This is because RotateAround does not return a new transform, so we must operate on an existing object - // We don't want to rotate the playspace itself because we want to rotate from some constant initial direction - // Rather than rotating from the last frame's playspace's orientation + // Update rotation and position + + // We must perform this on initialPlayspace + // because RotateAround does not return a new + // transform. + + // We don't want to rotate the playspace itself, because + // we want to rotate from some constant initial direction. + // Rather than rotating from the last frame's playspace's + // orientation. initialPlayspace.transform.RotateAround(copyOfInitialPivotPointPosition, Vector3.up, amount); playspace.rotation = initialPlayspace.transform.rotation; // Scale around a point: move to new position - playspace.position = ((initialPlayspace.transform.position - copyOfInitialPivotPointPosition) * scaleRatio) + copyOfInitialPivotPointPosition; + Vector3 scaledAroundPosition = ((initialPlayspace.transform.position - copyOfInitialPivotPointPosition) * scaleRatio) + copyOfInitialPivotPointPosition; // Scale around a point: update scale playspace.localScale = new Vector3(newScale, newScale, newScale); - // Reset initialPlayspace + // Translate + Vector3 deltaPosition = Vector3.zero - (currentPivotPointInPlayspace.position - initialPivotPointInPlayspace.position); + + playspace.position = scaledAroundPosition + deltaPosition; + + // Restore initialPlayspace from stored values initialPlayspace.transform.position = actualInitialPlayspacePosition; initialPlayspace.transform.rotation = actualInitialPlayspaceRotation; From 460d0580025ca2763bebca0ce80aa5e79cec73e9 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Mon, 10 Jan 2022 19:07:09 -0600 Subject: [PATCH 11/17] increased scale range to 0.1m to 10m --- .../Assets/IMPRESS/Prefab/WorldPulling.prefab | 4 +-- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Prefab/WorldPulling.prefab b/KOMODO-IMPRESS/Assets/IMPRESS/Prefab/WorldPulling.prefab index 45172e70..e5e2bd48 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Prefab/WorldPulling.prefab +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Prefab/WorldPulling.prefab @@ -99,8 +99,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: debdd6d91d87b624d876090dcc21992a, type: 3} m_Name: m_EditorClassIdentifier: - scaleMin: 0.835 - scaleMax: 1.94 + scaleMin: 0.1 + scaleMax: 10 debugAxes: {fileID: 7500337663012258881, guid: 2d19101d6d3ac6c438d33c092cc080b1, type: 3} showDebugAxes: 0 diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index df8b7a64..010212ac 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -10,9 +10,9 @@ namespace Komodo.IMPRESS { public class WorldPulling : MonoBehaviour, IUpdatable { - public float scaleMin = 0.835f; + public float scaleMin = 0.1f; - public float scaleMax = 1.94f; + public float scaleMax = 10.0f; public GameObject debugAxes; @@ -476,7 +476,22 @@ public void UpdateHandToHandLineEndpoints (Vector3 hand0Position, Vector3 hand1P public float ComputeRulerValue (float playerScale) { - return (playerScale - 0.9f) / 1.3f; + const float rulerMin = 0.0f; + + const float rulerMax = 1.0f; + + if (scaleMax - scaleMin == 0) + { + Debug.LogWarning("scaleMax - scaleMin was zero. Setting to 0.1m and 10m and proceeding."); + + scaleMin = 0.1f; + + scaleMax = 10f; + } + + float percentScale = (playerScale - scaleMin) / (scaleMax - scaleMin); + + return (percentScale * (rulerMax - rulerMin)) + rulerMin; } public void UpdateRulerValue (float newScale) @@ -502,6 +517,10 @@ protected void SetInitialValues () handDistanceInPlayspace = new UpdatingValue(Vector3.Distance(hands[0].position, hands[1].position) / playspace.localScale.x); + float clampedInitialScale = Mathf.Clamp(playspace.localScale.x, scaleMin, scaleMax); + + playspace.localScale = Vector3.one * clampedInitialScale; + initialPlayspaceScale = playspace.localScale.x; // Copy the transform to a new gameObject. From 712715450961680baf8fd63b16e45cde61426877 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Tue, 11 Jan 2022 12:12:54 -0600 Subject: [PATCH 12/17] allow unsafe code --- KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset b/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset index 4d3ed88b..9a0082d6 100644 --- a/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset +++ b/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset @@ -169,6 +169,7 @@ PlayerSettings: - {fileID: 0} - {fileID: 0} - {fileID: 0} + - {fileID: 0} - {fileID: 11400000, guid: 6145319c34f440441bbabe329561f17c, type: 2} - {fileID: 0} - {fileID: 2910771567588298596, guid: ac933aa07b1097d47a08984d469dccfc, type: 2} @@ -635,7 +636,7 @@ PlayerSettings: managedStrippingLevel: {} incrementalIl2cppBuild: {} suppressCommonWarnings: 1 - allowUnsafeCode: 0 + allowUnsafeCode: 1 useDeterministicCompilation: 1 useReferenceAssemblies: 1 enableRoslynAnalyzers: 1 From 49e15aed401807ffafaec9568091de9c35f91855 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Fri, 14 Jan 2022 12:36:53 -0600 Subject: [PATCH 13/17] removed unnecessary comments, variables, functions --- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 18 ------------------ .../ProjectSettings/ProjectSettings.asset | 9 +++++---- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 010212ac..95ce1abe 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -322,8 +322,6 @@ private void UpdateDebugAxes () [ContextMenu("Start World Pulling")] public void StartWorldPulling() { - Debug.Log("started world pulling"); //TODO Remove - SetInitialValues(); animalRuler.gameObject.SetActive(true); @@ -376,13 +374,6 @@ public Vector3 ComputePositionDifference (UpdatingValue handsAveragePos return handsAveragePosition.Initial - handsAveragePosition.Current; } - // Computes the dif - - public float ComputeScaleRatio (UpdatingValue handDistance, UpdatingValue playerLocalScaleX) - { - return handDistance.Initial / handDistance.Current * (playerLocalScaleX.Initial * playerLocalScaleX.Current); - } - public float ComputeDiffRotationY (Quaternion initial, Quaternion current) { float result = (current.eulerAngles - initial.eulerAngles).y; @@ -546,11 +537,6 @@ protected void SetInitialValues () handsAverageLocalPosition = new UpdatingValue(currentPivotPointInPlayspace.position - playspace.position); } - public void ScalePlayspaceAroundPoint (float scaleRatio, float newScale) - { - - } - public void UpdateLineRenderersScale (float newScale) { // TODO: update size of drawing strokes here @@ -605,10 +591,6 @@ public void OnUpdate (float realltime) // Position handsAverageLocalPosition.Current = currentPivotPointInPlayspace.position - playspace.position; - - Vector3 newPosition = ComputePositionDifference(handsAverageLocalPosition) + initialLeftEyePosition; - - //TODO put back UpdatePlayerPosition(newPosition); } public void OnDestroy () diff --git a/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset b/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset index 9a0082d6..ce500bbb 100644 --- a/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset +++ b/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset @@ -170,11 +170,12 @@ PlayerSettings: - {fileID: 0} - {fileID: 0} - {fileID: 0} - - {fileID: 11400000, guid: 6145319c34f440441bbabe329561f17c, type: 2} - {fileID: 0} - - {fileID: 2910771567588298596, guid: ac933aa07b1097d47a08984d469dccfc, type: 2} - - {fileID: 11400000, guid: a5e5b7605fb48984988490688c2a74e2, type: 2} - - {fileID: 2478256764130162806, guid: 552445d583cb06c4eaf9d56596dd45c2, type: 2} + - {fileID: 0} + - {fileID: 0} + - {fileID: 0} + - {fileID: 0} + - {fileID: 11400000, guid: 6145319c34f440441bbabe329561f17c, type: 2} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1 From 4f68f9228e67073cde6f1b77220c78ac681487c6 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Fri, 14 Jan 2022 13:09:12 -0600 Subject: [PATCH 14/17] added comments; removed unnecessary variables/functions --- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 169 ++++++------------ 1 file changed, 57 insertions(+), 112 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 95ce1abe..8b564d42 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -10,26 +10,16 @@ namespace Komodo.IMPRESS { public class WorldPulling : MonoBehaviour, IUpdatable { - public float scaleMin = 0.1f; - - public float scaleMax = 10.0f; - - public GameObject debugAxes; - - public bool showDebugAxes; - - /* - A convenient way to declare a variable that has an initial value and current value. - To use this, do - - T varName = new UpdatingValue(initialValueHere); - - to set the initial value. Then do - - varName.Current = currentValueHere; - - to update it. Then, you can refer to varName.Initial and varName.Current. - */ + // A convenient way to declare a variable that has an initial value and current value. + // To use this, do + // + // T varName = new UpdatingValue(initialValueHere); + // + // to set the initial value. Then do + // + // varName.Current = currentValueHere; + // + // to update it. Then, you can refer to varName.Initial and varName.Current. [Serializable] public struct UpdatingValue { @@ -45,72 +35,73 @@ public UpdatingValue(T initial) public T Current { get; set; } } - [SerializeField] - private UpdatingValue playerLocalScaleX; + // Assign a Komodo Player or Impress Player object so we can access its hands + public Transform player; - private float initialPlayspaceScale; + // Assign a playspace, so we can scale, rotate, and translate the avatar, + // while still allowing the player to move around + public Transform playspace; - [SerializeField] - private UpdatingValue handDistanceInPlayspace; + // Assign the player rig's hands so we can read their transform values + private Transform[] hands = new Transform[2]; - [SerializeField] - private Vector3 initialLeftEyePosition; + // Connect this action as a callback in Unity. + public Action onDoubleTriggerPress; - // With respect to the playspace. - [SerializeField] - private UpdatingValue handsAverageLocalPosition; + // Connect this action as a callback in Unity. + public Action onDoubleTriggerRelease; - private LineRenderer handToHandLine; + // Set the min scale for the avatar + public float scaleMin = 0.1f; + // Set the max scale for the avatar + public float scaleMax = 10.0f; + + // This is taken from Google Tilt Brush and has a texture that shows the current scale public MeshRenderer animalRulerMesh; + // This is also taken from Google Tilt Brush public Transform animalRuler; + // Assign a prefab here to help the user feel oriented towards the physical world while world pulling public GameObject physicalFloor; + // If you need to manage what's visible or not during world-pulling, + // set up a layer manager and assign it here public LayerVisibility layerManager; - //get parent if we are switching objects between hands we want to keep track of were to place it back, to avoid hierachy parenting displacement - public Transform originalParentOfFirstHandTransform; - - public Transform[] hands = new Transform[2]; - - private Transform initialPivotPointInPlayspace; - - public Transform currentPivotPointInPlayspace; - - // Connect this action as a callback in Unity. - public Action onDoubleTriggerPress; - - // Connect this action as a callback in Unity. - public Action onDoubleTriggerRelease; - - public Transform player; + // Assign a prefab in the inspector that will represent the position, scale, + // and rotation of world-pulling objects + public GameObject debugAxes; - public Transform leftEye; + // Assign materials for each debug axis that gets created. See below to understand + // How many materials you need. + public Material[] materials; - public Transform playspace; + // Turn this on to show the various debug axes that are created. + public bool showDebugAxes; - public TeleportPlayer teleportPlayer; + private Transform initialPivotPointInPlayspace; - public Vector3 initialPlayspacePosition; + private Transform currentPivotPointInPlayspace; - public Quaternion initialPlayspaceRotation; + private Vector3 copyOfInitialPivotPointPosition; - public float initialScale = 1; + private GameObject copyOfInitialPivotPointPositionAxes; private GameObject initialPlayspace; - public Material[] materials; + // This is the distance between the hands divided by the scale of the playspace + [SerializeField] + private UpdatingValue handDistanceInPlayspace; + + // When world-pulling, this is a line segment to hint that the user should move their hands + private LineRenderer handToHandLine; private GameObject initialPlayspaceAxes; private GameObject currentPlayspaceAxes; - private Vector3 copyOfInitialPivotPointPosition; - - private GameObject copyOfInitialPivotPointPositionAxes; - public void Awake() { initialPivotPointInPlayspace = new GameObject("InitialPivotPoint").transform; @@ -127,15 +118,10 @@ public void Awake() } initialPlayspace = new GameObject(); - - initialPlayspacePosition = new Vector3(); - - initialPlayspaceRotation = new Quaternion(); } public void Start() { - // This is the playspace. if (playspace == null) { playspace = GameObject.FindGameObjectWithTag("XRCamera").transform; @@ -143,11 +129,6 @@ public void Start() player = GameObject.FindGameObjectWithTag("Player").transform; - if (!leftEye) - { - throw new UnassignedReferenceException("leftEye"); - } - if (!player) { throw new UnassignedReferenceException("player"); @@ -163,13 +144,6 @@ public void Start() throw new MissingComponentException("PlayerReferences on player"); } - teleportPlayer = player.GetComponent(); - - if (!teleportPlayer) - { - throw new MissingComponentException("TeleportPlayer on player"); - } - InitializeDebugAxes(); handToHandLine = gameObject.GetComponent(); @@ -312,9 +286,9 @@ private void UpdateDebugAxes () return; } - initialPlayspaceAxes.transform.position = initialPlayspacePosition; + initialPlayspaceAxes.transform.position = initialPlayspace.transform.position; - initialPlayspaceAxes.transform.rotation = initialPlayspaceRotation; + initialPlayspaceAxes.transform.rotation = initialPlayspace.transform.rotation; copyOfInitialPivotPointPositionAxes.transform.position = copyOfInitialPivotPointPosition; } @@ -399,18 +373,7 @@ public void UpdateLocalPivotPoint (Transform pivotPointInPlayspace, Vector3 hand pivotPointInPlayspace.localRotation = Quaternion.Inverse(playspace.rotation) * Quaternion.LookRotation(deltaHandPositionsXZ, Vector3.up); } - public void UpdatePlayerPosition (Vector3 teleportLocation) - { - var finalPlayspacePosition = playspace.position; - - Vector3 deltaPosition = teleportLocation - leftEye.position; - - finalPlayspacePosition += deltaPosition; - - playspace.position = finalPlayspacePosition; - } - - public void RotateAndScalePlayspaceAroundPoint (float amount, float scaleRatio, float newScale) + public void RotateAndScalePlayspaceAroundPointThenTranslate (float amount, float scaleRatio, float newScale) { // Make our own client rotate in the opposite direction that our hands did amount *= -1.0f; @@ -512,8 +475,6 @@ protected void SetInitialValues () playspace.localScale = Vector3.one * clampedInitialScale; - initialPlayspaceScale = playspace.localScale.x; - // Copy the transform to a new gameObject. initialPlayspace.transform.position = playspace.position; @@ -522,19 +483,7 @@ protected void SetInitialValues () initialPlayspace.transform.localScale = playspace.localScale; - // Rotation - - initialPlayspacePosition = playspace.position; - - initialPlayspaceRotation = playspace.rotation; - UpdateDebugAxes(); - - // Position - - initialLeftEyePosition = leftEye.position; - - handsAverageLocalPosition = new UpdatingValue(currentPivotPointInPlayspace.position - playspace.position); } public void UpdateLineRenderersScale (float newScale) @@ -547,7 +496,7 @@ public void SendAvatarScaleUpdate (float newScale) //TODO: send message that avatar scale changed to other clients } - public void OnUpdate (float realltime) + public void OnUpdate (float unusedFloat) { UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); @@ -557,14 +506,14 @@ public void OnUpdate (float realltime) float unclampedScaleRatio = 1.0f / (handDistanceInPlayspace.Current / handDistanceInPlayspace.Initial); - float clampedNewScale = Mathf.Clamp(unclampedScaleRatio * initialPlayspaceScale, scaleMin, scaleMax); + float clampedNewScale = Mathf.Clamp(unclampedScaleRatio * initialPlayspace.transform.localScale.x, scaleMin, scaleMax); if (clampedNewScale > -0.001f && clampedNewScale < 0.001f) { clampedNewScale = 0.0f; } - float clampedScaleRatio = clampedNewScale / initialPlayspaceScale; + float clampedScaleRatio = clampedNewScale / initialPlayspace.transform.localScale.x; // Compute Rotation @@ -572,9 +521,9 @@ public void OnUpdate (float realltime) UpdateDebugAxes(); - // Apply Scale and Rotation + // Apply Scale and Rotation and Translation - RotateAndScalePlayspaceAroundPoint(rotateAmount, clampedScaleRatio, clampedNewScale); + RotateAndScalePlayspaceAroundPointThenTranslate(rotateAmount, clampedScaleRatio, clampedNewScale); UpdateLineRenderersScale(clampedNewScale); @@ -587,10 +536,6 @@ public void OnUpdate (float realltime) UpdateRulerPose(hands[0].transform.position, hands[1].transform.position, clampedNewScale); UpdateHandToHandLineEndpoints(hands[0].transform.position, hands[1].transform.position); - - // Position - - handsAverageLocalPosition.Current = currentPivotPointInPlayspace.position - playspace.position; } public void OnDestroy () From 1e3ece58dd1de31701a7cb80ccc41271edb7fcbc Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Fri, 14 Jan 2022 13:24:37 -0600 Subject: [PATCH 15/17] rearranged functions and added comments to all functions --- .../Assets/IMPRESS/Scripts/WorldPulling.cs | 388 ++++++++++-------- 1 file changed, 206 insertions(+), 182 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 8b564d42..5ab9099f 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -181,118 +181,8 @@ public void Start() onDoubleTriggerRelease += StopWorldPulling; } - private void InitializeDebugAxes() - { - if (!showDebugAxes) - { - return; - } - - var initialPivotPointAxes = Instantiate(debugAxes); - - initialPivotPointAxes.transform.parent = initialPivotPointInPlayspace; - - initialPivotPointAxes.transform.localPosition = Vector3.zero; - - initialPivotPointAxes.transform.localRotation = Quaternion.identity; - - initialPivotPointAxes.transform.GetChild(0).GetComponent().material = materials[0]; - - initialPivotPointAxes.transform.GetChild(1).GetComponent().material = materials[0]; - - initialPivotPointAxes.transform.GetChild(2).GetComponent().material = materials[0]; - - var currentPivotPointAxes = Instantiate(debugAxes); - - currentPivotPointAxes.transform.parent = currentPivotPointInPlayspace; - - currentPivotPointAxes.transform.localPosition = Vector3.zero; - - currentPivotPointAxes.transform.localRotation = Quaternion.identity; - - currentPivotPointAxes.transform.GetChild(0).GetComponent().material = materials[1]; - - currentPivotPointAxes.transform.GetChild(1).GetComponent().material = materials[1]; - - currentPivotPointAxes.transform.GetChild(2).GetComponent().material = materials[1]; - - initialPlayspaceAxes = Instantiate(debugAxes); - - initialPlayspaceAxes.transform.GetChild(0).GetComponent().material = materials[2]; - - initialPlayspaceAxes.transform.GetChild(1).GetComponent().material = materials[2]; - - initialPlayspaceAxes.transform.GetChild(2).GetComponent().material = materials[2]; - - currentPlayspaceAxes = Instantiate(debugAxes); - - currentPlayspaceAxes.transform.parent = playspace; - - currentPlayspaceAxes.transform.GetChild(0).GetComponent().material = materials[3]; - - currentPlayspaceAxes.transform.GetChild(1).GetComponent().material = materials[3]; - - currentPlayspaceAxes.transform.GetChild(2).GetComponent().material = materials[3]; - - var hand0Axes = Instantiate(debugAxes); - - hand0Axes.transform.parent = hands[0]; - - hand0Axes.transform.localPosition = Vector3.zero; - - hand0Axes.transform.localRotation = Quaternion.identity; - - hand0Axes.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); - - hand0Axes.transform.GetChild(0).GetComponent().material = materials[4]; - - hand0Axes.transform.GetChild(1).GetComponent().material = materials[4]; - - hand0Axes.transform.GetChild(2).GetComponent().material = materials[4]; - - var hand1Axes = Instantiate(debugAxes); - - hand1Axes.transform.parent = hands[1]; - - hand1Axes.transform.localPosition = Vector3.zero; - - hand1Axes.transform.localRotation = Quaternion.identity; - - hand1Axes.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); - - hand1Axes.transform.GetChild(0).GetComponent().material = materials[5]; - - hand1Axes.transform.GetChild(1).GetComponent().material = materials[5]; - - hand1Axes.transform.GetChild(2).GetComponent().material = materials[5]; - - copyOfInitialPivotPointPositionAxes = Instantiate(debugAxes); - - copyOfInitialPivotPointPositionAxes.transform.localPosition = Vector3.zero; - - copyOfInitialPivotPointPositionAxes.transform.localRotation = Quaternion.identity; - - copyOfInitialPivotPointPositionAxes.transform.GetChild(0).GetComponent().material = materials[6]; - - copyOfInitialPivotPointPositionAxes.transform.GetChild(1).GetComponent().material = materials[6]; - - copyOfInitialPivotPointPositionAxes.transform.GetChild(2).GetComponent().material = materials[6]; - } - - private void UpdateDebugAxes () - { - if (!showDebugAxes) - { - return; - } - - initialPlayspaceAxes.transform.position = initialPlayspace.transform.position; - - initialPlayspaceAxes.transform.rotation = initialPlayspace.transform.rotation; - - copyOfInitialPivotPointPositionAxes.transform.position = copyOfInitialPivotPointPosition; - } - + // It will feel like the player is pulling the world, but really they are pushing themselves + // in the opposite direction, with an inverse rotation, and and inverse scale. [ContextMenu("Start World Pulling")] public void StartWorldPulling() { @@ -333,46 +223,80 @@ public void StopWorldPulling() Debug.Log("stopped world pulling"); //TODO Remove } - private void ShowPhysicalFloor () + // Stores transforms of gameObjects and variables used to compute scale, rotation, and translation + protected void SetInitialValues () { - physicalFloor.SetActive(true); - } + UpdateLocalPivotPoint(initialPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); - private void HidePhysicalFloor () - { - physicalFloor.SetActive(false); - } + copyOfInitialPivotPointPosition = initialPivotPointInPlayspace.position; - public Vector3 ComputePositionDifference (UpdatingValue handsAveragePosition) - { - return handsAveragePosition.Initial - handsAveragePosition.Current; + UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); + + // Scale + + handDistanceInPlayspace = new UpdatingValue(Vector3.Distance(hands[0].position, hands[1].position) / playspace.localScale.x); + + float clampedInitialScale = Mathf.Clamp(playspace.localScale.x, scaleMin, scaleMax); + + playspace.localScale = Vector3.one * clampedInitialScale; + + // Copy the transform to a new gameObject. + + initialPlayspace.transform.position = playspace.position; + + initialPlayspace.transform.rotation = playspace.rotation; + + initialPlayspace.transform.localScale = playspace.localScale; + + UpdateDebugAxes(); } - public float ComputeDiffRotationY (Quaternion initial, Quaternion current) + // This function is used externally by the GameStateManager. + // Compares the current transforms of the hands to the initial transforms, then calls various functions + // to make the world pulling experience happen. + public void OnUpdate (float unusedFloat) { - float result = (current.eulerAngles - initial.eulerAngles).y; + UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); - if (result > -0.001f && result < 0.001f) + // Compute Scale + + handDistanceInPlayspace.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position) / playspace.localScale.x; + + float unclampedScaleRatio = 1.0f / (handDistanceInPlayspace.Current / handDistanceInPlayspace.Initial); + + float clampedNewScale = Mathf.Clamp(unclampedScaleRatio * initialPlayspace.transform.localScale.x, scaleMin, scaleMax); + + if (clampedNewScale > -0.001f && clampedNewScale < 0.001f) { - result = 0.0f; + clampedNewScale = 0.0f; } - return result; - } + float clampedScaleRatio = clampedNewScale / initialPlayspace.transform.localScale.x; - public void UpdateLocalPivotPoint (Transform pivotPointInPlayspace, Vector3 hand0Position, Vector3 hand1Position) - { - pivotPointInPlayspace.localPosition = playspace.InverseTransformPoint((hand0Position + hand1Position) / 2); + // Compute Rotation - Vector3 deltaHandPositionsXZ = new Vector3( - (hand1Position - hand0Position).x, - 0, - (hand1Position - hand0Position).z - ); + float rotateAmount = ComputeDiffRotationY(initialPivotPointInPlayspace.rotation, currentPivotPointInPlayspace.rotation); - pivotPointInPlayspace.localRotation = Quaternion.Inverse(playspace.rotation) * Quaternion.LookRotation(deltaHandPositionsXZ, Vector3.up); + UpdateDebugAxes(); + + // Apply Scale and Rotation and Translation + + RotateAndScalePlayspaceAroundPointThenTranslate(rotateAmount, clampedScaleRatio, clampedNewScale); + + UpdateLineRenderersScale(clampedNewScale); + + SendAvatarScaleUpdate(clampedNewScale); + + // Ruler + + UpdateRulerValue(clampedNewScale); + + UpdateRulerPose(hands[0].transform.position, hands[1].transform.position, clampedNewScale); + + UpdateHandToHandLineEndpoints(hands[0].transform.position, hands[1].transform.position); } + // Applies translation, rotation, and scale to the actual playspace. public void RotateAndScalePlayspaceAroundPointThenTranslate (float amount, float scaleRatio, float newScale) { // Make our own client rotate in the opposite direction that our hands did @@ -414,6 +338,37 @@ public void RotateAndScalePlayspaceAroundPointThenTranslate (float amount, float initialPlayspace.transform.rotation = actualInitialPlayspaceRotation; } + // Computes the transform of an invisible object that has the average position of the hands, a rotation corresponding to + // the line drawn between the two hands, and a scale corresponding to the distance between the hands. + // Makes all values relative to the playspace, so that even as the playspace scales, rotates, and translates, we can compute + // the correct difference corresponding to the user's physical actions + public void UpdateLocalPivotPoint (Transform pivotPointInPlayspace, Vector3 hand0Position, Vector3 hand1Position) + { + pivotPointInPlayspace.localPosition = playspace.InverseTransformPoint((hand0Position + hand1Position) / 2); + + Vector3 deltaHandPositionsXZ = new Vector3( + (hand1Position - hand0Position).x, + 0, + (hand1Position - hand0Position).z + ); + + pivotPointInPlayspace.localRotation = Quaternion.Inverse(playspace.rotation) * Quaternion.LookRotation(deltaHandPositionsXZ, Vector3.up); + } + + // Takes a rotation difference and returns that rotation difference projected to just a rotation around the Y axis. + public float ComputeDiffRotationY (Quaternion initial, Quaternion current) + { + float result = (current.eulerAngles - initial.eulerAngles).y; + + if (result > -0.001f && result < 0.001f) + { + result = 0.0f; + } + + return result; + } + + // Makes the ruler always be between the hands and the right size. public void UpdateRulerPose (Vector3 hand0Position, Vector3 hand1Position, float scale) { animalRuler.position = ((hand0Position + hand1Position) / 2); @@ -421,6 +376,7 @@ public void UpdateRulerPose (Vector3 hand0Position, Vector3 hand1Position, float animalRuler.localScale = Vector3.one * scale; } + // Makes the hand-to-hand line always be connected to both hands. public void UpdateHandToHandLineEndpoints (Vector3 hand0Position, Vector3 hand1Position) { handToHandLine.SetPosition(0, hand0Position); @@ -428,6 +384,7 @@ public void UpdateHandToHandLineEndpoints (Vector3 hand0Position, Vector3 hand1P handToHandLine.SetPosition(1, hand1Position); } + // Scales the playspace scale range to the ruler's texture offset range public float ComputeRulerValue (float playerScale) { const float rulerMin = 0.0f; @@ -448,6 +405,7 @@ public float ComputeRulerValue (float playerScale) return (percentScale * (rulerMax - rulerMin)) + rulerMin; } + // Updates the ruler's texture offset public void UpdateRulerValue (float newScale) { var rulerValue = ComputeRulerValue(newScale); @@ -459,89 +417,155 @@ public void UpdateRulerValue (float newScale) animalRulerMesh.material.SetTextureOffset("_MainTex", new Vector2(Mathf.Clamp(rulerValue, min, max), 0)); } - protected void SetInitialValues () + // TODO: Makes the current line renderer scale change proportionally with the playspace scale + public void UpdateLineRenderersScale (float newScale) { - UpdateLocalPivotPoint(initialPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); + // TODO: update size of drawing strokes here + } - copyOfInitialPivotPointPosition = initialPivotPointInPlayspace.position; + // TODO: Sends the playspace scale to other multiplayer clients, so their prefab avatar head and + // hand represetnations of your own client are the correct size + public void SendAvatarScaleUpdate (float newScale) + { + //TODO: send message that avatar scale changed to other clients + } - UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); + // Shows motion-sickness helper + private void ShowPhysicalFloor () + { + physicalFloor.SetActive(true); + } - // Scale + // Hides motion-sickness helper + private void HidePhysicalFloor () + { + physicalFloor.SetActive(false); + } - handDistanceInPlayspace = new UpdatingValue(Vector3.Distance(hands[0].position, hands[1].position) / playspace.localScale.x); + // Creates debug axes iff showDebugAxes is on + private void InitializeDebugAxes() + { + if (!showDebugAxes) + { + return; + } - float clampedInitialScale = Mathf.Clamp(playspace.localScale.x, scaleMin, scaleMax); + var initialPivotPointAxes = Instantiate(debugAxes); - playspace.localScale = Vector3.one * clampedInitialScale; + initialPivotPointAxes.transform.parent = initialPivotPointInPlayspace; - // Copy the transform to a new gameObject. + initialPivotPointAxes.transform.localPosition = Vector3.zero; - initialPlayspace.transform.position = playspace.position; + initialPivotPointAxes.transform.localRotation = Quaternion.identity; - initialPlayspace.transform.rotation = playspace.rotation; + initialPivotPointAxes.transform.GetChild(0).GetComponent().material = materials[0]; - initialPlayspace.transform.localScale = playspace.localScale; + initialPivotPointAxes.transform.GetChild(1).GetComponent().material = materials[0]; - UpdateDebugAxes(); - } + initialPivotPointAxes.transform.GetChild(2).GetComponent().material = materials[0]; - public void UpdateLineRenderersScale (float newScale) - { - // TODO: update size of drawing strokes here - } + var currentPivotPointAxes = Instantiate(debugAxes); - public void SendAvatarScaleUpdate (float newScale) - { - //TODO: send message that avatar scale changed to other clients - } + currentPivotPointAxes.transform.parent = currentPivotPointInPlayspace; - public void OnUpdate (float unusedFloat) - { - UpdateLocalPivotPoint(currentPivotPointInPlayspace, hands[0].transform.position, hands[1].transform.position); + currentPivotPointAxes.transform.localPosition = Vector3.zero; - // Compute Scale + currentPivotPointAxes.transform.localRotation = Quaternion.identity; - handDistanceInPlayspace.Current = Vector3.Distance(hands[0].transform.position, hands[1].transform.position) / playspace.localScale.x; + currentPivotPointAxes.transform.GetChild(0).GetComponent().material = materials[1]; - float unclampedScaleRatio = 1.0f / (handDistanceInPlayspace.Current / handDistanceInPlayspace.Initial); + currentPivotPointAxes.transform.GetChild(1).GetComponent().material = materials[1]; - float clampedNewScale = Mathf.Clamp(unclampedScaleRatio * initialPlayspace.transform.localScale.x, scaleMin, scaleMax); + currentPivotPointAxes.transform.GetChild(2).GetComponent().material = materials[1]; - if (clampedNewScale > -0.001f && clampedNewScale < 0.001f) - { - clampedNewScale = 0.0f; - } + initialPlayspaceAxes = Instantiate(debugAxes); - float clampedScaleRatio = clampedNewScale / initialPlayspace.transform.localScale.x; + initialPlayspaceAxes.transform.GetChild(0).GetComponent().material = materials[2]; - // Compute Rotation + initialPlayspaceAxes.transform.GetChild(1).GetComponent().material = materials[2]; - float rotateAmount = ComputeDiffRotationY(initialPivotPointInPlayspace.rotation, currentPivotPointInPlayspace.rotation); + initialPlayspaceAxes.transform.GetChild(2).GetComponent().material = materials[2]; - UpdateDebugAxes(); + currentPlayspaceAxes = Instantiate(debugAxes); - // Apply Scale and Rotation and Translation + currentPlayspaceAxes.transform.parent = playspace; - RotateAndScalePlayspaceAroundPointThenTranslate(rotateAmount, clampedScaleRatio, clampedNewScale); + currentPlayspaceAxes.transform.GetChild(0).GetComponent().material = materials[3]; - UpdateLineRenderersScale(clampedNewScale); + currentPlayspaceAxes.transform.GetChild(1).GetComponent().material = materials[3]; - SendAvatarScaleUpdate(clampedNewScale); + currentPlayspaceAxes.transform.GetChild(2).GetComponent().material = materials[3]; - // Ruler + var hand0Axes = Instantiate(debugAxes); - UpdateRulerValue(clampedNewScale); + hand0Axes.transform.parent = hands[0]; - UpdateRulerPose(hands[0].transform.position, hands[1].transform.position, clampedNewScale); + hand0Axes.transform.localPosition = Vector3.zero; - UpdateHandToHandLineEndpoints(hands[0].transform.position, hands[1].transform.position); + hand0Axes.transform.localRotation = Quaternion.identity; + + hand0Axes.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); + + hand0Axes.transform.GetChild(0).GetComponent().material = materials[4]; + + hand0Axes.transform.GetChild(1).GetComponent().material = materials[4]; + + hand0Axes.transform.GetChild(2).GetComponent().material = materials[4]; + + var hand1Axes = Instantiate(debugAxes); + + hand1Axes.transform.parent = hands[1]; + + hand1Axes.transform.localPosition = Vector3.zero; + + hand1Axes.transform.localRotation = Quaternion.identity; + + hand1Axes.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); + + hand1Axes.transform.GetChild(0).GetComponent().material = materials[5]; + + hand1Axes.transform.GetChild(1).GetComponent().material = materials[5]; + + hand1Axes.transform.GetChild(2).GetComponent().material = materials[5]; + + copyOfInitialPivotPointPositionAxes = Instantiate(debugAxes); + + copyOfInitialPivotPointPositionAxes.transform.localPosition = Vector3.zero; + + copyOfInitialPivotPointPositionAxes.transform.localRotation = Quaternion.identity; + + copyOfInitialPivotPointPositionAxes.transform.GetChild(0).GetComponent().material = materials[6]; + + copyOfInitialPivotPointPositionAxes.transform.GetChild(1).GetComponent().material = materials[6]; + + copyOfInitialPivotPointPositionAxes.transform.GetChild(2).GetComponent().material = materials[6]; + } + + // Updates the debug axes that specifically need to be recalculated; others are parented + private void UpdateDebugAxes () + { + if (!showDebugAxes) + { + return; + } + + initialPlayspaceAxes.transform.position = initialPlayspace.transform.position; + + initialPlayspaceAxes.transform.rotation = initialPlayspace.transform.rotation; + + copyOfInitialPivotPointPositionAxes.transform.position = copyOfInitialPivotPointPosition; } public void OnDestroy () { Destroy(initialPlayspace); } + + // TODO remove + public Vector3 ComputePositionDifference (UpdatingValue handsAveragePosition) + { + return handsAveragePosition.Initial - handsAveragePosition.Current; + } } } From 43ca017f812bf2ee7109df8c0a311f0c76373b2d Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Fri, 14 Jan 2022 13:38:22 -0600 Subject: [PATCH 16/17] removed unneccessary function --- KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs index 5ab9099f..c477e12c 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scripts/WorldPulling.cs @@ -560,12 +560,6 @@ public void OnDestroy () { Destroy(initialPlayspace); } - - // TODO remove - public Vector3 ComputePositionDifference (UpdatingValue handsAveragePosition) - { - return handsAveragePosition.Initial - handsAveragePosition.Current; - } } } From 87274f08e45874e6d4098877035cf9b7c8b9016d Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Thu, 20 Jan 2022 18:46:04 -0600 Subject: [PATCH 17/17] hid pink spheres --- .../Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity | 6 +++--- KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity index 4b424a9b..772e11f8 100644 --- a/KOMODO-IMPRESS/Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity +++ b/KOMODO-IMPRESS/Assets/IMPRESS/Scene/OutsideTheMilkyWay.unity @@ -236,7 +236,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!135 &1186417696 SphereCollider: m_ObjectHideFlags: 0 @@ -331,7 +331,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!135 &1275368508 SphereCollider: m_ObjectHideFlags: 0 @@ -426,7 +426,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!135 &1531216789 SphereCollider: m_ObjectHideFlags: 0 diff --git a/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset b/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset index ce500bbb..54e5cf54 100644 --- a/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset +++ b/KOMODO-IMPRESS/ProjectSettings/ProjectSettings.asset @@ -51,7 +51,7 @@ PlayerSettings: m_MTRendering: 1 mipStripping: 0 numberOfMipsStripped: 0 - m_StackTraceTypes: 010000000100000001000000010000000100000001000000 + m_StackTraceTypes: 020000000200000002000000020000000200000001000000 iosShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1 iosUseCustomAppBackgroundBehavior: 0 @@ -633,7 +633,8 @@ PlayerSettings: additionalCompilerArguments: {} platformArchitecture: {} scriptingBackend: {} - il2cppCompilerConfiguration: {} + il2cppCompilerConfiguration: + WebGL: 1 managedStrippingLevel: {} incrementalIl2cppBuild: {} suppressCommonWarnings: 1