Question

I have a camera within my 3D project that I'm trying to get to pan across the world along the z-axis. The camera is positioned at (0.0, 50.0, -75.0) with a target of (0.0, 1.0, 0.0). I'm just trying to get the camera to move from the first position to it's opposite of (0.0, 50.0, 75.0).

Within my constructor, I initialized the camera position, target and up vectors.

_camPos = glm::vec3(0.0f, 50.0f, -75.0f);
_target = glm::vec3(0.0f, 1.0f, 0.0f);
_up     = glm::vec3(0.0f, 1.0f, 0.0f);

Within my my OnInit function:

_viewMatrix = glm::lookAt(_camPos, _target, _up); // glm::mat4 _viewMatrix

And within my OnRender function:

_camPos.z += 0.05f;

The camera's position updates, but visually, the camera stays in the same place. I do have moving objects within my scene that are being updated in OnRender, but the camera itself won't move.

Was it helpful?

Solution

Just updating your _camPos.z in the per-frame render function won't do a thing. You have to also update the view matrix. Move _viewMatrix = glm::lookAt(_camPos, _target, _up); into the render function and you might see some results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top