# Off Center Projection ?

This topic is 1100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys,

Is is possible to make (an unrealistic) projection that appears as if the camera is offset even though it isn't ?

The image on the left is a regular projection, the look at point is the black object. I want it to be like the image on the right which I made by moving the look at point to the right (x+ axis) and then using Photoshop to move the cube back to the center.

Thanks.

##### Share on other sites
Yup, you just apply translation and scaling transformations after the perspective transform


finalPerspectiveMatrix = Translate(offsetX, 0, 0) * perspectiveMatrix


one thing to note, the view space after the perspective transform is in the range form -1 to 1 in the x direction, so offset would likely be a value in that range. If you need to zoom in after translating you can apply scale transformation after the perspective transform

##### Share on other sites

Hi HappyCoder,

I don't know what you mean by applying a translation *after* the perspective transform.

I pass the WorldViewProjection to the shader and it does the transform:

world = DirectX::XMMatrixIdentity();
view = DirectX::XMMatrixLookAtLH(eye, look, up);
projection = DirectX::XMMatrixPerspectiveFovLH(pi / 4.0f, aspect_ratio, near_z, far_z);

world_view = DirectX::XMMatrixMultiply(world, view);
world_view_projection = DirectX::XMMatrixMultiply(world_view, projection);


Thanks for helping.

##### Share on other sites

You just need to multiply your projection matrix by a translation matrix

world = DirectX::XMMatrixIdentity();
view = DirectX::XMMatrixLookAtLH(eye, look, up);
projection = DirectX::XMMatrixPerspectiveFovLH(pi / 4.0f, aspect_ratio, near_z, far_z);
// move the projection off center
projectionOffset = DirectX::XMMatrixTranslation(-offsetX, 0.0f, 0.0f);
projection = DirectX::XMMatrixMultiply(projection, projectionOffset);

world_view = DirectX::XMMatrixMultiply(world, view);
world_view_projection = DirectX::XMMatrixMultiply(world_view, projection);

Since your code appears to be using row vectors, your world matrix is on the right left and projection on the right. When using row vectors, matrices are applied from left to right so any matrices to the right of the projection, in this case projectionOffset, will be applied after the projection.

##### Share on other sites
Is is possible to make (an unrealistic) projection that appears as if the camera is offset even though it isn't ?

The image on the left is a regular projection, the look at point is the black object. I want it to be like the image on the right which I made by moving the look at point to the right (x+ axis) and then using Photoshop to move the cube back to the center.

It's actually *really* easy.

Your vertex shader simply outputs normalized screen coordinates (from -1 to 1) multiplied by W.

If you want to simulate the same shift in screen coordinates that you would get by shifting in Photoshop, then you take the computed screen coordinates (X/W, Y/W) and add the necessary constant amount to each one.

So to sum up If you want to shift from (Xo, Yo) in screen coordinates, you do this (after you've done all the transforms !) :

output.position.x += Xo * output.position.w;

output.position.y += Yo * output.position.w;

(Note : z and w won't change obviously).

Edited by LeGreg

##### Share on other sites

You just need to multiply your projection matrix by a translation matrix

I would not perform 4x4  multiplication of perspective matrix with 4x4 simple x axis translation because perspective matrix performs the w component construction in 4th row, performing later unlinear operation of w division (you would obviosly alter the w component row).

You can write the translation in x and y safely into the perspective matrix, performing the shift of object on screen, but that will not make it projected any different.

The solution to see the cube as if the camera was moved to side, is to add the translation to view matrix position column, and then, put the projection space offset to move it back (only on x or y or both, not z).

But to calibrate the amount of offset in normalized projection space synchronized with camera translation is more tricky.

As I think of it, the projection space offset vector (x,y) can be evaluated as

-original matrix World*View*Proj(objectposition)=(a,b,c) - the projected point of object space (0,0,0) of cube

-altered view matrix with camera translation World*View1*Proj(objectposition)=(d,e,f) - the projected point of object space (0,0,0) of cube with moved camera

(x,y)=(a-d,b-e)

and then you just add x and y, or one of them, to fourth column first two components of projection matrix.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633703
• Total Posts
3013455
×