2

i am making a very basic application in ThreeJs, i have an object in the center and 2 sliders (horizontal rotation and vertical rotation). Both sliders output an integer between 0 and 360. So far i managed to move my camera around the object horizontally with the first slider. But i want to be able to move the camera up and down around the object with the second slider, and i cannot figure out the correct math.

Here is what my equations look like at the moment:

camera.position.x =  originX + radius * Math.cos(horizontal_degrees*(Math.PI/180));
camera.position.z =  originY + radius *Math.sin(controls.horizontal_rotation(Math.PI/180));
camera.position.y=  //??? i can't figure this out.
camera.lookAt(scene.position);

1 Answer 1

2

You can use the code of this example as base:

var horizontal_degrees = 0;
var vertical_degrees = 0;

var theta = horizontal_degrees * Math.PI / 180;
var phi = vertical_degrees * Math.PI / 180;

camera.position.x = originX + radius * Math.sin( phi ) * Math.cos( theta );
camera.position.y = originY + radius * Math.cos( phi );
camera.position.z = originZ + radius * Math.sin( phi ) * Math.sin( theta );
Sign up to request clarification or add additional context in comments.

1 Comment

I'm sorry, but what does the "lat" variable refer to? the Latitude? Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.