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

Support (vertical) camera target limitation #16125

Open
wants to merge 15 commits into
base: master
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
11 changes: 11 additions & 0 deletions packages/dev/core/src/Cameras/arcRotateCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ export class ArcRotateCamera extends TargetCamera {
@serialize()
public upperRadiusLimit: Nullable<number> = null;

/**
* Minimum allowed vertical target position of the camera.
* Use this setting in combination with `upperRadiusLimit` to set a global limit for the Cameras vertical position.
*/
@serialize()
public lowerTargetYLimit: Nullable<number> = null;

/**
* Defines the current inertia value used during panning of the camera along the X axis.
*/
Expand Down Expand Up @@ -866,6 +873,7 @@ export class ArcRotateCamera extends TargetCamera {
alpha = Clamp(alpha, this.lowerAlphaLimit ?? -Infinity, this.upperAlphaLimit ?? Infinity);
beta = Clamp(beta, this.lowerBetaLimit ?? -Infinity, this.upperBetaLimit ?? Infinity);
radius = Clamp(radius, this.lowerRadiusLimit ?? -Infinity, this.upperRadiusLimit ?? Infinity);
target.y = Clamp(target.y, this.lowerTargetYLimit ?? -Infinity, Infinity);

this._goalAlpha = alpha;
this._goalBeta = beta;
Expand Down Expand Up @@ -1129,6 +1137,9 @@ export class ArcRotateCamera extends TargetCamera {
this.radius = this.upperRadiusLimit;
this.inertialRadiusOffset = 0;
}
if (this.lowerTargetYLimit !== null && this.target.y < this.lowerTargetYLimit) {
this.target.y = this.lowerTargetYLimit;
Copy link
Member

Choose a reason for hiding this comment

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

is it basically not a this.target.y = Math.max(this.target.y, this.lowerTargetYLimit) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was my initial though as well, but the TS compiler blames because null is not a valid input for Math.max.
I guess that's why are lowerAlphaLimit and upperAlphaLimit are solved with this if pattern as well.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should initialize at -infinity so we prevent different objects maps and simplify the code ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me, as it would solve the inspector issue as well.
Should I also change lowerAlphaLimit and upperAlphaLimit to -Infinity / Infinity?

Copy link
Member

Choose a reason for hiding this comment

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

looks like an inmprovment ?

}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ export class ArcRotateCameraPropertyGridComponent extends React.Component<IArcRo
propertyName="upperRadiusLimit"
onPropertyChangedObservable={this.props.onPropertyChangedObservable}
/>
<FloatLineComponent
lockObject={this.props.lockObject}
label="Lower target Y limit"
target={camera}
propertyName="lowerTargetYLimit"
onPropertyChangedObservable={this.props.onPropertyChangedObservable}
/>
</LineContainerComponent>
<LineContainerComponent title="BEHAVIORS" closed={true} selection={this.props.globalState}>
<CheckBoxLineComponent
Expand Down