Camera Problem


I got the camera setup correctly but when I start the navigation , the camera doesn’t follow the specified path. However when I print the x,y,z coordinates of vFrom, they are showing the correct coordinates. For example, I have a box with 8 vertices with coordinates (-0.5 0.5 1, -0.5 -0.5 1, 0.5 -0.5 1, 0.5 0.5 1, 0.5 -0.5 0, 0.5 0.5 0, -0.5 0.5 0, -0.5 -0.5 0, ). And I have a rectangle with coordinates (-0.6 -0.6 0, -0.6 -0.8 0, 0.6 -0.8 0, 0.6 -0.6 0).

I start the camera from vFrom = (-0.7f, -0.7f, 0.5f) and vTo = (0.7f, -0.7f, 0.5f) with increasing the x-coordinate of vFrom by 0.005 units every time in the RenderScene() function. Therefore, the camera should move straight parallel to the building. But for some reason, it is moving at an angle to the building and finally colliding into it.

I printed the vFrom.x in the RenderScene() function and it shows the correct values everytime.

Does someone know what problem is this ?

I think you’ve misunderstood how the camera construction in our tools works.

vFrom is your camera’s position.

vTo is the point in your scene you’re looking at.

By only modifying vFrom.x, the camera’s is being translated along the x axis but it is still looking at the same point in space. This is why you’re seeing a rotation. You can resolve this by also translating the x-coordinate of your vTo vector at the same time.



But if I want to travel straight and the x coordinate of my vTo lies at the end point of my straight path , why should I change it ?

If you want your camera to move along the axis without rotation, the x-coordinate of your vFrom & vTo vectors must be incremented/decremented by the same value to ensure the moving camera is parallel.

the vTo vector should be your current point of interest. In your case, I think it would be best to keep this at a fixed distance from your vFrom vector. Incrementing both vectors as I’ve suggested would do this.



I sorted out the rotation problem. When I removed all the model matrices and used only (ProjectionMatrix * ViewMatrix) as the matrix which is passed to the shader, the camera starts moving on the parallel path. But, a new problem came up.

As I said there are four streets on all the sides of the building. The camera moves perfectly on the first three streets but on the fourth street, it goes crazy and moves random. The building starts falling and all. What is the problem ?

maybe it s only your Vto that get set by wrong value giving the impression that your building are falling where it s only the camera motion that triggered it .

Thanks David. It was vTo indeed that was causing problems. Got the navigation perfect. :smiley: