Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About orthographic projection matrix #785

Open
Ligo04 opened this issue Mar 13, 2024 · 2 comments
Open

About orthographic projection matrix #785

Ligo04 opened this issue Mar 13, 2024 · 2 comments
Assignees

Comments

@Ligo04
Copy link

Ligo04 commented Mar 13, 2024

I don't particularly understand why the projection matrix function projection_matrix of the orthographic camera uses the following calculation formulas for top, bottom, right, left. The ndc coordinates calculated in this way are incorrect.

top = 1.0
bottom = -top
right = 1.0 * self.width / self.height
left = -right

Instead of using the standard form, the function code is commented out and the ndc calculated using the standard form is correct.

top = self.height / 2
bottom = -top
right = self.width / 2
left = -right
@Ligo04 Ligo04 changed the title About orthogonal camera projection matrix About orthographic camera projection matrix Mar 13, 2024
@Ligo04 Ligo04 changed the title About orthographic camera projection matrix About orthographic projection matrix Mar 13, 2024
@orperel
Copy link
Collaborator

orperel commented Mar 13, 2024

Hi @Ligo04 !

Off the top of my head (I still need to empirically test how it plays with the rest of the code) I think you're right -

The ortho matrix is:

$$ \left(\begin{array}{cc} \frac{2}{right-left} & 0 & 0 & -\frac{right+left}{right-left} \\ 0 & \frac{2}{top-bottom} & 0 & -\frac{top+bottom}{top-bottom} \\ 0 & 0 & -\frac{2}{far-near} & -\frac{far+near}{far-near} \\ 0 & 0 & 0 & 1 \\ \end{array}\right) $$

Subbing the current case (1):

$$ \left(\begin{array}{cc} \frac{H}{W} & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & -\frac{2}{far-near} & -\frac{far+near}{far-near} \\ 0 & 0 & 0 & 1 \\ \end{array}\right) $$

Subbing the commented out case (2):

$$ \left(\begin{array}{cc} \frac{2}{W} & 0 & 0 & 0 \\ 0 & \frac{2}{H} & 0 & 0 \\ 0 & 0 & -\frac{2}{far-near} & -\frac{far+near}{far-near} \\ 0 & 0 & 0 & 1 \\ \end{array}\right) $$

where $W,H$ are the image plane width, height.

For the default NDC space ranging [-1,1] (aligned with old OpenGL conventions) the viewing volume should be a 2 units wide cuboid, so case (2) should be the correct one.

@orperel orperel self-assigned this Mar 13, 2024
@Ligo04
Copy link
Author

Ligo04 commented Mar 14, 2024

Hi @Ligo04 !

Off the top of my head (I still need to empirically test how it plays with the rest of the code) I think you're right -

The ortho matrix is:

$$ \left(\begin{array}{cc} \frac{2}{right-left} & 0 & 0 & -\frac{right+left}{right-left} \ 0 & \frac{2}{top-bottom} & 0 & -\frac{top+bottom}{top-bottom} \ 0 & 0 & -\frac{2}{far-near} & -\frac{far+near}{far-near} \ 0 & 0 & 0 & 1 \ \end{array}\right) $$

Subbing the current case (1):

$$ \left(\begin{array}{cc} \frac{H}{W} & 0 & 0 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & -\frac{2}{far-near} & -\frac{far+near}{far-near} \ 0 & 0 & 0 & 1 \ \end{array}\right) $$

Subbing the commented out case (2):

$$ \left(\begin{array}{cc} \frac{2}{W} & 0 & 0 & 0 \ 0 & \frac{2}{H} & 0 & 0 \ 0 & 0 & -\frac{2}{far-near} & -\frac{far+near}{far-near} \ 0 & 0 & 0 & 1 \ \end{array}\right) $$

where $W,H$ are the image plane width, height.

For the default NDC space ranging [-1,1] (aligned with old OpenGL conventions) the viewing volume should be a 2 units wide cuboid, so case (2) should be the correct one.

Yes. Thanks~. Hope this can be updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants