Im programming with opengl (lwjgl) and building my own mini-library. My Camera, which takes the projection type, builds its projection matrix like this:
this.aspect = (float) Display.getWidth() / (float) Display.getHeight();
this.top = (float) (Math.tan(Math.toRadians(fov) / 2));
this.bottom = -top;
this.right = top * aspect;
this.left = -right;
if(type == AGLProjectionType.PERSPECTIVE){
float aspect = 800.0f / 600.0f;
final double f = (1.0 / Math.tan(Math.toRadians(fov / 2.0)));
projection = new Matrix4f();
projection.m00 = (float) (f / aspect);
projection.m11 = (float) f;
projection.m22 = (far + near) / (near - far);
projection.m23 = -1;
projection.m32 = (2 * far + near) / (near - far);
projection.m33 = 0;
}
else if(type == AGLProjectionType.ORTHOGONAL){
projection.m00 = 2 / (right - left);
projection.m03 = -(right + left) / (right - left);
projection.m11 = 2 / (top - bottom);
projection.m13 = -(top + bottom) / (top - bottom);
projection.m22 = -2 / (far - near);
}
So far so good. Now, the VBO input, so the raw meshes of objects - for example a quad - i keep in the normalized dimension, so values in the range of [ -1 | 1 ]. If i want to scale it, i scale the model matrix to a value, and to move it i translate the model matrix. My Problem is: That are all relative values. If i say "matrix.scale(0.5f, 0.5f, 0.5f)" the object will take the half of its previous size. But what if for example i want to have an object with 500 pixel width? How can i calculate this? Or if i want the object to be Screen.width / heiht, and x = -Screen.width * 0.5 and y = -Screen.height * 0.5 - so an object wich fills out the screen and has his position in the upper left corner of the screen? I have to calculate something with help of the projection matrix - right? But how?