Skip to content

Commit

Permalink
Fixed Billboards alignment across all axes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwittner committed Jul 28, 2016
1 parent edbce40 commit 4d8fd92
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Assets/HoloToolkit/Utilities/Scripts/Billboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,32 @@ private void Awake()
private void Update()
{
// Get a Vector that points from the Camera to the target.
Vector3 directionToTarget = Camera.main.transform.position - gameObject.transform.position;

// If we are right next to the camera the rotation is undefined.
if (directionToTarget.sqrMagnitude < Mathf.Epsilon)
{
return;
}
Vector3 forward;
Vector3 up;

// Adjust for the pivot axis.
switch (PivotAxis)
{
case PivotAxis.X:
directionToTarget.x = gameObject.transform.position.x;
forward = Vector3.ProjectOnPlane(Camera.main.transform.forward, Vector3.right).normalized;
up = Vector3.Cross(forward, Vector3.right);
break;

case PivotAxis.Y:
directionToTarget.y = gameObject.transform.position.y;
up = Vector3.up;
forward = Vector3.ProjectOnPlane(Camera.main.transform.forward, up);
break;

case PivotAxis.Free:
default:
// No changes needed.
forward = Camera.main.transform.forward;
up = Camera.main.transform.up;
break;
}

// Calculate and apply the rotation required to reorient the object and apply the default rotation to the result.
gameObject.transform.rotation = Quaternion.LookRotation(-directionToTarget) * DefaultRotation;

// Calculate and apply the rotation required to reorient the object
gameObject.transform.rotation = Quaternion.LookRotation(forward, up);
}
}
}

5 comments on commit 4d8fd92

@markgrossnickle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old way used to only affect the x/y axes. Setting Free meant setting both X and Y. The new code now sets the z as well when you set free.

There should be an option for just X and Y (example: Tag-a-longs).

@jwittner
Copy link
Member Author

@jwittner jwittner commented on 4d8fd92 Sep 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little unclear on what you're trying to achieve, but I think for most Tag-a-long style things this should work. For reference, the new FPS display prefab is an example of a tag along that uses this Billboard class as is and pivots around the Y-axis (Up in Unity).

@pnolen
Copy link

@pnolen pnolen commented on 4d8fd92 Sep 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to clarify: previously the billboard for a tagalong in Free would turn so that it was facing the camera on both orientations. So, if you were looking straight down at it would face the user as it was oriented with the floor, similar to the bloom menu. It still does this but now it also rotates on the Z axis so that it's essentially rotated with the user's head rather than staying in line with the rest of the world. While this can keep the tagalong or whatever in the holographic frame, it's also a little disorienting and doesn't match the way the UI works in the shell. So another option that would allow Free rotation but with a locked Z axis would be desirable (and would match the previous functionality).

@jwittner
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think that makes sense. I'll make an issue!

@jwittner
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#208 for reference, let's move any further conversation there.

Please sign in to comment.