我正在尝试旋转矩形以始终指向鼠标位置。
我试过这个:
document.getElementById('viewport').onmousemove = function(e){
var scratch = Physics.scratchpad();
mousePos = scratch.vector().set(e.x, e.y);
var newAngle = box.state.pos.angle(mousePos);
box.state.angular.pos = newAngle;
scratch.done();
};
感谢。
答案 0 :(得分:1)
也许尝试这样的事情:
document.getElementById('viewport').onmousemove = function(e){
var scratch = Physics.scratchpad();
// assuming your viewport is the whole screen
mousePos = scratch.vector().set(e.pageX, e.pageY);
mousePos.vsub( box.state.pos ); // get vector pointing towards mouse pos
var newAngle = mousePos.angle(); // get angle with respect to x axis
box.state.angular.pos = newAngle;
scratch.done();
};