private void setTransformation(Matrix4f transformation) { // Compute the modelview matrix by multiplying the camera matrix and // the transformation matrix of the object Matrix4f modelview = new Matrix4f(sceneManager.getCamera().getCameraMatrix()); modelview.mul(transformation); // Set modelview and projection matrices in shader gl.glUniformMatrix4fv( gl.glGetUniformLocation(activeShaderID, "modelview"), 1, false, transformationToFloat16(modelview), 0); gl.glUniformMatrix4fv( gl.glGetUniformLocation(activeShaderID, "projection"), 1, false, transformationToFloat16(sceneManager.getFrustum().getProjectionMatrix()), 0); int id = gl.glGetUniformLocation(activeShaderID, "camera"); if (id != -1) { Vector3f cop = sceneManager.getCamera().getCenterOfProjection(); gl.glUniform4f(id, cop.x, cop.y, cop.z, 0); } // } else // System.out.println("Could not get location of uniform variable camera"); }
/** * This method is called by the GLRenderPanel to redraw the 3D scene. The method traverses the * scene using the scene manager and passes each object to the rendering method. */ public void display(GLAutoDrawable drawable) { // Get reference to the OpenGL rendering context gl = drawable.getGL().getGL3(); gl.glPolygonMode(GL3.GL_FRONT_AND_BACK, GL3.GL_POINT); // Do some processing at the beginning of the frame beginFrame(); // Traverse scene manager and draw everything SceneManagerIterator iterator = sceneManager.iterator(); while (iterator.hasNext()) { RenderItem r = iterator.next(); if (r.getShape() != null && r.getShape() .checkBoundingSphere(sceneManager.getFrustum(), sceneManager.getCamera(), r.getT())) { draw(r); } } // Do some processing at the end of the frame endFrame(); }