Skip to content

Allow specifying duration of movement time #320

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

Merged
merged 2 commits into from
Apr 10, 2025
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
9 changes: 7 additions & 2 deletions engine-helpers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export interface GotoTargetOptions {
/** If true, the camera will continue tracking the view target as it moves
* with the progression of the WWT internal clock. */
trackObject: boolean;

/** Optional: The desired duration of the movement */
duration?: number;
}


Expand Down Expand Up @@ -503,15 +506,17 @@ export class WWTInstance {
* @param zoomDeg The zoom setting, in *degrees*
* @param instant Whether to snap the camera instantly, or pan it
* @param rollRad If specified, the roll of the target camera position, in radians
* @param duration If specified, the duration of the motion (in seconds)
* @returns A void promise that resolves when the camera arrives at the target position.
*/
async gotoRADecZoom(raRad: number, decRad: number, zoomDeg: number, instant: boolean, rollRad?: number): Promise<void> {
async gotoRADecZoom(raRad: number, decRad: number, zoomDeg: number, instant: boolean, rollRad?: number, duration?: number): Promise<void> {
this.ctl.gotoRADecZoom(
raRad * R2H,
decRad * R2D,
zoomDeg,
instant,
rollRad
rollRad,
duration,
);
return this.makeArrivePromise(instant);
}
Expand Down
7 changes: 5 additions & 2 deletions engine-pinia/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ export interface GotoRADecZoomParams {

/** Optional: The target roll of the camera, in radians. */
rollRad?: number;

/** Optional: The desired duration of the movement */
duration?: number;
}

/** The parameters for the {{@link engineStore.loadTour} action. */
Expand Down Expand Up @@ -1485,11 +1488,11 @@ export const engineStore = defineStore('wwt-engine', {
* TODO: document semantics when not in 2D sky mode!
*/
async gotoRADecZoom(
{ raRad, decRad, zoomDeg, instant, rollRad }: GotoRADecZoomParams
{ raRad, decRad, zoomDeg, instant, rollRad, duration }: GotoRADecZoomParams
): Promise<void> {
if (this.$wwt.inst === null)
throw new Error('cannot gotoRADecZoom without linking to WWTInstance');
return this.$wwt.inst.gotoRADecZoom(raRad, decRad, zoomDeg, instant, rollRad);
return this.$wwt.inst.gotoRADecZoom(raRad, decRad, zoomDeg, instant, rollRad, duration);
},

/** Returns the time it would take, in seconds, to navigate to the given target. */
Expand Down
4 changes: 2 additions & 2 deletions engine/esm/script_interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ var ScriptInterface$ = {
}
},

gotoRaDecZoom: function (ra, dec, zoom, instant, roll) {
gotoRaDecZoom: function (ra, dec, zoom, instant, roll, duration) {
if (globalWWTControl != null) {
globalWWTControl.gotoRADecZoom(ra / 15, dec, zoom * 6, instant, roll);
globalWWTControl.gotoRADecZoom(ra / 15, dec, zoom * 6, instant, roll, duration);
}
},

Expand Down
10 changes: 9 additions & 1 deletion engine/esm/view_mover.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,17 @@ export function ViewMoverSlew() {
this._complete = false;
}

ViewMoverSlew.create = function (from, to) {
ViewMoverSlew.create = function (from, to, duration) {
var temp = new ViewMoverSlew();
temp.init(from, to);
if (duration) {
const originalTargetTime = temp._toTargetTime;
const upFraction = temp._upTargetTime / originalTargetTime;
const downFraction = temp._downTargetTime / originalTargetTime;
temp._upTargetTime = duration * upFraction;
temp._downTargetTime = duration * downFraction;
temp._toTargetTime = duration;
}
return temp;
};

Expand Down
23 changes: 12 additions & 11 deletions engine/esm/wwt_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -1610,15 +1610,16 @@ var WWTControl$ = {
globalScriptInterface._fireReady();
},

gotoRADecZoom: function (ra, dec, zoom, instant, roll) {
gotoRADecZoom: function (ra, dec, zoom, instant, roll, duration) {
this._tracking = false;
this._trackingObject = null;
this.gotoTargetFull(
false, // noZoom
instant,
this._cameraParametersFromRADecZoom(ra, dec, zoom, roll),
globalRenderContext.get_foregroundImageset(),
globalRenderContext.get_backgroundImageset()
globalRenderContext.get_backgroundImageset(),
duration,
);
},

Expand Down Expand Up @@ -1648,7 +1649,7 @@ var WWTControl$ = {
return this.renderContext.get_backgroundImageset().get_dataSetType() == ImageSetType.solarSystem;
},

gotoTarget: function (place, noZoom, instant, trackObject) {
gotoTarget: function (place, noZoom, instant, trackObject, duration) {
if (place == null) {
return;
}
Expand All @@ -1673,7 +1674,7 @@ var WWTControl$ = {
if (target !== 65536) {
this._trackingObject = place;
if (target === this._solarSystemTrack && !(place.get_classification() === 1 || place.get_classification() === 1048576)) {
this.gotoTarget3(place.get_camParams(), noZoom, instant);
this.gotoTarget3(place.get_camParams(), noZoom, instant, duration);
return;
}
var jumpTime = 4;
Expand Down Expand Up @@ -1789,7 +1790,7 @@ var WWTControl$ = {
// replace with planet surface
camTo.viewTarget = Planets.getPlanetTargetPoint(target, camTo.lat, camTo.lng, SpaceTimeController.getJNowForFutureTime(jumpTime));
}
var solarMover = new ViewMoverKenBurnsStyle(fromParams, camTo, jumpTime, SpaceTimeController.get_now(), SpaceTimeController.getTimeForFutureTime(jumpTime), 3);
var solarMover = new ViewMoverKenBurnsStyle(fromParams, camTo, duration ?? jumpTime, SpaceTimeController.get_now(), SpaceTimeController.getTimeForFutureTime(jumpTime), 3);
solarMover.fastDirectionMove = true;
this.set__mover(solarMover);
return;
Expand All @@ -1812,28 +1813,28 @@ var WWTControl$ = {
}
if (place.get_classification() === 128) {
camParams.zoom = this.get_zoomMax();
this.gotoTargetFull(false, instant, camParams, null, null);
this.gotoTargetFull(false, instant, camParams, null, null, duration);
} else {
this._solarSystemTrack = place.get_target();
this.gotoTargetFull(noZoom, instant, camParams, place.get_studyImageset(), place.get_backgroundImageset());
this.gotoTargetFull(noZoom, instant, camParams, place.get_studyImageset(), place.get_backgroundImageset(), duration);
if (trackObject) {
this._tracking = true;
this._trackingObject = place;
}
}
},

gotoTarget3: function (camParams, noZoom, instant) {
gotoTarget3: function (camParams, noZoom, instant, duration) {
this._tracking = false;
this._trackingObject = null;
this.gotoTargetFull(noZoom, instant, camParams, this.renderContext.get_foregroundImageset(), this.renderContext.get_backgroundImageset());
this.gotoTargetFull(noZoom, instant, camParams, this.renderContext.get_foregroundImageset(), this.renderContext.get_backgroundImageset(), duration);
},

_tooCloseForSlewMove: function (cameraParams) {
return Math.abs(this.renderContext.viewCamera.lat - cameraParams.lat) < 1E-12 && Math.abs(this.renderContext.viewCamera.lng - cameraParams.lng) < 1E-12 && Math.abs(this.renderContext.viewCamera.zoom - cameraParams.zoom) < 1E-12 && Math.abs(this.renderContext.viewCamera.rotation - cameraParams.rotation) < 1E-12;
},

gotoTargetFull: function (noZoom, instant, cameraParams, studyImageSet, backgroundImageSet) {
gotoTargetFull: function (noZoom, instant, cameraParams, studyImageSet, backgroundImageSet, duration) {
this._tracking = false;
this._trackingObject = null;
this._targetStudyImageset = studyImageSet;
Expand Down Expand Up @@ -1868,7 +1869,7 @@ var WWTControl$ = {
}
this._mover_Midpoint();
} else {
this.set__mover(ViewMoverSlew.create(this.renderContext.viewCamera, cameraParams));
this.set__mover(ViewMoverSlew.create(this.renderContext.viewCamera, cameraParams, duration));
this.get__mover().set_midpoint(ss.bind('_mover_Midpoint', this));
}
},
Expand Down
9 changes: 6 additions & 3 deletions engine/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2549,16 +2549,18 @@ export class WWTControl {
* @param zoom The target zoom level (see below)
* @param instant Whether to snap the view instantly or move gradually.
* @param roll_deg Optional, The roll of the camera, in degrees.
* @param duration Optional, The duration of the motion, in seconds.
*
* If `instant` is true or the commanded camera position is extremely close to the
* current camera position, the view will update instantly. Otherwise it will
* scroll there smoothly, taking an unpredictable amount of time to arrive.
* scroll there smoothly. If no duration is specified, it will take an unpredictable
* amount of time to arrive.
*
* The zoom level is the height of the viewport in degrees, times six.
*
* Navigating the view in this way ends any "tracking" status of the current view.
*/
gotoRADecZoom(ra_hours: number, dec_deg: number, zoom: number, instant: boolean, roll_deg?: number): void;
gotoRADecZoom(ra_hours: number, dec_deg: number, zoom: number, instant: boolean, roll_deg?: number, duration?: number): void;

/** Returns how long moving to the given position will take, in seconds.
*
Expand All @@ -2579,10 +2581,11 @@ export class WWTControl {
* @param instant If true, the view camera will immediately snap to the
* destination position. Otherwise, it will gradually move.
* @param trackObject If true, the camera will continue tracking the view
* @param duration If specified, the duration of the motion (in seconds)
* target as it moves with the progression of the WWT internal clock.
*
*/
gotoTarget(place: Place, noZoom: boolean, instant: boolean, trackObject: boolean): void;
gotoTarget(place: Place, noZoom: boolean, instant: boolean, trackObject: boolean, duration?: number): void;

/** Change the zoom of the current view. The change is not necessarily
* instantaneous, depending on whether the "smooth pan" setting is activated.
Expand Down