<p>Nothing is wrong.</p>
<p>If we suppose <code>n</code> is fixed, then <code>l</code>, <code>r</code>, <code>t</code>, and <code>b</code> control the <em>slope of the sides of the view frustum.</em> When you make <code>l</code> = 0, you are setting that slope to zero, and the left edge of the image corresponds to looking directly along the view direction of the camera.</p>
<p><a href="https://i.sstatic.net/XxpSX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XxpSX.png" alt="" /></a></p>
<p>Since you moved the cube too, and the cube is entirely to the right of the viewpoint, your projection is now allowing you a look at the left face of the cube.</p>
<p>What you're doing is effectively the same as cutting off the left half of a normal perspective projection. (Generally, you can arbitrarily skew the view projection frustum without changing its volume by adding the <em>same</em> amount to <code>l</code> and <code>r</code> or to <code>t</code> and <code>b</code>.)</p>
<p>In order to change the coordinate system without changing the projection, you should apply a translation to your view matrix, and leave the projection parameters unchanged.</p>

CC BY-SA 4.0
2023-05-19T21:17:59.960Z
After a moment of thinking, I figured it out, basically, dividing by z moves towards the zero, in my case the 0 is no longer the center of the image, but the left edge.
Serilena
CC BY-SA 4.0
2023-05-19T21:07:36.847Z
2023-05-19T21:07:36.847Z
Kevin Reid
<p>Assuming my viewing volume has x coordinates varies from l to r, and y varies from top to bottom, and finally z-axis varies n to f, I derived the following projection matrix:</p>
<pre><code>    mat4 projection = {
                      2n/(r-l), 0,       (r+l)/(r-l), 0,
                      0,        2n(t-b), (t+b)/(t-b), 0, 
                      0,        0,       (n+f)/(n-f), 2nf/(n-f),
                      0,        0,       -1,          0
</code></pre>
<p>which matches the projection matrix derived <a href="http://www.songho.ca/opengl/gl_projectionmatrix.html" rel="nofollow noreferrer">here</a></p>
<p>Plugging in values for my cube coordinates, to be centered in the middle of the screen with Left = -100, Right = 100, Top = 100, Bottom = -100. I have the following vertices positions:</p>
<pre><code>    f32 r =  100;
    f32 l = -100;

    f32 t =  100;
    f32 b = -100;

    f32 n = -1;
    f32 f = -3;

GLfloat VertexData[40] = 
{

    //--------- Vertex Positions ---------//
   -50.0f,  -50.0f,   1.0f,
   +50.0f,  -50.0f,   1.0f,
   +50.0f,  +50.0f,   1.0f, 
   -50.0f,  +50.0f,   1.0f,


   -50.0f,  -50.0f,   3.0f,
   +50.0f,  -50.0f,   3.0f,
   +50.0f,  +50.0f,   3.0f, 
   -50.0f,  +50.0f,   3.0f,
   //-------Other data for texture coordinates------//
   };
</code></pre>
<p>which produces the expected image</p>
<p><a href="https://i.sstatic.net/3I06J.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3I06J.png" alt="Image" /></a></p>
<p>and here is my question: <strong>if I am using a non-symmetric boundaries (Right != -Left) should not the output image be the same?</strong></p>
<p>I set Right = 100, Left = 0, and I changed vertices positions to be from 25 to 75 ([-50,+50] range with respect to r =100, l = -100 should be equivalent to [+25,+75] with r = 100, l = 0) but the output image does not match</p>
<p><a href="https://i.sstatic.net/vBVzt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vBVzt.png" alt="https://cdn.discordapp.com/attachments/591343919598534681/1108811954308534392/image.png" /></a></p>
<p>Looking at it, it seems like the perspective divide moves further away points to the edge of the screen, instead of the center of the screen.</p>
<p>full source code for this example is available <a href="https://git.sr.ht/%7Ealiabdulkareem/openGLTemplate/tree/master" rel="nofollow noreferrer">here</a></p>

<opengl><rendering><projections><perspective><clipping>
My projection matrix for OpenGL fails on non-symmetric boundaries
Serilena
# My projection matrix for OpenGL fails on non-symmetric boundaries

(Asked by: username_0 on 2023-05-19)

Assuming my viewing volume has x coordinates varies from l to r, and y varies from top to bottom, and finally z-axis varies n to f, I derived the following projection matrix:

```
    mat4 projection = {
                      2n/(r-l), 0,       (r+l)/(r-l), 0,
                      0,        2n(t-b), (t+b)/(t-b), 0, 
                      0,        0,       (n+f)/(n-f), 2nf/(n-f),
                      0,        0,       -1,          0

```

which matches the projection matrix derived [here](http://www.songho.ca/opengl/gl_projectionmatrix.html)

Plugging in values for my cube coordinates, to be centered in the middle of the screen with Left = -100, Right = 100, Top = 100, Bottom = -100. I have the following vertices positions:

```
    f32 r =  100;
    f32 l = -100;

    f32 t =  100;
    f32 b = -100;

    f32 n = -1;
    f32 f = -3;

GLfloat VertexData[40] = 
{

    //--------- Vertex Positions ---------//
   -50.0f,  -50.0f,   1.0f,
   +50.0f,  -50.0f,   1.0f,
   +50.0f,  +50.0f,   1.0f, 
   -50.0f,  +50.0f,   1.0f,

   -50.0f,  -50.0f,   3.0f,
   +50.0f,  -50.0f,   3.0f,
   +50.0f,  +50.0f,   3.0f, 
   -50.0f,  +50.0f,   3.0f,
   //-------Other data for texture coordinates------//
   };

```

which produces the expected image

[![Image](https://i.sstatic.net/3I06J.png)](https://i.sstatic.net/3I06J.png)

and here is my question: **if I am using a non-symmetric boundaries (Right != -Left) should not the output image be the same?**

I set Right = 100, Left = 0, and I changed vertices positions to be from 25 to 75 ([-50,+50] range with respect to r =100, l = -100 should be equivalent to [+25,+75] with r = 100, l = 0) but the output image does not match

[![https://cdn.discordapp.com/attachments/591343919598534681/1108811954308534392/image.png](https://i.sstatic.net/vBVzt.png)](https://i.sstatic.net/vBVzt.png)

Looking at it, it seems like the perspective divide moves further away points to the edge of the screen, instead of the center of the screen.

full source code for this example is available [here](https://git.sr.ht/%7Ealiabdulkareem/openGLTemplate/tree/master)

**Tags:** opengl, rendering, projections, perspective, clipping


---

## 1 answers

### Answer by username_1 on 2023-05-19. Score: 0 | Accepted answer

Nothing is wrong.

If we suppose `n` is fixed, then `l`, `r`, `t`, and `b` control the *slope of the sides of the view frustum.* When you make `l` = 0, you are setting that slope to zero, and the left edge of the image corresponds to looking directly along the view direction of the camera.

[![](https://i.sstatic.net/XxpSX.png)](https://i.sstatic.net/XxpSX.png)

Since you moved the cube too, and the cube is entirely to the right of the viewpoint, your projection is now allowing you a look at the left face of the cube.

What you're doing is effectively the same as cutting off the left half of a normal perspective projection. (Generally, you can arbitrarily skew the view projection frustum without changing its volume by adding the *same* amount to `l` and `r` or to `t` and `b`.)

In order to change the coordinate system without changing the projection, you should apply a translation to your view matrix, and leave the projection parameters unchanged.

> **Comments:**
> **username_0**: After a moment of thinking, I figured it out, basically, dividing by z moves towards the zero, in my case the 0 is no longer the center of the image, but the left edge.  

---

