Advertisement
DuskFall

Untitled

Nov 24th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. For rendering the world stuff :
  2.  
  3. Transform.setOrtho(-aspect, aspect, -1, 1, -10, 10);
  4.  
  5. For rendering the interface stuff :
  6.  
  7. Transform.setOrtho(0,width,0,height,-10,10);
  8.  
  9.  
  10. Set and get Ortho transformations (Identical for 2d and 3d)
  11. public static void setOrtho(float l, float r, float b, float t, float n, float f)
  12. {
  13. Matrix4f ortho = new Matrix4f();
  14. float[][] m = { {2.0f/(r-1),0,0,0},
  15. {0,2/(t-b),0,0},
  16. {0,0,-2/(f-n),0},
  17. {-( (r + 1)/(r-l) ),-( (t+b)/(t-b)),-((f+n)/(f-n)),1} };
  18. ortho.setM(m);
  19.  
  20. Transform.ortho = ortho;
  21. }
  22.  
  23. public Matrix4f getOrthoTransformation()
  24. {
  25. Matrix4f transformationMatrix = getTransformation();
  26.  
  27. Matrix4f cameraRotation = new Matrix4f().setCamera(camera.getForward(), camera.getUp());
  28. Matrix4f cameraTranslation = new Matrix4f().setTranslation(-camera.getPosition().getX(), -camera.getPosition().getY(), -camera.getPosition().getZ());
  29.  
  30. return ortho.multiply(cameraRotation.multiply(cameraTranslation.multiply(transformationMatrix)));
  31. }
  32.  
  33. How I'm rendering and how I'm setting Interface sizes :
  34.  
  35. InterfacePanel panel = new InterfacePanel();
  36. panel.setLocation(new Vector2f(50,50));
  37. panel.setBounds(new Vector2f(500,500));
  38.  
  39.  
  40. And render :
  41. public void draw()
  42. {
  43. this.updateShaderForThisB();
  44. this.getMesh().draw();
  45. }
  46.  
  47. public void updateShaderForThisB()
  48. {
  49. InterfaceShader shader = InterfaceShader.getInstance();
  50. shader.bind();
  51. shader.setColour(this.getActingColour());
  52. shader.setLocation(this.getLocation());
  53. shader.setSize(this.getBounds());
  54. shader.setGradient(this.getShouldGradient());
  55. Transform t = new Transform();
  56.  
  57. shader.setViewMatrix(t.getOrthoTransformation());
  58. shader.updateUniforms();
  59. }
  60.  
  61. Mesh code :
  62. protected void generateMesh()
  63. {
  64. Vertex[] vertices = new Vertex[] {
  65. new Vertex(new Vector3f(location.getX(), location.getY(),zDepth)),
  66. new Vertex(new Vector3f(location.getX() + bounds.getX(), location.getY(),zDepth)),
  67. new Vertex(new Vector3f(location.getX(), location.getY() + bounds.getY(),zDepth)),
  68. new Vertex(new Vector3f(location.getX() + bounds.getX(), location.getY() + bounds.getY(),zDepth)),
  69.  
  70. };
  71. int[] indices = new int[] { 0,1,2,
  72. 1,2,3
  73. };
  74.  
  75. mesh = new Mesh(vertices,indices);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement