Three .js object rotation on keypress

烈酒焚心 提交于 2019-12-25 03:40:34

问题


I'm desperate. been trying for so long to simply rotate an object on key press event. I can't just figure it, can anyone please show how to do it?

this is my model https://www.dropbox.com/s/8yefhx3yc11zbik/b.obj?dl=0

i need to keep rotating it on x axis, as long as keyboard button "B" is pressed down, so that that the shadow from the spotlight or direct light would be changing. anyone?

i need to do that with the whole alphabet (i've got all the models) what's the best way to do it?


回答1:


You have different problems in your code.

1) You use the variable "letter" to rotate the object. This variable is only defined in the function onLoad. So you need to get a gloabal variable and asign the letter to it.

2) Try to rotate the hole scene first. "lesson6.scene.rotation.y += 1;" With that you could test how to use the button controls. In your code it will rotate only once per click. I think you need to use "setInterval" and "window.clearInterval" http://www.w3schools.com/js/js_timing.asp



来源:https://stackoverflow.com/questions/29189857/three-js-object-rotation-on-keypress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!