【发布时间】:2013-05-25 02:58:12
【问题描述】:
目前我正在使用鼠标位置和 (0, 1) 的点积来生成弧度来旋转对象,在三个.js 中
下面的代码,工作正常,但对象“跳跃”,因为当clientX 值介于window.innerWidth / 2 之间时,弧度角从正跳到负
onDocumentMouseMove : function(event) {
// rotate circle relative to current mouse pos
var oldPos = new THREE.Vector2(0, 1);
Template.Main.mouseCurrPos = new THREE.Vector2((event.clientX / window.innerWidth ) * 2 - 1, - (event.clientY / window.innerHeight) * 2 + 1);
Template.Main.mouseCurrPos.normalize();
//Template.Main.projector.unprojectVector(Template.Main.mouseCurrPos, Template.Main.scene);
var angle = oldPos.dot(Template.Main.mouseCurrPos);
Template.Main.mousePrevPos.x = event.clientX;
Template.Main.mousePrevPos.y = event.clientY;
if (event.clientX < window.innerWidth / 2) {
Template.Main.circle.rotation.z = -angle;
}
else {
Template.Main.circle.rotation.z = angle;
}
console.log(Template.Main.circle.rotation.z);
}
但是,如果我添加它以将值分配给 oldPos:
if (event.clientX < window.innerWidth / 2) {
oldPos = new THREE.Vector2(0, -1);
}
else {
oldPos = new THREE.Vector2(0, 1);
}
然后“跳跃”消失,但当鼠标在窗口左侧时,旋转效果反转。
即鼠标上移会逆时针旋转,反之亦然,这是不希望的。
这令人沮丧。
另外,如果我保留 oldPos 条件赋值并省略角度的条件否定,跳跃就会回来。
您可以在此处查看演示:http://theworldmoves.me/rotation-demo/
非常感谢任何提示。
【问题讨论】:
-
你希望鼠标如何影响旋转?
标签: graphics geometry three.js dot-product