BGE Camera Shift + Camera Projection Matrix


I’ve been Googling this for ages and pored over the forum but can’t find a working answer…

I’m trying to change the camera shift values based on the camera’s distance from a center line (in this case, simply the Y axis), so I’m trying to write it as a function of the camera’s x-position. Since the shift_x and shift_y parameters don’t seem to be exposed, I’ve read that you need to change the camera projection matrix.

I tried following this: but that doesn’t seem to work.

Would really appreciate any pointers or help for how to deal with camera projection matrices properly!

I don’t see why you need to use the projection matrix. You have acess to the camera’s position via camera.worldPosition. If you only care about distance the camera is from the line along the y-axis in one dimenstion (the x-axis), the magnitude of camera.worldPosition.x gives you the value you need.

If you need to get the distance from the line in two or three dimenstions, just use the equation for the distance from a point to a line.

EDIT: I may have misunderstood your questions when I read it the first time. If you’re trying to change the camera projection matrix using the script on that page, you need to specify your own values for shiftx and shifty corresponding to how much you want to shift the matrix.

Mobious: I’m trying to use camera shift in the Game Engine, so that the view always stays locked onto a set ‘viewing plane’ while the camera moves around in 3d space. Getting the camera’s position is no problem, it’s shifting the lens / viewing plane in terms of the camera’s distance from the Y-axis (camera lens shift as a function of its x-position).

I’ve got the formula for getting my shift_x and shift_y values from an earlier script, I’m just having trouble figuring out where to plug them in… Following the script on the page I linked to does not work, and I suspect that’s from an earlier Blender version…

I hope that makes it a bit clearer! And thanks for helping out :slight_smile:

If you only want the camera to be looking at fixed plane, why not just keep the camera from rotating. Then all you need to worry about is when the camera passes through the plane. In that case you just have rotate the camera 180 degrees about its local y-axis.

Take a look at this crude diagram:

The camera - which is the apex of the triangle, on the y-axis - is looking at the plane a-b. The camera lens / angle is exactly as wide as plane a-b at that specific distance along the y-axis. There is no movement along the y-axis in this example. There is absolutely no rotation of the camera either.

When the camera shifts in the x-direction, the frustrum needs to stay locked to plane a-b. The original lens angle is shown by the dashed line, and the solid line shows what needs to happen to the frustrum.

This is done by adjusting the lens shift, which is easily done in the main Blender interface ([camera_name].shift_x and .shift_y), however, it appears that to do this within the Game Engine requires you to manipulate the camera projection matrix - something a fair bit more involved.

That’s the bit that I’m stuck on: how to make sense of the projection matrix and how to go about manipulating it as I would the shift_x and shift_y parameters in the regular Blender interface.

I hope that clears things up! Thanks for bearing with me.

Thanks, the diagram makes it a lot more clear.

I’m just as lost as you are when it comes to calculating the values to use for the new projection matrix.

Is there some reason you can just keep the camera still or parent the plane to the camera? Those would be the solutions people would normally use.

No, it’s exactly the perspectival distortion that I’m after, so it needs to be done with lens shift…

Thanks for your help, though! I’ll keep looking.