Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/enhancement/free-camera-support'…
Browse files Browse the repository at this point in the history
… into develop
  • Loading branch information
ComBatVision committed Sep 28, 2022
2 parents 3ed8dc2 + 4c56cf3 commit 76638e5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/WorldWindow.js
Expand Up @@ -208,6 +208,8 @@ define([
* @default [Camera]{@link Camera}
*/
this.camera = new Camera();
// Initialize vertical field of view assuming that default angle value is horizontal
this.camera.fieldOfView *= this.viewport.height / this.viewport.width;

/**
* The controller used to manipulate the globe.
Expand Down Expand Up @@ -572,11 +574,17 @@ define([
* @returns {LookAt} A reference to the result parameter.
* @throws {ArgumentError} If the specified result object is null or undefined.
*/
WorldWindow.prototype.cameraAsLookAt = function (result, terrainPosition = this.pick([this.viewport.width / 2, this.viewport.height / 2]).terrainObject().position) {
WorldWindow.prototype.cameraAsLookAt = function (result, terrainPosition) {
if (!result) {
throw new ArgumentError(
Logger.logMessage(Logger.LEVEL_SEVERE, "Camera", "getAsLookAt", "missingResult"));
}
if (!terrainPosition) {
var terrainObject = this.pick([this.viewport.width / 2, this.viewport.height / 2]).terrainObject();
if (terrainObject) {
terrainPosition = terrainObject.position;
}
}

var globe = this.globe,
forwardRay = this.scratchRay,
Expand Down Expand Up @@ -812,6 +820,15 @@ define([
gl.canvas.width = width;
gl.canvas.height = height;

// Keep map scale by adopting field of view on view port resize
if (this.viewport.height !== 0) {
try {
this.camera.fieldOfView *= height / this.viewport.height;
} catch (ignore: IllegalArgumentException) {
// Keep original field of view in case new one does not fit requirements
}
}

// Set the WebGL viewport to match the canvas drawing buffer size.
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
this.viewport = new Rectangle(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
Expand Down

0 comments on commit 76638e5

Please sign in to comment.