修复缩放面板时三视图拉伸bug。

This commit is contained in:
tengge1 2019-08-18 09:53:52 +08:00
parent ac42829678
commit a2da365155
3 changed files with 41 additions and 16 deletions

View File

@ -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;

View File

@ -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);
};

View File

@ -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);