So I’ve started to switch a project over from using old deprecated OpenGL to the new core profile stuff. So while reimplementing the perspective camera, and then running the program, I noticed that nothing was being drawn, or everything was off the screen. So I opened up the debugger and saw this in the mesh view.
Why is it that all of those vertices are squished together on the z/x axis like that? All of the math for the making the perspective camera looks correct, as shown below.
package com.tinfoilboy.yagl.render;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;
import static org.lwjgl.opengl.GL11.*;
import com.tinfoilboy.yagl.MainApplication;
public class PerspectiveCamera extends Camera
{
private float fieldOfView = 60.0f;
private float aspectRatio = 0.0f;
private float nearZ = 0.1f;
private float farZ = 1000.0f;
public Matrix4f projection = new Matrix4f();
public Matrix4f view = new Matrix4f();
public Vector3f position = new Vector3f();
public Vector3f rotation = new Vector3f();
public PerspectiveCamera()
{
this(75.0f, MainApplication.getWidth() / MainApplication.getHeight(), 0.1f, 1000.0f);
}
public PerspectiveCamera(float fieldOfView, float aspectRatio, float nearZ, float farZ)
{
this.fieldOfView = fieldOfView;
this.aspectRatio = aspectRatio;
this.nearZ = nearZ;
this.farZ = farZ;
init(false);
}
@Override
protected void init(boolean isResize)
{
glViewport(0, 0, (int) MainApplication.getWidth(), (int) MainApplication.getHeight());
setupProjectionMatrix();
}
@Override
public void update()
{
view.set(0.0f);
view.setTranslation(position);
view.setRotation(new Quat4f(rotation.x, rotation.y, rotation.z, 1.0f));
view.setScale(1.0f);
}
public float getAspectRatio()
{
return aspectRatio;
}
@Override
public void resize(float width, float height)
{
aspectRatio = width / height;
init(true);
}
public Matrix4f getProjection()
{
return projection;
}
public Matrix4f getView()
{
return view;
}
public float getFarZ()
{
return farZ;
}
private void setupProjectionMatrix()
{
float tanHalfFovy = (float) Math.tan(fieldOfView / 2.0f);
projection.m00 = 1.0f / (aspectRatio * tanHalfFovy);
projection.m11 = 1.0f / tanHalfFovy;
projection.m22 = -(farZ + nearZ) / (farZ - nearZ);
projection.m23 = -1.0f;
projection.m32 = -(2.0f * farZ * nearZ) / (farZ - nearZ);
}
}
Any help would be appreciated.