From decd1d262e243396f20fa8cd0cb48048e962e7b6 Mon Sep 17 00:00:00 2001 From: liteng <930372551@qq.com> Date: Fri, 17 Aug 2018 12:07:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=94=E5=B0=8F=E7=90=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShadowEditor.Web/src/editor/Physics.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ShadowEditor.Web/src/editor/Physics.js b/ShadowEditor.Web/src/editor/Physics.js index 5d56d545..7b936214 100644 --- a/ShadowEditor.Web/src/editor/Physics.js +++ b/ShadowEditor.Web/src/editor/Physics.js @@ -1,3 +1,7 @@ +/** + * 物理 + * @param {*} options + */ function Physics(options) { this.app = options.app; this.app.physics = this; @@ -95,7 +99,10 @@ Physics.prototype.onThrowBall = function (event) { var raycaster = new THREE.Raycaster(); var camera = this.app.editor.camera; - mouse.set((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window.innerHeight) * 2 + 1); + var width = UI.get('viewport').dom.clientWidth; + var height = UI.get('viewport').dom.clientHeight; + + mouse.set((event.offsetX / width) * 2 - 1, -(event.offsetY / height) * 2 + 1); raycaster.setFromCamera(mouse, camera); // Creates a ball and throws it @@ -106,6 +113,7 @@ Physics.prototype.onThrowBall = function (event) { var ball = new THREE.Mesh(new THREE.SphereBufferGeometry(ballRadius, 14, 10), ballMaterial); ball.castShadow = true; ball.receiveShadow = true; + this.app.editor.scene.add(ball); var ballShape = new Ammo.btSphereShape(ballRadius); ballShape.setMargin(this.margin);