Skip to content

Commit

Permalink
Merge branch 'dev-unstable' of https://github.com/VCityTeam/UD-Viz in…
Browse files Browse the repository at this point in the history
…to dev-unstable
  • Loading branch information
Livebardon committed Sep 20, 2021
2 parents 8e777e7 + 7e7a823 commit 43a3203
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Views/View3D/View3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,30 @@ export class View3D {

//start
this.inputManager.startListening(this.itownsView.domElement);

//dynamic near far computation
this.itownsView.addFrameRequester(
itowns.MAIN_LOOP_EVENTS.AFTER_CAMERA_UPDATE,
this.computeNearFarCamera.bind(this)
);
}

/**
* dynamic computation of the near and far of the camera to fit the extent
*/
computeNearFarCamera() {
const camera = this.itownsView.camera.camera3D;
const radius = Math.sqrt(
Math.pow(0.5 * (this.extent.north - this.extent.south), 2) +
Math.pow(0.5 * (this.extent.east - this.extent.west), 2)
);

const distToCenter = camera.position.distanceTo(this.extent.center());

camera.near = Math.max(distToCenter - radius, 0.001);
camera.far = distToCenter + radius;

camera.updateProjectionMatrix();
}

/**
Expand Down

0 comments on commit 43a3203

Please sign in to comment.