From 123a9be8292cb4bfccb1a3199f388267fd9fd1e7 Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Fri, 26 Jan 2018 14:38:57 -0800 Subject: [PATCH 1/2] Adding two-axis pivots, fixing free, and adding other missing axes to Billboard Fixes #1672, fixes #383, fixes #208. --- .../Utilities/Scripts/Billboard.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/Assets/HoloToolkit/Utilities/Scripts/Billboard.cs b/Assets/HoloToolkit/Utilities/Scripts/Billboard.cs index be11b1bee9d..ad12a75ad7b 100644 --- a/Assets/HoloToolkit/Utilities/Scripts/Billboard.cs +++ b/Assets/HoloToolkit/Utilities/Scripts/Billboard.cs @@ -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 } /// @@ -22,7 +29,7 @@ public class Billboard : MonoBehaviour /// The axis about which the object will rotate. /// [Tooltip("Specifies the axis about which the object will rotate.")] - public PivotAxis PivotAxis = PivotAxis.Free; + public PivotAxis PivotAxis = PivotAxis.XY; [Tooltip("Specifies the target we will orient to. If no Target is specified the main camera will be used.")] public Transform TargetTransform; @@ -49,11 +56,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; @@ -70,7 +101,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); } } } From 8667c29bb7c11ae5079c315e1c4bd18a4514a63f Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Wed, 21 Mar 2018 16:23:23 -0700 Subject: [PATCH 2/2] Updating to match new coding guidelines. --- .../Utilities/Scripts/Billboard.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Assets/HoloToolkit/Utilities/Scripts/Billboard.cs b/Assets/HoloToolkit/Utilities/Scripts/Billboard.cs index ad12a75ad7b..a5f78454711 100644 --- a/Assets/HoloToolkit/Utilities/Scripts/Billboard.cs +++ b/Assets/HoloToolkit/Utilities/Scripts/Billboard.cs @@ -29,10 +29,23 @@ public class Billboard : MonoBehaviour /// The axis about which the object will rotate. /// [Tooltip("Specifies the axis about which the object will rotate.")] - public PivotAxis PivotAxis = PivotAxis.XY; + 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; + /// + /// The target we will orient to. If no target is specified, the main camera will be used. + /// + [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() {