Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-13852 Increase precision, otherwise tilt is too inaccurate
Browse files Browse the repository at this point in the history
- Improve the epsilon used when comparing the dot product.
- When the tilt animation has finished, a final check is done to see if the targeted
tilt is reached, and if not, we apply the delta needed to reach the desired tilt.

Signed-off-by: Jonathan Stichbury <[email protected]>
  • Loading branch information
nzjony committed Jan 19, 2021
1 parent acb2690 commit dcf7298
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions @here/harp-map-controls/lib/MapControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,22 @@ export class MapControls extends EventDispatcher {
const tiltFinished = this.m_tiltAnimationTime > this.tiltToggleDuration;
if (tiltFinished) {
if (this.m_needsRenderLastFrame) {
// There may be some numerical inaccuracies in the application of the
// `deltaAngle` during the animation, hence we check one last time to see if we
// need to fix the tilt
const mapViewTiltRad = THREE.MathUtils.degToRad(this.mapView.tilt);
const deltaAngle = (this.m_targetedTilt ?? mapViewTiltRad) - mapViewTiltRad;
if (deltaAngle !== 0) {
MapViewUtils.orbitAroundScreenPoint(
this.mapView,
0,
0,
0,
deltaAngle,
this.m_maxTiltAngle
);
this.updateMapView();
}
this.m_needsRenderLastFrame = false;
this.m_tiltAnimationTime = this.tiltToggleDuration;
this.stopTilt();
Expand Down
8 changes: 4 additions & 4 deletions @here/harp-mapview/lib/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,8 @@ export namespace MapViewUtils {

// Decompose rotation matrix into Z0 X Z1 Euler angles.
const d = space.z.dot(cache.vector3[1].set(0, 0, 1));
if (d < 1.0 - epsilon) {
if (d > -1.0 + epsilon) {
if (d < 1.0 - Number.EPSILON) {
if (d > -1.0 + Number.EPSILON) {
yaw = Math.atan2(space.z.x, -space.z.y);
pitch = Math.acos(space.z.z);
roll = Math.atan2(space.x.z, space.y.z);
Expand Down Expand Up @@ -1387,7 +1387,7 @@ export namespace MapViewUtils {
// Get point to object vector in `cache.vector3[1]` and deduce `tilt` from the angle with
// tangent Z.
cache.vector3[1].copy(object.position).sub(cache.vector3[0]).normalize();
if (cache.vector3[1].dot(tangentSpace.z) > 1 - epsilon) {
if (cache.vector3[1].dot(tangentSpace.z) > 1 - Number.EPSILON) {
// Top down view: the azimuth of the object would be opposite the yaw, and clockwise.
azimuth = Math.PI - extractAttitude(mapView, object).yaw;
// Wrap between -PI and PI.
Expand Down Expand Up @@ -1450,7 +1450,7 @@ export namespace MapViewUtils {
dirVec.divideScalar(dirLen);

const cosTheta = dirVec.dot(tangentSpace.z);
if (cosTheta > 1 - epsilon) {
if (cosTheta >= 1 - Number.EPSILON) {
// Top down view.
return 0;
}
Expand Down

0 comments on commit dcf7298

Please sign in to comment.