Created
November 13, 2012 17:19
-
-
Save olamedia/4067099 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected FloatBuffer Mvi = FloatBuffer.allocate(16); | |
protected FloatBuffer Pi = FloatBuffer.allocate(16); | |
protected ProjectFloat projectFloat = new ProjectFloat(true); | |
public void renderFrustum() { | |
GL2 gl = GLContext.getCurrentGL().getGL2(); | |
gl2 = gl; | |
gl.glDisable(GL2.GL_CULL_FACE); | |
gl.glDisable(GL2.GL_DEPTH_TEST); | |
gl.glDisable(GL2.GL_TEXTURE_2D); | |
gl.glDisable(GL2.GL_ALPHA_TEST); | |
gl.glEnable(GL2.GL_BLEND); | |
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE); | |
gl.glColor4f(0.2f, 0.2f, 0.7f, 0.3f); | |
gl.glBegin(GL2.GL_QUADS); | |
flb.v(); | |
flt.v(); | |
frt.v(); | |
frb.v(); | |
gl.glEnd(); | |
gl.glBegin(GL2.GL_QUADS); | |
nlb.v(); | |
nlt.v(); | |
nrt.v(); | |
nrb.v(); | |
gl.glEnd(); | |
gl.glBegin(GL2.GL_LINES); | |
gl.glColor4f(1f, 1f, 1f, 0.4f); | |
nearc.v(); | |
farc.v(); | |
gl.glColor3f(1.0f, 0.0f, 1.0f); | |
nlb.v(); | |
flb.v(); | |
nlt.v(); | |
flt.v(); | |
nrt.v(); | |
frt.v(); | |
nrb.v(); | |
frb.v(); | |
gl.glEnd(); | |
} | |
public void updateFrustum() { | |
frustum.updateByPlanes(pmvMatrix.glGetFrustum().getPlanes()); | |
projectFloat.gluInvertMatrixf(pmvMatrix.glGetMvMatrixf(), Mvi); | |
projectFloat.gluInvertMatrixf(pmvMatrix.glGetPMatrixf(), Pi); | |
final float tang = (float) Math.tan((Math.PI * fov / 180) / 2.0f); | |
final float near = 1f; | |
final float far = 100f; | |
final float nh = near * tang; | |
final float nw = nh * aspect; | |
final float fh = far * tang; | |
final float fw = fh * aspect; | |
eye.set(position.x, position.y, position.z); | |
nearc.set(eye); | |
nearc.translate(look, -near); | |
farc.set(eye); | |
farc.translate(look, -far); | |
flb.set(farc); | |
flb.translate(right, -fw / 2); | |
flb.translate(up, -fh / 2); | |
flt.set(farc); | |
flt.translate(right, -fw / 2); | |
flt.translate(up, fh / 2); | |
frb.set(farc); | |
frb.translate(right, fw / 2); | |
frb.translate(up, -fh / 2); | |
frt.set(farc); | |
frt.translate(right, fw / 2); | |
frt.translate(up, fh / 2); | |
nlb.set(nearc); | |
nlb.translate(right, -nw / 2); | |
nlb.translate(up, -nh / 2); | |
nlt.set(nearc); | |
nlt.translate(right, -nw / 2); | |
nlt.translate(up, nh / 2); | |
nrb.set(nearc); | |
nrb.translate(right, nw / 2); | |
nrb.translate(up, -nh / 2); | |
nrt.set(nearc); | |
nrt.translate(right, nw / 2); | |
nrt.translate(up, nh / 2); | |
} | |
private vec eye = new vec(); | |
private vec nearc = new vec(); | |
private vec flb = new vec(); | |
private vec flt = new vec(); | |
private vec frb = new vec(); | |
private vec frt = new vec(); | |
private vec nlb = new vec(); | |
private vec nlt = new vec(); | |
private vec nrb = new vec(); | |
private vec nrt = new vec(); | |
private vec farc = new vec(); | |
private GL2 gl2; | |
private class vec { | |
public float x; | |
public float y; | |
public float z; | |
public void v() { | |
gl2.glVertex3f(x, y, z); | |
} | |
public void set(vec v) { | |
set(v.x, v.y, v.z); | |
} | |
public void set(float x, float y, float z) { | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
} | |
public void translate(Vector3f dir, float d) { | |
translate(dir.x * d, dir.y * d, dir.z * d); | |
} | |
public void translate(float x, float y, float z) { | |
this.x += x; | |
this.y += y; | |
this.z += z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment