Search code examples
mobilelibgdxperspectivecamera

libgdx modelinstances position changed after calling camera.position.set or camera.lookat


I have my camera with below initial settings: camera.lookAt(200f, 100f, -300f); camera.position.set(0f, 0f, 0f); and the modelinstances displayed as below: initial image

I coded a button on click and call the set of methods: camera.lookAt(200f, 100f, -300f); camera.position.set(0f, 0f, 0f);

and the screen became as below: call camera methods again

Between the initial image and the button click, I have done nothing else. To troubleshoot this problem, I've tried adding camera.up.set(xyz), camera.normalizedUp() but did not solve the problem.

Any suggestion? Thanks in advance.


Solution

  • I found that it's not the ModelInstances moved. It's the camera moved by the resize(). Under the resize() method, I've coded viewport.update(width, height, true) which will center the camera within the viewport and thus the camera moved without my notice. Also, the skybox is coded in a way that it will moved with the camera and makes it looks like the camera has not moved.