Skip to content

Commit d5839db

Browse files
author
Jared Bienz
committed
Completed changes to nudge based on controller direction. About to test on device.
1 parent b2731ec commit d5839db

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

SpatialAlignment-Unity/Assets/SpatialAlignment/Refinement/Prefabs/NudgeController.prefab

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ BoxCollider:
143143
m_IsTrigger: 0
144144
m_Enabled: 1
145145
serializedVersion: 2
146-
m_Size: {x: 0.5, y: 0.45, z: 0.02}
147-
m_Center: {x: 0, y: 0, z: 0.17}
146+
m_Size: {x: 0.5, y: 0.8, z: 0.05}
147+
m_Center: {x: 0, y: -0.005, z: 0.2}
148148
--- !u!114 &6313569961156761970
149149
MonoBehaviour:
150150
m_ObjectHideFlags: 0

SpatialAlignment-Unity/Assets/SpatialAlignment/Refinement/Scripts/NudgeController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ protected virtual RefinementDirection GetLookDirection()
6565
forward = refinement.TargetTransform.InverseTransformDirection(transform.forward);
6666
}
6767

68-
// Normalize the forward direction
69-
Vector3 normForward = forward.normalized;
68+
// Get the absolute axis for the forward direction (snaps to axis only)
69+
forward = forward.AbsoluteAxis();
7070

71-
// Round the normalized vector to 0 decimal places
72-
Vector3 roundedForward = normForward.Round();
71+
// Normalize it toward 1.0
72+
forward = forward.normalized;
7373

7474
// Try to convert the vector to a direction
7575
RefinementDirection direction;
76-
if (roundedForward.TryGetDirection(out direction))
76+
if (forward.TryGetDirection(out direction))
7777
{
7878
return direction;
7979
}

SpatialAlignment-Unity/Assets/SpatialAlignment/Utilities/Scripts/SpatialExtensions.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,44 @@ static public bool TryGetDirection(this Vector3 vector, out RefinementDirection
311311

312312

313313
#region Vector Extensions
314+
/// <summary>
315+
/// Returns a new <see cref="Vector3"/> that contains only the greatest
316+
/// absolute value on any axis.
317+
/// </summary>
318+
/// <param name="vector">
319+
/// The vector to obtain the absolute axis for.
320+
/// </param>
321+
/// <returns>
322+
/// A <see cref="Vector3"/> with the greatest absolute axis.
323+
/// If any two axis are exactly equal, this method returns
324+
/// <see cref="Vector3.zero"/>.
325+
/// </returns>
326+
static public Vector3 AbsoluteAxis(this Vector3 vector)
327+
{
328+
// Placeholder
329+
Vector3 result = Vector3.zero;
330+
331+
// Get the absolute value of the incoming vector
332+
Vector3 abs = new Vector3(Mathf.Abs(vector.x), Mathf.Abs(vector.y), Mathf.Abs(vector.z));
333+
334+
// Select larges axis
335+
if ((abs.x > abs.y) && (abs.x > abs.z))
336+
{
337+
result.x = vector.x;
338+
}
339+
else if ((abs.y > abs.x) && (abs.y > abs.z))
340+
{
341+
result.y = vector.y;
342+
}
343+
else if ((abs.z > abs.x) && (abs.z > abs.y))
344+
{
345+
result.z = vector.z;
346+
}
347+
348+
// Done
349+
return result;
350+
}
351+
314352
/// <summary>
315353
/// Rounds a <see cref="Vector3"/>.
316354
/// </summary>
@@ -323,7 +361,7 @@ static public bool TryGetDirection(this Vector3 vector, out RefinementDirection
323361
/// <returns>
324362
/// The rounded vector.
325363
/// </returns>
326-
public static Vector3 Round(this Vector3 vector, int decimalPlaces = 0)
364+
static public Vector3 Round(this Vector3 vector, int decimalPlaces = 0)
327365
{
328366
float multiplier = 1;
329367
if (decimalPlaces > 0)

0 commit comments

Comments
 (0)