public void displayInit(Point pickPoint) { gl.glShadeModel(GL.GL_SMOOTH); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); if (pickPoint != null) { int[] vp = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, vp, 0); GLU glu = new GLU(); int px = (int) pickPoint.getX(); int py = (int) (vp[3] - pickPoint.getY()); glu.gluPickMatrix(px, py, 1e-2, 1e-2, vp, 0); } gl.glOrtho(0, bounds.getWidth(), 0, bounds.getHeight(), .1, depth); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(0, 0, depth - 0.1, 0, 0, 0, 0, 1, 0); gl.glInitNames(); gl.glPushName(-1); }
public void prepare(GL2 gl, GLU glu, GLUT glut) { if (DEBUG) { System.out.println("Eye: " + eyeX + ", " + eyeY + ", " + eyeZ); System.out.println("Center: " + centerX + ", " + centerY + ", " + centerZ); System.out.println("ViewUp: " + viewUpX + ", " + viewUpY + ", " + viewUpZ); } glu.gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, viewUpX, viewUpY, viewUpZ); }
@Override public void display(GLAutoDrawable dr) { GL2 gl = dr.getGL().getGL2(); // Очиска экрана gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Загрузка единичной матрицы gl.glLoadIdentity(); // Определение точки и направления взгляда glu.gluLookAt(0f, 0f, 2f, 0f, 0f, -100f, 0f, 1f, 0f); renderer.render(gl, model); }
public void setup(GL gl, GLU glu) { glu.gluLookAt( location.getX(), location.getY(), location.getZ(), target.getX(), target.getY(), target.getZ(), 0.0f, 1.0f, 0.0f); }
public void eertLookAt(GL gl) { GLU glu = new GLU(); this.loc = this.engine.camMove.pos; glu.gluLookAt( this.engine.camMove.pos.x, this.engine.camMove.pos.y, this.engine.camMove.pos.z, this.engine.camMove.lookAt.x, this.engine.camMove.lookAt.y, this.engine.camMove.lookAt.z, 0f, 1f, 0f); }
@Override public void display(GLAutoDrawable dr) { GL2 gl = dr.getGL().getGL2(); // Очиска экрана gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Загрузка единичной матрицы gl.glLoadIdentity(); // Определение точки и направления взгляда glu.gluLookAt(0f, 0f, 10f, 0f, 0f, -100f, 0f, 1f, 0f); // Загрузка текстуры в графическую память this.texture.bind(gl); GLUquadric ground = glu.gluNewQuadric(); // enabling texturing on the quadric glu.gluQuadricTexture(ground, true); glu.gluSphere(ground, 1, 64, 64); glu.gluDeleteQuadric(ground); }
/** performs the gl camera transformations for the right eye */ public void translateRightEye(GL gl, GLU glu, GLUT glut) { // calculate the right vector Vector3d right = new Vector3d(); Vector3d temp1 = (Vector3d) cameraTarget.clone(); temp1.scale(-1); Vector3d temp2 = (Vector3d) cameraPosition.clone(); temp2.add(temp1); right.cross(cameraUp, temp2); right.normalize(); right.scale(eyespread / 2.); glu.gluLookAt( right.x + cameraPosition.x, right.y + cameraPosition.y, right.z + cameraPosition.z, right.x + cameraTarget.x, right.y + cameraTarget.y, right.z + cameraTarget.z, cameraUp.x, cameraUp.y, cameraUp.z); }
@Override public void display(GLAutoDrawable drawable) { gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); // desenha ou nao a bounding sphere de cada objeto if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_B)) { // tecla B BoundingVolume.isVisible = !BoundingVolume.isVisible; } // habilita ou nao fog if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_F)) { // tecla F fogEnabled = !fogEnabled; if (fogEnabled) gl.glEnable(GL2.GL_FOG); else gl.glDisable(GL2.GL_FOG); } // atualiza camera camera.update(); // atualiza objetos { Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator(); while (it.hasNext()) { SceneObject so = it.next(); // animacao da porta if (so.getName().contains("door")) { if (Collision.collide( camera.getSceneObject().getBoundingSphere(), so.getBoundingSphere())) so.setAnimating(true); else so.setAnimating(false); } so.update(); } } glu.gluLookAt( FPCamera.position.x, FPCamera.position.y, FPCamera.position.z, FPCamera.position.x + FPCamera.look.x, FPCamera.position.y + FPCamera.look.y, FPCamera.position.z + FPCamera.look.z, FPCamera.up.x, FPCamera.up.y, FPCamera.up.z); if (FPCamera.changed) { // se direcao da camera mudar FPCamera.changed = false; frustum.generate(drawable); // gera o frustum Scene.getInstance().clearVisibleObjectsList(); Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator(); while (it.hasNext()) { SceneObject so = it.next(); if (frustum.sphereInFrustum(so.getBoundingSphere())) Scene.getInstance().addVisibleObject(so); } // System.out.println("Renderable objects: "+ Scene.getInstance().getSize()); // System.out.println(FPCamera.position); } // desenha objetos { Iterator<SceneObject> it = Scene.getInstance().getVisibleObjectsIterator(); SceneObject so; while (it.hasNext()) { so = it.next(); if (so.getName().contains("lake")) { gl.glPushAttrib(GL2.GL_ENABLE_BIT); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE); so.draw(drawable); gl.glPopAttrib(); continue; } so.draw(drawable); } } // int e = gl.glGetError(); // if(e != GL.GL_NO_ERROR) { // System.err.println("Erro: "+ gl.glGetString(e)); // } // calculo do fps ++frame; long time = System.currentTimeMillis(); elapsed = time - timebase; if (elapsed > 1000) { long fps = frame * 1000 / (time - timebase); timebase = time; frame = 0; String str = "FPS: " + fps; mainFrame.setTitle(str); } // gl.glFlush(); }
/* public void makeBoundingSphere() { float x = (float) (Math.sin(this.pitch) * Math.cos(this.heading)); float y = (float) (Math.sin(this.pitch) * Math.sin(this.heading)); float z = (float) Math.cos(this.pitch); this.dirVector = new Vector(x, y, z); this.dirVector.normalize(); this.frustMiddle = VectorUtil.add(this.loc, VectorUtil.mult(this.dirVector, this.zHalf + this.nearPlane)); float viewLength = this.farPlane - this.nearPlane; float heightWidth = (float) (viewLength * Math.tan(this.viewAngle * 0.5f)); Vector farUpCorner = new Vector(heightWidth, heightWidth, viewLength); this.frustRadius = (float) Math.sqrt(Math.pow((this.frustMiddle.x - farUpCorner.x), 2) + Math.pow((this.frustMiddle.y - farUpCorner.y), 2) + Math.pow((this.frustMiddle.z - farUpCorner.z), 2)); } public void updateFrustMiddle() { float x = (float) (Math.sin(this.pitch) * Math.cos(this.heading)); float y = (float) (Math.sin(this.pitch) * Math.sin(this.heading)); float z = (float) Math.cos(this.pitch); this.dirVector = new Vector(x, y, z); this.dirVector.normalize(); this.frustMiddle = VectorUtil.add(this.loc, VectorUtil.mult(this.dirVector, this.zHalf + this.nearPlane)); } */ public void drawCam() { GLU glu = new GLU(); glu.gluLookAt( this.loc.x, this.loc.y, this.loc.z, this.ori.x, this.ori.y, this.ori.z, 0.0f, 1.0f, 0.0f); }
// display callback function public void display(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); // The usual OpenGL stuff to clear the screen and set up viewing. gl.glClearColor(.25f, .25f, .25f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(30.0f, 1.0f, .1f, 100); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(4, 4, -4, 0, 0, 0, 0, 1, 0); // Make the object rotate a bit each time the display function // is called gl.glRotatef(curTime, 0, 1, 0); // Now make sure that the vertex and fragment programs, loaded // in LoadCgPrograms() are bound. CgGL.cgGLBindProgram(vertexProgram); CgGL.cgGLBindProgram(fragmentProgram); // Bind uniform parameters to vertex shader CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelViewProj"), CgGL.CG_GL_MODELVIEW_PROJECTION_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY); CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelView"), CgGL.CG_GL_MODELVIEW_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY); CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelViewIT"), CgGL.CG_GL_MODELVIEW_MATRIX, CgGL.CG_GL_MATRIX_INVERSE_TRANSPOSE); // We can also go ahead and bind varying parameters to vertex shader // that we just want to have the same value for all vertices. The // vertex shader could be modified so that these were uniform for // better efficiency, but this gives us flexibility for the future. final float Kd[] = {.7f, .2f, .2f}, Ks[] = {.9f, .9f, .9f}; CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(vertexProgram, "diffuse"), Kd, 0); CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(vertexProgram, "specular"), Ks, 0); // Now bind uniform parameters to fragment shader final float lightPos[] = {3, 2, -3}; CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(fragmentProgram, "Plight"), lightPos, 0); final float lightColor[] = {1, 1, 1}; CgGL.cgGLSetParameter3fv( CgGL.cgGetNamedParameter(fragmentProgram, "lightColor"), lightColor, 0); CgGL.cgGLSetParameter1f(CgGL.cgGetNamedParameter(fragmentProgram, "shininess"), 40); // And finally, enable the approprate texture for fragment shader; the // texture was originally set up in LoadTextures(). CgGL.cgGLEnableTextureParameter(CgGL.cgGetNamedParameter(fragmentProgram, "diffuseMap")); // And go ahead and draw the scene geometry DrawGeometry(gl); // Disable the texture now that we're done with it. CgGL.cgGLDisableTextureParameter(CgGL.cgGetNamedParameter(fragmentProgram, "diffuseMap")); ++curTime; }
void setLookAt(GLU glu) { glu.gluLookAt(ex, ey, ez, cx, cy, cz, ux, uy, uz); }
/** * Draws the five sides of the hemicube into the provided drawable * * @param drawable * @param which * @param near * @param far * @param bCollect */ public void drawHemiCube( GLAutoDrawable drawable, int which, double near, double far, boolean bCollect) { // TODO - PART 1 - DRAW HEMICUBE! GL gl = drawable.getGL(); GLU glu = new GLU(); /* Return the face based on which parameter */ int[] vertices = scene.getObject().getFace(which); /* Find the center of the face */ /* Center of the face is the average of the three vertices */ /* Using returned list of vertex indices, find the vertices * corresponding to a particular face */ Vertex v1 = scene.getObject().vertexList.get(vertices[0]); Vertex v2 = scene.getObject().vertexList.get(vertices[1]); Vertex v3 = scene.getObject().vertexList.get(vertices[2]); /* Locate center of face */ /* Average of three vertices */ Point3d centerPoint = new Point3d(); centerPoint = new Point3d(v1.p); centerPoint.add(v2.p); centerPoint.add(v3.p); centerPoint.scale(0.33333); /* Set up camera frame */ /* --- Surface normal --- */ /* Declare points of vertex for face */ Point3d p1 = new Point3d(v1.p); Point3d p2 = new Point3d(v2.p); Point3d p3 = new Point3d(v3.p); /* Declare vector u as p2-p1 */ Point3d uVec = new Point3d(p2); uVec.sub(p1); Vector3d u = new Vector3d(uVec); /* Declare vector v as p3-p1 */ Point3d vVec = new Point3d(p3); vVec.sub(p1); Vector3d v = new Vector3d(vVec); /* Make normal vector */ Vector3d norm = new Vector3d(); norm.cross(u, v); /* --- Vectors Orthonormal to Normal --- */ Point3d vec1pt = new Point3d(p1); vec1pt.sub(p2); Vector3d vec1 = new Vector3d(vec1pt); vec1.cross(vec1, norm); // Cross surface normal with vec1 to get orthogonal vector Vector3d vec2 = new Vector3d(); vec2.cross( norm, vec1); // Cross product of surface normal with new vector vec1 to get 2nd orthogonal vector /* Make unit vectors */ norm.normalize(); vec1.normalize(); vec2.normalize(); /* Set up the five different frustums, and stitch together using viewPort */ /* Viewport to set up the view of the scene */ /* ----- FRONT FACE ----- */ gl.glPushMatrix(); gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight() / 3); /* Set up frustums for this face */ gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(-near, near, -near, near, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + norm.x, centerPoint.y + norm.y, centerPoint.z + norm.z, centerPoint.x + vec1.x, centerPoint.y + vec1.y, centerPoint.z + vec1.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ----- BOTTOM FACE ----- */ gl.glPushMatrix(); gl.glViewport(0, drawable.getHeight() / 3, drawable.getWidth(), drawable.getHeight() / 6); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(-near, near, 0, near, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + (-vec1.x), centerPoint.y + (-vec1.y), centerPoint.z + (-vec1.z), centerPoint.x + norm.x, centerPoint.y + norm.y, centerPoint.z + norm.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ----- TOP FACE ----- */ gl.glPushMatrix(); gl.glViewport( 0, (drawable.getHeight() / 3) + (drawable.getHeight() / 6), drawable.getWidth(), drawable.getHeight() / 6); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(-near, near, -near, 0, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + vec1.x, centerPoint.y + vec1.y, centerPoint.z + vec1.z, centerPoint.x - norm.x, centerPoint.y - norm.y, centerPoint.z - norm.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ----- LEFT FACE ----- */ gl.glPushMatrix(); gl.glViewport( 0, (drawable.getHeight() / 3) + 2 * (drawable.getHeight() / 6), drawable.getWidth(), drawable.getHeight() / 6); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(0, near, -near, near, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + vec2.x, centerPoint.y + vec2.y, centerPoint.z + vec2.z, centerPoint.x + vec1.x, centerPoint.y + vec1.y, centerPoint.z + vec1.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ----- RIGHT FACE ----- */ gl.glPushMatrix(); gl.glViewport( 0, (drawable.getHeight() / 3) + 3 * (drawable.getHeight() / 6), drawable.getWidth(), drawable.getHeight() / 6); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(near, 0, -near, near, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + (-vec2.x), centerPoint.y + (-vec2.y), centerPoint.z + (-vec2.z), centerPoint.x + vec1.x, centerPoint.y + vec1.y, centerPoint.z + vec1.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ---- End Frustums ---- */ // if collecting the form factors, then read back and process the data if (bCollect) { gl.glFlush(); gl.glFinish(); gl.glReadPixels( 0, 0, divisions * 2, divisions * 6, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelDataBuffer); collectData(which); } }
public void display(GLAutoDrawable gLDrawable) { key = Input.keysPressed(); double dt = (System.currentTimeMillis() - dt_timer) / 1000.0; dt_timer = System.currentTimeMillis(); // Start 3d Rendering GL gl = gLDrawable.getGL(); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); GLU glu = new GLU(); // Code to adjust camera if (input.getKey(KeyEvent.VK_UP)) z -= .5 * dt; if (input.getKey(KeyEvent.VK_DOWN)) z += .5 * dt; if (input.getKey(KeyEvent.VK_LEFT)) y -= .5 * dt; if (input.getKey(KeyEvent.VK_RIGHT)) y += .5 * dt; if (input.getKey(KeyEvent.VK_SPACE)) System.out.println(y + " " + z); glu.gluLookAt(0, y, z, 0, 0, -3, 0, 1, 0); // orangeNote.drawBar(gLDrawable, zTest); // redNote.draw(gLDrawable, -3f, -4f, zTest); // yellowNote.draw(gLDrawable, -1.5f, -4f, zTest); // blueNote.draw(gLDrawable, 0f, -4f, zTest); // greenNote.draw(gLDrawable, 1.5f, -4f, zTest); zTest += 0.005f; if (zTest > -2f) zTest = -10f; gl.glPushMatrix(); gl.glEnable(GL.GL_BLEND); // gl.glRotatef(70,1,-2,1); gl.glBegin(GL.GL_QUADS); // Draw the Board // x goes basically from -1 to 1(camera changed tho) // y stays same // board length is -z gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f); // R,G,B,A gl.glVertex3f(-3f, -4f, 0f); // x,y,z gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f); gl.glVertex3f(3f, -4f, 0f); gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f); gl.glVertex3f(3f, -4f, -10f); gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f); gl.glVertex3f(-3f, -4f, -10f); // All y values on top of the Board must have at least // 0.0001f added for some reason // Bottom bar - Orange gl.glColor4f(255 / 256f, 165 / 256f, 0 / 256f, 1f); gl.glVertex3f(-3f, -4f + .0001f, -2.15f); // close left gl.glVertex3f(3f, -4f + .0001f, -2.15f); // close right gl.glVertex3f(3f, -4f + .0001f, -2.85f); // far right gl.glVertex3f(-3f, -4f + .0001f, -2.85f); // far left // RedNote gl.glColor4f(1f, 0f, 0f, 1f); gl.glVertex3f(-3f, -4f + .001f, -2.25f); gl.glVertex3f(-1.5f, -4f + .001f, -2.25f); gl.glVertex3f(-1.5f, -4f + .001f, -2.75f); gl.glVertex3f(-3f, -4f + .001f, -2.75f); // YellowNote gl.glColor4f(1f, 1f, 0f, 1f); gl.glVertex3f(-1.5f, -4f + .001f, -2.25f); gl.glVertex3f(0f, -4f + .001f, -2.25f); gl.glVertex3f(0f, -4f + .001f, -2.75f); gl.glVertex3f(-1.5f, -4f + .001f, -2.75f); // BlueNote gl.glColor4f(0f, 0f, 1f, 1f); gl.glVertex3f(0f, -4f + .001f, -2.25f); gl.glVertex3f(1.5f, -4f + .001f, -2.25f); gl.glVertex3f(1.5f, -4f + .001f, -2.75f); gl.glVertex3f(0f, -4f + .001f, -2.75f); // GreenNote gl.glColor4f(0f, 1f, 0f, 1f); gl.glVertex3f(1.5f, -4f + .001f, -2.25f); gl.glVertex3f(3f, -4f + .001f, -2.25f); gl.glVertex3f(3f, -4f + .001f, -2.75f); gl.glVertex3f(1.5f, -4f + .001f, -2.75f); // End Bottom Bar this.renderNotes(gLDrawable, dt); ///////////////////////////////////// gl.glEnd(); gl.glDisable(GL.GL_BLEND); gl.glPopMatrix(); try { Thread.sleep(1); } catch (Exception e) { } }