Java Code Examples for org.lwjgl.util.vector.Matrix4f#setZero()

The following examples show how to use org.lwjgl.util.vector.Matrix4f#setZero() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatrixUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Matrix4f createOrthoMatrix(final float left, final float right, final float bottom, final float top, final float near, final float far)
{
	Matrix4f ortho = new Matrix4f();
	ortho.setZero();
	
	// First the scale part
	ortho.m00 = 2.0f / (right - left);
	ortho.m11 = 2.0f / (top - bottom);
	ortho.m22 = (-2.0f) / (far - near);
	ortho.m33 = 1.0f;
	
	// Then the translation part
	ortho.m30 = -( (right+left) / (right-left) );
	ortho.m31 = -( (top+bottom) / (top-bottom) );
	ortho.m32 = -( (far+near) / (far-near) );
	
	return ortho;
}
 
Example 2
Source File: MatrixUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static Matrix4f createPerspectiveMatrix(final float fovYDeg, final float aspect, final float zNear, final float zFar)
{
	Matrix4f persp = new Matrix4f();
	persp.setZero();
	
	final float fovYRad = degToRad(fovYDeg);
	
	final float f = 1.0f / (float)Math.tan( fovYRad/2 );
	
	persp.m00 = f / aspect;
	persp.m11 = f;
	persp.m22 = (zFar + zNear) / (zNear-zFar);
	
	persp.m23 = -1;
	
	persp.m32 = (2*zNear*zFar) / (zNear-zFar);
	
	return persp;
}