0
votes

I have given up trying to orbit a camera around my scene in Three.js and have now decided to revert to doing what I used to do in XNA, just rotate everything except the camera.

The reason I have given up is because I cannot get the camera to orbit properly 360 degrees in all the axis, it starts inverting after going over the top or under the bottom. Using THREE.OrbitControls does not solve this because it merely restricts rotation in the problematic axis instead of fixing the problem.

My problem is now getting this other rotation story working. What I have done is put all objects except the camera in another object "rotSection" and I am now just rotating that object. This is working but rotation is always performed according to the relative (0, 0, 0) position of the rotation object which seems to always stay in the one corner but I would like to rotate around the centre of my world on not around the edge. I have tried to centre the rotSection relative to the scene but it still rotates around its corner and not its centre. Any idea how I can get rotation of an Object3D around a certain point?

1
You probably don't want to be rotating every object in your scene in the way you describe. I have never used Three.js but my guess is that your initial problem was caused by your "look at" direction and "up" direction becoming linearly dependent. This occurs when your "look at" and "up" vectors point in the same or opposite directions.Homar
@Homar what can I do about this?Gerharddc
Really, the library should handle this case for you. You should look at the Three source code to find out. The way I deal with this is that my Quaternion::lookRotation method checks whether the to and from directions are colinear and if so it chooses its axis of rotation appropriately. You can read through my source code for clarification: github.com/kermado/M3D/blob/master/source/M3D/…Homar

1 Answers

0
votes

The engines don’t move the ship at all. The ship stays where it is and the engines move the universe around it.

Futurama

The camera in 3d technically never rotates, everything else is rotated and move in order to bring it to camera's local space. You don't have to do any tricks in order to do this, this should be the core of the 3d engine, setting the matrices, setting up the shaders, and doing the correct transforms. Three.js does this for you.

Perhaps you should look into quaternions? Specifically the axisAngle conversion to quats. THREE.OrbitControls won't do what you want.