public final void glOrthof( final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { // Ortho matrix: // 2/dx 0 0 tx // 0 2/dy 0 ty // 0 0 2/dz tz // 0 0 0 1 final float dx = right - left; final float dy = top - bottom; final float dz = zFar - zNear; final float tx = -1.0f * (right + left) / dx; final float ty = -1.0f * (top + bottom) / dy; final float tz = -1.0f * (zFar + zNear) / dz; matrixOrtho[0 + 4 * 0] = 2.0f / dx; matrixOrtho[1 + 4 * 1] = 2.0f / dy; matrixOrtho[2 + 4 * 2] = -2.0f / dz; matrixOrtho[0 + 4 * 3] = tx; matrixOrtho[1 + 4 * 3] = ty; matrixOrtho[2 + 4 * 3] = tz; glMultMatrixf(matrixOrtho, 0); }
public final void glTranslatef(final float x, final float y, final float z) { // Translation matrix: // 1 0 0 x // 0 1 0 y // 0 0 1 z // 0 0 0 1 matrixTrans[0 + 4 * 3] = x; matrixTrans[1 + 4 * 3] = y; matrixTrans[2 + 4 * 3] = z; glMultMatrixf(matrixTrans, 0); }
public final void glScalef(final float x, final float y, final float z) { // Scale matrix: // x 0 0 0 // 0 y 0 0 // 0 0 z 0 // 0 0 0 1 matrixScale[0 + 4 * 0] = x; matrixScale[1 + 4 * 1] = y; matrixScale[2 + 4 * 2] = z; glMultMatrixf(matrixScale, 0); }
public final void glFrustumf( final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { if (zNear <= 0.0f || zFar < 0.0f) { throw new GLException("GL_INVALID_VALUE: zNear and zFar must be positive, and zNear>0"); } if (left == right || top == bottom) { throw new GLException("GL_INVALID_VALUE: top,bottom and left,right must not be equal"); } // Frustum matrix: // 2*zNear/dx 0 A 0 // 0 2*zNear/dy B 0 // 0 0 C D // 0 0 -1 0 final float zNear2 = 2.0f * zNear; final float dx = right - left; final float dy = top - bottom; final float dz = zFar - zNear; final float A = (right + left) / dx; final float B = (top + bottom) / dy; final float C = -1.0f * (zFar + zNear) / dz; final float D = -2.0f * (zFar * zNear) / dz; matrixFrustum[0 + 4 * 0] = zNear2 / dx; matrixFrustum[1 + 4 * 1] = zNear2 / dy; matrixFrustum[2 + 4 * 2] = C; matrixFrustum[0 + 4 * 2] = A; matrixFrustum[1 + 4 * 2] = B; matrixFrustum[2 + 4 * 3] = D; matrixFrustum[3 + 4 * 2] = -1.0f; glMultMatrixf(matrixFrustum, 0); }
public final void glRotatef(final float angdeg, float x, float y, float z) { final float angrad = angdeg * (float) Math.PI / 180.0f; final float c = (float) Math.cos(angrad); final float ic = 1.0f - c; final float s = (float) Math.sin(angrad); vec3f[0] = x; vec3f[1] = y; vec3f[2] = z; FloatUtil.normalize(vec3f); x = vec3f[0]; y = vec3f[1]; z = vec3f[2]; // Rotation matrix: // xx(1-c)+c xy(1-c)+zs xz(1-c)-ys 0 // xy(1-c)-zs yy(1-c)+c yz(1-c)+xs 0 // xz(1-c)+ys yz(1-c)-xs zz(1-c)+c 0 // 0 0 0 1 final float xy = x * y; final float xz = x * z; final float xs = x * s; final float ys = y * s; final float yz = y * z; final float zs = z * s; matrixRot[0 * 4 + 0] = x * x * ic + c; matrixRot[0 * 4 + 1] = xy * ic + zs; matrixRot[0 * 4 + 2] = xz * ic - ys; matrixRot[1 * 4 + 0] = xy * ic - zs; matrixRot[1 * 4 + 1] = y * y * ic + c; matrixRot[1 * 4 + 2] = yz * ic + xs; matrixRot[2 * 4 + 0] = xz * ic + ys; matrixRot[2 * 4 + 1] = yz * ic - xs; matrixRot[2 * 4 + 2] = z * z * ic + c; glMultMatrixf(matrixRot, 0); }