[SOLVED] Camera matrixView update

I have an issue with the camera component. You can see the issue in the clip:

You may notice the black screen appearing at the bottom. After some debugging, I found that it was because the viewMatrix has changed, and as a result affected the camera frustum:

image vs image

I would like to know what actions may affect the camera viewMatrix? I think the only thing I do with the camera is move it by .setPosition().

Can’t think of anything off hand besides scaling. Are you (accidentally) reusing and modifying returned objects from getPosition and the such?

It almost looks like the near clip has changed too.

Well, I do re-use the Vec3 position, which holds the new camera position:

this.targetPosition = CameraHandler._p2;        // re-use Vec3
this.targetPosition.copy(cameraPos).add(temp);  // calc new position
this.camera.setPosition(this.targetPosition);   // set camera to new pos

The camera isn’t parented to any entity that is changing its scale, right?

Nope, the orthographic camera is in the root as a standalone entity. It is not attached to anything. So, you guys think this might come from scaling? The only things I scale are the platform meshes. I will look into it to make sure the camera doesn’t use any scale objects from there, but it shouldn’t.

Ah, if you are using an orthographic camera and you are changing its position make sure the orthoHeight property is big enough to fit the scene.

Try playing with some values and see if it has any impact.


That did place a camera further away from the ground, which helped to highlight the issue:

And my camera:

I think what might happen is that the ground plane goes into the near plane of the camera frustum. However, I would think that if the camera moves back, the frustum should include the previously cut parts? I will play with this a bit more.

Got it. The issue was with the current camera position height vs the new position height. I find the new position by casting the ray. That ray could hit an existing platform, which made the ground level elevated. That affected the math responsible for calculating the new camera position. The orthographic camera didn’t show the change in height, but switching it to perspective immediately showed the camera gradually moving towards the ground. As a result, the ground plane got inside the near plane of the frustum, effectively getting cut. Ignoring the height of the possible obstacle on the ground solved it by keeping the camera at the same distance from the ground.

Thank you, @Leonidas, @yaustar!