Hi all. Hope for a good day. I am facing a weird orientation of my object(not all but only for some case).
I have a 3D object loaded from a glb file(created in blender). My object is looking at -Y of blender so which is equivalent to looking at +Z in 3JS (since their axis lable is different).
Now I have two 3D point B, A. I position my object at B (also the center of rotation for my object) and scale it upto A. So my object is not BA. In the animation loop these points are continuously updating. And I continuously calculate my camera position from B, my camera is not fixed it moves along B. I have two camera and their direction from B are Cs(side camera direction to see objects Side view), and Cf(front camera direction to see objects Front View).
So i calculate the two camera position using these direction vector and B. And after that I set camera lookAt vector to B.
Something like this,
camera.position.copy(B+Cf)
camera.lookAt(B)
Now my object rotates on its local X axis always. So to find the rotation of the object. I use two thing.
- Set object.lookAt(camera.position) to always face the camera
- Find angle between (Cs x Cf) and AB vector and apply object.rotateOnAxis(Xaxis, angle)
However the problem is, almost 95% it works. But sometimes it seems that the rotation is in opposite direction. (Based on side view camera sees). My side view uses a 2D sprite instead of 3D object and calculate the object rotation simple by Math.atan2(AB.y, AB.x)
Now the problem is in some points, my side view sees the object rotating in one direction, and front canera sees it exactlt opposite direction. The rotation amount is same but direction is opposite. And interestingly, if I see the points in the screen the rotation seems correct, i mean in data space the rotation is okay, the only problem i think is the front camera perspective. It seems like the camera is sitting on the opposite side from its actual position.
Is my camera positioning and looking At is okay? And my object positionig and lookingAt function + rotation function is correct? I think I am missing some fundamental aspects.