AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SolverBodyLock.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity
8 {
13  [Obsolete("Body Locked Solvers are replaced by Orbital Solvers. Use the YawOnly/CameraAligned orientations and a World Offset to exactly replace SolverBodyLocked.", false)]
14  public class SolverBodyLock : Solver
15  {
16  #region public enums
18  {
22  Default,
26  CameraFacing,
27  }
28  #endregion
29 
30  #region public members
31  [Tooltip("The desired orientation of this object. Default sets the object to face the TrackedObject/TargetTransform. CameraFacing sets the object to always face the user.")]
32  public OrientationReference Orientation = OrientationReference.Default;
33  [Tooltip("XYZ offset for this object in relation to the TrackedObject/TargetTransform")]
34  public Vector3 offset;
35  [Tooltip("RotationTether snaps the object to be in front of TrackedObject regardless of the object's local rotation.")]
36  public bool RotationTether = false;
37  [Tooltip("TetherAngleSteps is the division of steps this object can tether to. Higher the number, the more snapple steps.")]
38  [Range(4, 12)]
39  public int TetherAngleSteps = 6;
40  #endregion
41 
42  private Quaternion desiredRot = Quaternion.identity;
43 
44  public override void SolverUpdate()
45  {
46 
47  if (RotationTether)
48  {
49  float targetYRotation = GetOrientationRef().eulerAngles.y;
50  float tetherYRotation = desiredRot.eulerAngles.y;
51  float angleDiff = Mathf.DeltaAngle(targetYRotation, tetherYRotation);
52  float tetherAngleLimit = 360f / TetherAngleSteps;
53 
54  if (Mathf.Abs(angleDiff) > tetherAngleLimit)
55  {
56  int numSteps = Mathf.RoundToInt(targetYRotation / tetherAngleLimit);
57  tetherYRotation = numSteps * tetherAngleLimit;
58  desiredRot = Quaternion.Euler(0f, tetherYRotation, 0f);
59  }
60 
61  }
62 
63  Vector3 desiredPos = solverHandler.TransformTarget != null ? solverHandler.TransformTarget.position + (desiredRot * offset) : Vector3.zero;
64 
65  GoalPosition = desiredPos;
66  GoalRotation = desiredRot;
67 
68  UpdateWorkingPosToGoal();
69  UpdateWorkingRotToGoal();
70  }
71 
72  private Transform GetOrientationRef()
73  {
74  if (Orientation == OrientationReference.CameraFacing)
75  {
76  return CameraCache.Main.transform;
77  }
78  return solverHandler.TransformTarget;
79  }
80  }
81 }
SolverBase is the base abstract class for all Solvers to derive from. It provides state tracking...
Definition: Solver.cs:15
The purpose of this class is to provide a cached reference to the main camera. Calling Camera...
Definition: CameraCache.cs:12
static Camera Main
Returns a cached reference to the main camera and uses Camera.main if it hasn't been cached yet...
Definition: CameraCache.cs:20
SolverBodyLock provides a solver that follows the TrackedObject/TargetTransform. Adjusting "LerpTime"...