3

I am using this function and it is not working properly. Coding is using three.js

function rotate(){
    camera.rotation.x+=0.1;
}

. If I add this at the render function it works just once and not correct meaning that the rotate function event on mouse movement I have, rotates wrong or maybe at an other centre. What I need is to rotate the camera on the x,y,z axes when the button is clicked. Any ideas?

2
  • from what i gather there could be a problem in the render function, could you post it? Commented Jan 7, 2015 at 13:56
  • function render() { controls.update(); requestAnimationFrame(render); //camera.rotation.x+=10; renderer.render(scene, camera); updateLabels(); } This is the render function.I need the camera.rotation.x+=10; to be inside a function and executed whenever a button is clicked. thx:) Commented Jan 8, 2015 at 1:54

3 Answers 3

4

You defined controls. They decide the camera rotation instead of the line you added. You have to set controls.enabled=false when you want the camera to rotate.

Sign up to request clarification or add additional context in comments.

Comments

1

Yo can’t rotate the camera if you later call controls.update(), OrbitControls will overwrite anything what you have applied. So one simple solution is to not update the controls if you are transforming the camera by yourself.

Comments

1

As the previous answers said the OrbitControls overwrite anything But it looks like three.js now doesn't need to call controls.update() as long as you instantiated it const controls = new OrbitControls(camera, renderer.domElement); it will work fine and won't interfere with the camera.

source

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.