Esempio n. 1
0
  public float getHeightOfTerrain(float worldX, float worldZ) {
    float terrainX = worldX - this.x;
    float terrainZ = worldZ - this.z;
    float gridSquareSize = SIZE / ((float) heights.length - 1);
    int gridX = (int) Math.floor(terrainX / gridSquareSize);
    int gridZ = (int) Math.floor(terrainZ / gridSquareSize);
    if (gridX >= heights.length - 1 || gridZ >= heights.length - 1 || gridX < 0 || gridZ < 0) {
      return 0;
    }
    float xCoord = (terrainX % gridSquareSize) / gridSquareSize;
    float zCoord = (terrainZ % gridSquareSize) / gridSquareSize;

    float answer;
    if (xCoord <= (1 - zCoord)) {
      answer =
          Maths.barryCentric(
              new Vector3f(0, heights[gridX][gridZ], 0),
              new Vector3f(1, heights[gridX + 1][gridZ], 0),
              new Vector3f(0, heights[gridX][gridZ + 1], 1),
              new Vector2f(xCoord, zCoord));
    } else {
      answer =
          Maths.barryCentric(
              new Vector3f(1, heights[gridX + 1][gridZ], 0),
              new Vector3f(1, heights[gridX + 1][gridZ + 1], 1),
              new Vector3f(0, heights[gridX][gridZ + 1], 1),
              new Vector2f(xCoord, zCoord));
    }
    return answer;
  }
Esempio n. 2
0
 private void prepareInstance(Entity entity) {
   Matrix4f transformationMatrix =
       Maths.createTransformationMatrix(
           entity.getPosition(),
           entity.getRotX(),
           entity.getRotY(),
           entity.getRotZ(),
           entity.getScale());
   shader.loadTransformationMatrix(transformationMatrix);
   shader.loadOffset(entity.getTextureXOffset(), entity.getTextureYOffset());
 }
Esempio n. 3
0
  private void billboardRotation(Camera camera) {
    Matrix4f matrix =
        Maths.createTransformationMatrix(
            new Vector3f(
                camera.getPosition().x,
                camera.getPosition().y + DayNightCycle.getSunY(),
                camera.getPosition().z + DayNightCycle.getSunZ()),
            0,
            0,
            0,
            DayNightCycle.getSunScale());

    Vector3f objToCamProj, objToCam;
    float angleCosine;

    objToCamProj = new Vector3f(0, 0, DayNightCycle.getSunZ());
    /*lookAt = new Vector3f(0,0,1);

    try{
    	objToCamProj.normalise();
    	lookAt.normalise();
    	angleCosine = Vector3f.dot(lookAt, objToCamProj);
    	if((angleCosine < 1f) && (angleCosine > -1f)){
    		if(objToCamProj.x > 0)
    			matrix.rotate((float)(Math.acos(angleCosine)), new Vector3f(0,1,0));
    		else
    			matrix.rotate((float)(Math.acos(angleCosine)), new Vector3f(0,-1,0));
    	}
    }catch(Exception e){

    }*/

    objToCam = new Vector3f(0, -DayNightCycle.getSunY(), -DayNightCycle.getSunZ());

    try {
      objToCamProj.normalise();
      objToCam.normalise();

      angleCosine = Vector3f.dot(objToCamProj, objToCam);
      if ((angleCosine < 1) && (angleCosine > -1)) {
        if (objToCam.y < 0) matrix.rotate((float) (Math.acos(angleCosine)), new Vector3f(1, 0, 0));
        else matrix.rotate((float) (Math.acos(angleCosine)), new Vector3f(-1, 0, 0));
      }
    } catch (Exception e) {

    }

    shader.loadTransformationMatrix(matrix);
  }
Esempio n. 4
0
 public void render(List<GuiTexture> guis) {
   shader.start();
   GL30.glBindVertexArray(quad.getVaoID());
   GL20.glEnableVertexAttribArray(0);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   GL11.glDisable(GL11.GL_DEPTH_TEST);
   for (GuiTexture gui : guis) {
     GL13.glActiveTexture(GL13.GL_TEXTURE0);
     GL11.glBindTexture(GL11.GL_TEXTURE_2D, gui.getTexture());
     Matrix4f matrix = Maths.createTransformationMatrix(gui.getPosition(), gui.getScale());
     shader.loadTransformation(matrix);
     GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount());
   }
   GL11.glEnable(GL11.GL_DEPTH_TEST);
   GL11.glDisable(GL11.GL_BLEND);
   GL20.glDisableVertexAttribArray(0);
   GL30.glBindVertexArray(0);
   shader.stop();
 }
 private void loadModelMatrix(Terrain terrain) {
   Matrix4f transfomation =
       Maths.createTransformationMatrix(
           new Vector3f(terrain.getX(), 0, terrain.getZ()), 0, 0, 0, 1);
   shader.loadTransformationMatrix(transfomation);
 }