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

Updated ConstantViewSize solver to retain the initial scale and aspect ratio (Fixes #306) #719

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions org.mixedrealitytoolkit.spatialmanipulation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [3.3.0-development] - 2024-04-5
## [3.3.0-development] - 2024-04-07

### Added

* Made bounds control overridable for custom translation, scaling and rotation logic. PR #715
* Made bounds control overridable for custom translation, scaling and rotation logic. [PR #715](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/715)

## [3.2.0-development] - 2024-03-20
### Fixed

* ConstantViewSize solver now retains the initial scale and aspect ratio [PR #719](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/719)

## [3.2.0] - 2024-03-20

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public float ManualObjectSize
/// Get the current scale progress on this <see cref="ConstantViewSize"/> object.
/// </summary>
/// <remarks>
/// This is a value between zero and one, representing progress between
/// This is a value between zero and one, representing progress between
/// <see cref="MinScale"/> and <see cref="MaxScale"/>. If current scale is less
/// than max, then scaling is being applied. This value is subject to inaccuracies
/// than max, then scaling is being applied. This value is subject to inaccuracies
/// due to smoothing, interpolation, and momentum.
/// </remarks>
public float CurrentScalePercent { get; private set; } = 1f;
Expand All @@ -130,9 +130,9 @@ public float ManualObjectSize
/// Get the current distance progress on this <see cref="ConstantViewSize"/> object.
/// </summary>
/// <remarks>
/// This is a value between zero and one, representing progress between
/// This is a value between zero and one, representing progress between
/// <see cref="MinDistance"/> and <see cref="MaxDistance"/>. If current is less than
/// max, object is potentially on a surface. This value is subject to inaccuracies due
/// max, object is potentially on a surface. This value is subject to inaccuracies due
/// to smoothing, interpolation, and momentum.
/// </remarks>
public float CurrentDistancePercent { get; private set; } = 1f;
Expand All @@ -153,9 +153,17 @@ public float FovScale

#endregion

private Vector3 originalScale;
private float fovScalar = 1f;
private float objectSize = 1f;

/// <inheritdoc/>
protected override void Awake()
{
base.Awake();
originalScale = GoalScale;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have enough context on the original intent here.

@keveleigh or @david-c-kline , how do you feel about this change?

}

/// <inheritdoc/>
protected override void Start()
{
Expand All @@ -175,17 +183,17 @@ public override void SolverUpdate()

if (SolverHandler.TransformTarget != null)
{
// Get current fov each time instead of trying to cache it. Can never count on init order these days
// Get current fov each time instead of trying to cache it. Can never count on init order these days
fovScalar = FovScale;

// Set the linked alt scale ahead of our work. This is an attempt to minimize jittering by having solvers work with an interpolated scale.
SolverHandler.AltScale.SetGoal(transform.localScale);

// Calculate scale based on distance from view. Do not interpolate so we can appear at a constant size if possible. Borrowed from greybox.
// Calculate scale based on distance from view. Do not interpolate so we can appear at a constant size if possible. Borrowed from greybox.
Vector3 targetPosition = SolverHandler.TransformTarget.position;
float distance = Mathf.Clamp(Vector3.Distance(transform.position, targetPosition), minDistance, maxDistance);
float scale = Mathf.Clamp(fovScalar * distance, minScale, maxScale);
GoalScale = Vector3.one * scale;
GoalScale = originalScale * scale;

// Save some state information for external use
CurrentDistancePercent = Mathf.InverseLerp(minDistance, maxDistance, distance);
Expand Down