diff --git a/ShadowEditor.Web/src/controls/OrthographicCameraControls.js b/ShadowEditor.Web/src/controls/OrthographicCameraControls.js index 048b2d5e..cfb92c98 100644 --- a/ShadowEditor.Web/src/controls/OrthographicCameraControls.js +++ b/ShadowEditor.Web/src/controls/OrthographicCameraControls.js @@ -78,22 +78,22 @@ OrthographicCameraControls.prototype.onMouseUp = function (event) { }; OrthographicCameraControls.prototype.onMouseWheel = function (event) { - const delta = event.wheelDelta / 1000; + const delta = -event.wheelDelta / 1000; let camera = this.camera; let width = this.domElement.clientWidth; let height = this.domElement.clientHeight; - let pointerX = this.camera.left + (this.camera.right - this.camera.left) * event.offsetX / width; - let pointerY = this.camera.top - (this.camera.top - this.camera.bottom) * event.offsetY / height; + let pointerX = camera.left + (camera.right - camera.left) * event.offsetX / width; + let pointerY = camera.top - (camera.top - camera.bottom) * event.offsetY / height; - this.camera.left = this.camera.left - Math.abs(pointerX - this.camera.left) * delta; - this.camera.right = this.camera.right + Math.abs(this.camera.right - pointerX) * delta; - this.camera.top = this.camera.top + Math.abs(this.camera.top - pointerY) * delta; - this.camera.bottom = this.camera.bottom - Math.abs(pointerY - this.camera.bottom) * delta; + camera.left = camera.left - Math.abs(pointerX - camera.left) * delta; + camera.right = camera.right + Math.abs(camera.right - pointerX) * delta; + camera.top = camera.top + Math.abs(camera.top - pointerY) * delta; + camera.bottom = camera.bottom - Math.abs(pointerY - camera.bottom) * delta; - this.camera.updateProjectionMatrix(); + camera.updateProjectionMatrix(); }; export default OrthographicCameraControls; \ No newline at end of file diff --git a/ShadowEditor.Web/src/event/ResizeEvent.js b/ShadowEditor.Web/src/event/ResizeEvent.js index 5c6dc192..10136b3f 100644 --- a/ShadowEditor.Web/src/event/ResizeEvent.js +++ b/ShadowEditor.Web/src/event/ResizeEvent.js @@ -21,20 +21,43 @@ ResizeEvent.prototype.stop = function () { }; ResizeEvent.prototype.onResize = function () { - var editor = app.editor; - var viewport = app.viewport; - var camera = editor.camera; - var renderer = editor.renderer; + let { editor, viewport } = app; + let { DEFAULT_CAMERA, camera, orthCamera, renderer } = editor; - var width = viewport.clientWidth; - var height = viewport.clientHeight; + const width = viewport.clientWidth; + const height = viewport.clientHeight; - editor.DEFAULT_CAMERA.aspect = width / height; - editor.DEFAULT_CAMERA.updateProjectionMatrix(); + if (this.width === undefined || this.height === undefined) { + this.width = width; + this.height = height; + } + + DEFAULT_CAMERA.aspect = width / height; + DEFAULT_CAMERA.updateProjectionMatrix(); camera.aspect = width / height; camera.updateProjectionMatrix(); + if (width !== this.width) { + let dwidth = (orthCamera.right - orthCamera.left) * (width / this.width - 1); + + orthCamera.left -= dwidth / 2; + orthCamera.right += dwidth / 2; + + this.width = width; + } + + if (height !== this.height) { + let dheight = (orthCamera.top - orthCamera.bottom) * (height / this.height - 1); + + orthCamera.top += dheight / 2; + orthCamera.bottom -= dheight / 2; + + this.height = height; + } + + orthCamera.updateProjectionMatrix(); + renderer.setSize(width, height); }; diff --git a/ShadowEditor.Web/src/event/ViewEvent.js b/ShadowEditor.Web/src/event/ViewEvent.js index 7f044703..0ba8d71a 100644 --- a/ShadowEditor.Web/src/event/ViewEvent.js +++ b/ShadowEditor.Web/src/event/ViewEvent.js @@ -43,6 +43,8 @@ ViewEvent.prototype.changeView = function (view) { let camera = app.editor.orthCamera; + // TODO: 根据场景大小确定初始位置 + switch (view) { case 'front': camera.position.set(100, 0, 0);