1
基本上我試圖讓一個3d立方體面對鼠標所在的方向。它幾乎在那裏,但現在它不是渲染立方體,它在我添加之前做得很好驗證碼:three; js:訪問對象出錯
cube.look(xTarget, yTarget);
這是給這個錯誤:
Uncaught TypeError: Cannot read property 'look' of undefined`
它使得cube
對象不可訪問,這是爲什麼? (至少......我認爲這是問題所在)。我在這裏做錯了什麼?
下面是相關的JS:
Cube.prototype.updateBody = function(speed){
this.box.rotation.y += (this.tBoxRotY - this.box.rotation.y)/speed;
this.box.rotation.x += (this.tBoxRotX - this.box.rotation.x)/speed;
this.box.position.x += (this.tBoxPosX-this.box.position.x)/speed;
this.box.position.y += (this.tBoxPosY-this.box.position.y)/speed;
this.box.position.z += (this.tBoxPosZ-this.box.position.z)/speed;
}
Cube.prototype.look = function(xTarget, yTarget){
this.tBoxRotY = rule3(xTarget, -200, 200, -Math.PI/4, Math.PI/4);
this.tBoxRotX = rule3(yTarget, -200,200, -Math.PI/4, Math.PI/4);
this.tBoxPosX = rule3(xTarget, -200, 200, 70,-70);
this.tBoxPosY = rule3(yTarget, -140, 260, 20, 100);
this.tBoxPosZ = 0;
}
function loop() {
render();
var xTarget = (mousePos.x-windowHalfX);
var yTarget= (mousePos.y-windowHalfY);
console.log('Mouse X position: ' + xTarget +', Y Target = '+yTarget);
cube.look(xTarget, yTarget);
requestAnimationFrame(loop);
}
是正確的plunker鏈接?循環函數沒有cube.look。 –
是的,它在第92行:'Cube.prototype.look = function(xTarget,yTarget){....};'等等,循環函數中的行在149行。 –