Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dev→master] Billboard updates #1856

Merged
merged 2 commits into from
Mar 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions Assets/HoloToolkit/Utilities/Scripts/Billboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ namespace HoloToolkit.Unity
{
public enum PivotAxis
{
// Rotate about all axes.
Free,
// Most common options, preserving current functionality with the same enum order.
XY,
Y,
// Rotate about an individual axis.
Y
X,
Z,
// Rotate about a pair of axes.
XZ,
YZ,
// Rotate about all axes.
Free
}

/// <summary>
Expand All @@ -22,10 +29,23 @@ public class Billboard : MonoBehaviour
/// The axis about which the object will rotate.
/// </summary>
[Tooltip("Specifies the axis about which the object will rotate.")]
public PivotAxis PivotAxis = PivotAxis.Free;
private PivotAxis pivotAxis = PivotAxis.XY;
public PivotAxis PivotAxis
{
get { return pivotAxis; }
set { pivotAxis = value; }
}

[Tooltip("Specifies the target we will orient to. If no Target is specified the main camera will be used.")]
public Transform TargetTransform;
/// <summary>
/// The target we will orient to. If no target is specified, the main camera will be used.
/// </summary>
[Tooltip("Specifies the target we will orient to. If no target is specified, the main camera will be used.")]
private Transform targetTransform;
public Transform TargetTransform
{
get { return targetTransform; }
set { targetTransform = value; }
}

private void OnEnable()
{
Expand All @@ -49,11 +69,35 @@ private void Update()

// Get a Vector that points from the target to the main camera.
Vector3 directionToTarget = TargetTransform.position - transform.position;
Vector3 targetUpVector = CameraCache.Main.transform.up;

// Adjust for the pivot axis.
switch (PivotAxis)
{
case PivotAxis.X:
directionToTarget.x = 0.0f;
targetUpVector = Vector3.up;
break;

case PivotAxis.Y:
directionToTarget.y = 0.0f;
targetUpVector = Vector3.up;
break;

case PivotAxis.Z:
directionToTarget.x = 0.0f;
directionToTarget.y = 0.0f;
break;

case PivotAxis.XY:
targetUpVector = Vector3.up;
break;

case PivotAxis.XZ:
directionToTarget.x = 0.0f;
break;

case PivotAxis.YZ:
directionToTarget.y = 0.0f;
break;

Expand All @@ -70,7 +114,7 @@ private void Update()
}

// Calculate and apply the rotation required to reorient the object
transform.rotation = Quaternion.LookRotation(-directionToTarget);
transform.rotation = Quaternion.LookRotation(-directionToTarget, targetUpVector);
}
}
}