Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- For rendering the world stuff :
- Transform.setOrtho(-aspect, aspect, -1, 1, -10, 10);
- For rendering the interface stuff :
- Transform.setOrtho(0,width,0,height,-10,10);
- Set and get Ortho transformations (Identical for 2d and 3d)
- public static void setOrtho(float l, float r, float b, float t, float n, float f)
- {
- Matrix4f ortho = new Matrix4f();
- float[][] m = { {2.0f/(r-1),0,0,0},
- {0,2/(t-b),0,0},
- {0,0,-2/(f-n),0},
- {-( (r + 1)/(r-l) ),-( (t+b)/(t-b)),-((f+n)/(f-n)),1} };
- ortho.setM(m);
- Transform.ortho = ortho;
- }
- public Matrix4f getOrthoTransformation()
- {
- Matrix4f transformationMatrix = getTransformation();
- Matrix4f cameraRotation = new Matrix4f().setCamera(camera.getForward(), camera.getUp());
- Matrix4f cameraTranslation = new Matrix4f().setTranslation(-camera.getPosition().getX(), -camera.getPosition().getY(), -camera.getPosition().getZ());
- return ortho.multiply(cameraRotation.multiply(cameraTranslation.multiply(transformationMatrix)));
- }
- How I'm rendering and how I'm setting Interface sizes :
- InterfacePanel panel = new InterfacePanel();
- panel.setLocation(new Vector2f(50,50));
- panel.setBounds(new Vector2f(500,500));
- And render :
- public void draw()
- {
- this.updateShaderForThisB();
- this.getMesh().draw();
- }
- public void updateShaderForThisB()
- {
- InterfaceShader shader = InterfaceShader.getInstance();
- shader.bind();
- shader.setColour(this.getActingColour());
- shader.setLocation(this.getLocation());
- shader.setSize(this.getBounds());
- shader.setGradient(this.getShouldGradient());
- Transform t = new Transform();
- shader.setViewMatrix(t.getOrthoTransformation());
- shader.updateUniforms();
- }
- Mesh code :
- protected void generateMesh()
- {
- Vertex[] vertices = new Vertex[] {
- new Vertex(new Vector3f(location.getX(), location.getY(),zDepth)),
- new Vertex(new Vector3f(location.getX() + bounds.getX(), location.getY(),zDepth)),
- new Vertex(new Vector3f(location.getX(), location.getY() + bounds.getY(),zDepth)),
- new Vertex(new Vector3f(location.getX() + bounds.getX(), location.getY() + bounds.getY(),zDepth)),
- };
- int[] indices = new int[] { 0,1,2,
- 1,2,3
- };
- mesh = new Mesh(vertices,indices);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement