Beispiel #1
0
  /**
   * Renders the various attributes on screen
   *
   * @param size
   * @param position
   * @param rotMat
   */
  public void render(
      final Vector3<Float> size, final Vector3<Float> position, final Quaternion rotation) {
    try {
      boolean recalculate = false;
      if (!size.equals(lastSize)) {
        this.lastSize.set(size);
        recalculate = true;
      }
      if (!this.lastPosition.equals(position)) {
        this.lastPosition.set(position);
        recalculate = true;
      }
      if (!this.lastRot.equals(rotation)) {
        this.lastRot.set(rotation);
        recalculate = true;
      }
      // Only do the calculations when it has been changed
      if (recalculate) {
        Matrix4x4 mat = Matrix4x4.identityMatrix();
        mat = Matrix4x4.scale(mat, size);
        Matrix4x4 pos = Matrix4x4.identityMatrix();
        pos.translate(position);
        mat = Matrix4x4.multiply(pos, mat);
        this.lastMat.set(Matrix4x4.multiply(mat, Quaternion.quaternionToMatrix(rotation)));
      }

      glUseProgram(AssetManager.getProgram(this.program));
      glBindVertexArray(AssetManager.getMeshVao(this.mesh));

      glEnableVertexAttribArray(0);

      glUniformMatrix4fv(this.glPos, true, this.lastMat.getRawData());
      if (this.texture != -1) {
        glBindTexture(GL_TEXTURE_2D, AssetManager.getTexture(this.texture));
      }

      glDrawArrays(GL_TRIANGLES, 0, AssetManager.getMeshSize(this.mesh));
      glDisableVertexAttribArray(0);
      glBindVertexArray(0);
    } catch (AssetManager.AssetNotFoundException ex) {
      Logger.getLogger(Renderer.class.getName()).log(Level.SEVERE, null, ex);
    }
  }