2015-06-20 87 views
0

我需要旋轉和平移對象。我可以做到這一點,但是在旋轉方向失去後,物體會按照它們所面對的方向移動。旋轉和平移對象

 if(keyboard.pressed("up")) 
      objects[movementControls.translate].translateX(1); 
     if(keyboard.pressed("down")) 
      objects[movementControls.translate].translateX(-1); 
     if(keyboard.pressed("left")) 
      objects[movementControls.translate].translateZ(-1); 
     if(keyboard.pressed("right")) 
      objects[movementControls.translate].translateZ(1); 
     if(keyboard.pressed("x")) 
      objects[movementControls.rotate].rotation.x+=0.1; 
     if(keyboard.pressed("y")) 
      objects[movementControls.rotate].rotation.y+=0.1; 
     if(keyboard.pressed("z")) 
      objects[movementControls.rotate].rotation.z+=0.1; 

有沒有辦法只旋轉物體而不是軸?

+0

所有旋轉和平移操作都圍繞原點(0,0,0)應用。如果要在旋轉時保留翻譯,則需要保存當前對象位置,先將對象翻譯爲(0,0,0),然後旋轉,然後再翻譯回去。可能需要查看[場景圖](https://en.wikipedia.org/?title=Scene_graph)來管理複雜的對象和場景 - WebGL的一個是[SceneJS](http://scenejs.org/ )。 –

回答

0

parent.add(yourobject);將您的對象添加到另一個父對象中。然後移動父母,旋轉孩子。