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

HARP-13852 Increase precision, otherwise tilt is too inaccurate #2062

Merged
merged 1 commit into from
Jan 20, 2021
Merged
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: 9 additions & 2 deletions @here/harp-map-controls/lib/MapControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,22 @@ export class MapControls extends EventDispatcher {
this.m_tiltRequested = undefined;
}

// Whether the tilt animation has reached full duration & a final frame is rendered. We need
// this to know when to stop the tilt (and hence deregister the methon )
let tiltAnimationFinished = false;
if (this.inertiaEnabled) {
if (!this.m_tiltIsAnimated) {
this.m_tiltIsAnimated = true;
this.mapView.addEventListener(MapViewEventNames.AfterRender, this.tilt);
}
const currentTime = performance.now();
this.m_tiltAnimationTime = (currentTime - this.m_tiltAnimationStartTime) / 1000;
const tiltFinished = this.m_tiltAnimationTime > this.tiltToggleDuration;
const tiltFinished = this.m_tiltAnimationTime >= this.tiltToggleDuration;
if (tiltFinished) {
if (this.m_needsRenderLastFrame) {
this.m_needsRenderLastFrame = false;
this.m_tiltAnimationTime = this.tiltToggleDuration;
this.stopTilt();
tiltAnimationFinished = true;
}
} else {
this.m_needsRenderLastFrame = true;
Expand All @@ -650,6 +653,10 @@ export class MapControls extends EventDispatcher {

MapViewUtils.orbitAroundScreenPoint(this.mapView, 0, 0, 0, deltaAngle, this.m_maxTiltAngle);
this.updateMapView();

if (tiltAnimationFinished) {
this.stopTilt();
}
}

private 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