我是WebGL的新手,我正在尝试为网站创建一个演练,我已经在inka3D的帮助下将我的Maya模型带入了WebGL,但是当我应用以下代码时对于运动而言,它并没有像它解释的那样起作用。只有左箭头可以正常工作。
function resize()
{
var width = canvas.offsetWidth;
var height = canvas.offsetHeight;
canvas.width = width;
canvas.height = height;
aspect = width / height;
}
var cameraTargetX = 37.2878151;
var cameraTargetY = 12.846137;
var cameraTargetZ = 7.17901707;
var dx = 5;
var dy = 5;
window.addEventListener('keydown',doKeyDown,true);
function doKeyDown(evt){
switch (evt.keyCode) {
case 38: /* Up arrow was pressed */
if (cameraTargetY - dy > 0){
cameraTargetY -= dy;
}
break;
case 40: /* Down arrow was pressed */
if (cameraTargetY + dy < height){
cameraTargetY += dy;
}
break;
case 37: /* Left arrow was pressed Fine*/
if (cameraTargetX - dx > 0){
cameraTargetX -= dx;
}
break;
case 39: /* Right arrow was pressed */
if (cameraTargetX + dx < width){
cameraTargetX += dx;
}
break;
}
}
};
答案 0 :(得分:0)
如果只有左箭头工作,这意味着(cameraTargetX - dx)&gt;的差异。这就是为什么你可以翻译。原因是cameraTargetX是37 diff的5使其成为32并且按下按键你可以在5X7(循环)中看到它。按键7次,直到值小于零 但是当var cameraTargetY = 12.846137时;和dy是5它只需要5x2(循环)只是一个分数,并且值变得小于零,你可以看到差异。
解决方案如所述dx和dy是delta值意味着这应该是非常小的可变对流所以尝试 var dx = 0.05; var dy = 0.05; 你会得到答案。如果有任何疑问,请随时提出