<p>Yes, you can use an off-axis projection matrix.
This is what I use in my code (note: I shift the centre upwards, not left as you do in your example.)</p>

<pre><code>void camera_setAspectRatio(float aspect, float zNear, float zFar, bool offaxis)
{
        // create a projection matrix
        const float f = 1.0f / tanf(fovy_radians/2.0f);
        fovx_radians = 2.0f * atanf( aspect * tanf(fovy_radians/2.0f) );
        float* mout = proj.data;

        mout[0] = f / aspect;
        mout[1] = 0.0f;
        mout[2] = 0.0f;
        mout[3] = 0.0f;

        mout[4] = 0.0f;
        mout[5] = f;
        mout[6] = 0.0f;
        mout[7] = 0.0f;

        mout[8] = 0.0f;
        mout[9] = offaxis ? -0.25f : 0.0f; // off axis projection!
        mout[10] = (zFar+zNear) / (zNear-zFar);
        mout[11] = -1.0f;

        mout[12] = 0.0f;
        mout[13] = 0.0f;
        mout[14] = 2 * zFar * zNear /  (zNear-zFar);
        mout[15] = 0.0f;
}
</code></pre>

<p>Stereo Projection screens (not head-mounted) tend to use Off-Axis projection matrices as well. <a href="http://paulbourke.net/stereographics/stereorender/" rel="noreferrer">Paul Bourke</a> has a great write up on these projections.</p>

CC BY-SA 3.0
2017-05-03T21:12:54.930Z
2017-05-03T21:12:54.930Z
Bram
<p>So ordinarily we have this</p>

<p><a href="https://i.sstatic.net/W7GLv.png" rel="noreferrer"><img src="https://i.sstatic.net/W7GLv.png" alt="enter image description here"></a></p>

<p>But I'm after this!</p>

<p><a href="https://i.sstatic.net/3bVXX.png" rel="noreferrer"><img src="https://i.sstatic.net/3bVXX.png" alt="enter image description here"></a></p>

<p>Is it possible to do this? Ideally by changing the projection matrix?</p>

<p>The reasoning is kinda interesting - I am developing for mobile VR, and I have found that putting my phone (and surely many others) in headsets that are too wide for them makes its so that your horizontal perspective convergence point is in the wrong place.</p>

<projections><perspective><matrix><camera>
Render with camera perspective off-center
Hamish Todd
# Render with camera perspective off-center

(Asked by: username_0 on 2017-05-03)

So ordinarily we have this

[![enter image description here](https://i.sstatic.net/W7GLv.png)](https://i.sstatic.net/W7GLv.png)

But I'm after this!

[![enter image description here](https://i.sstatic.net/3bVXX.png)](https://i.sstatic.net/3bVXX.png)

Is it possible to do this? Ideally by changing the projection matrix?

The reasoning is kinda interesting - I am developing for mobile VR, and I have found that putting my phone (and surely many others) in headsets that are too wide for them makes its so that your horizontal perspective convergence point is in the wrong place.

**Tags:** projections, perspective, matrix, camera


---

## 1 answers

### Answer by username_1 on 2017-05-03. Score: 7 | Accepted answer

Yes, you can use an off-axis projection matrix.
This is what I use in my code (note: I shift the centre upwards, not left as you do in your example.)

```
void camera_setAspectRatio(float aspect, float zNear, float zFar, bool offaxis)
{
        // create a projection matrix
        const float f = 1.0f / tanf(fovy_radians/2.0f);
        fovx_radians = 2.0f * atanf( aspect * tanf(fovy_radians/2.0f) );
        float* mout = proj.data;

        mout[0] = f / aspect;
        mout[1] = 0.0f;
        mout[2] = 0.0f;
        mout[3] = 0.0f;

        mout[4] = 0.0f;
        mout[5] = f;
        mout[6] = 0.0f;
        mout[7] = 0.0f;

        mout[8] = 0.0f;
        mout[9] = offaxis ? -0.25f : 0.0f; // off axis projection!
        mout[10] = (zFar+zNear) / (zNear-zFar);
        mout[11] = -1.0f;

        mout[12] = 0.0f;
        mout[13] = 0.0f;
        mout[14] = 2 * zFar * zNear /  (zNear-zFar);
        mout[15] = 0.0f;
}

```

Stereo Projection screens (not head-mounted) tend to use Off-Axis projection matrices as well. [Paul Bourke](http://paulbourke.net/stereographics/stereorender/) has a great write up on these projections.


---

