Hello Guest

# JOML perspective matrix problem?

• 2 Replies
• 3401 Views

#### Gojira

• 22
##### JOML perspective matrix problem?
« on: July 09, 2017, 03:50:54 »
Hi all, I just tried some very basic JOML code, and I got an odd answer.

public class JomlTest {
public static void main( String[] args ) {
System.out.println( new Matrix4f().setPerspective( (float)Math.PI/3, 2,
0.1f, 1000f ) );
}
}

run:
8.660E-1  0.000E+0  0.000E+0  0.000E+0
0.000E+0  1.732E+0  0.000E+0  0.000E+0
0.000E+0  0.000E+0 -1.000E+0 -2.000E-1
0.000E+0  0.000E+0 -1.000E+0  0.000E+0

BUILD SUCCESSFUL (total time: 0 seconds)

Is that right?  Did I do something wrong?  The third column is confusing me, shouldn't the first and second element have non-zero values?

This is a relatively recent 1.9.4 snapshot that I downloaded from GitHub and compiled myself.

#### Kai

##### Re: JOML perspective matrix problem?
« Reply #1 on: July 09, 2017, 10:26:12 »
A symmetric perspective projection matrix (as built by this method) has no X or Y skew factors (i.e. neither X or Y depend on Z), since the principal axis (perpendicular to the projection plane) passes both through the center of the near and far projection planes. In other words, it is no "off-center" projection.
If you use Matrix4f.setFrustum()/frustum() then m20/m21 may have non-zero values depending on how much the projection frustum is skewed along X/Y, controlled by the left/right and bottom/top values.

I really recommend you read this:
- http://www.songho.ca/opengl/gl_projectionmatrix.html
- http://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/opengl-perspective-projection-matrix
« Last Edit: July 09, 2017, 10:27:46 by Kai »

#### Gojira

• 22
##### Re: JOML perspective matrix problem?
« Reply #2 on: July 09, 2017, 17:33:19 »
Ah, OK.  I can see now that the other terms in that third column would cancel and go to zero.  Sorry about the false alarm, it just looked weird when I printed it out because I was only used to seeing the more general form.

Thanks for the prompt reply btw.  You guys are always attentive and always on point.  LWJGL has great support.