/** Update world model matrix. */ public void updateWorldModelMatrix() { // parentMatrix * worldModelMatrix Entity parent = getParent(); if (parent != null) { Matrix4f parentMatrix = parent.getWorldModelMatrix(); parentMatrix.mul(localMatrix, worldModelMatrix); } else { // worldModelMatrix = localMatrix worldModelMatrix.set(localMatrix); } }
/** * Called at every frame update. * * @param frame Frame information */ public void update(FrameInput frame) { // Notify to components for (Component component : components.values()) { component.update(frame); } // Notify to children for (Entity child : children) { child.update(frame); } // Update local model matrix if necessary. if (localMatrixUpdateRequired) { updateLocalMatrix(); invalidateWorldModelMatrix(); localMatrixUpdateRequired = false; } // Update world model matrix if necessary. if (worldMatrixUpdateRequired) { updateWorldModelMatrix(); worldMatrixUpdateRequired = false; // Update native side values worldModelMatrix.get(matrixValues); setWorldModelMatrix(nativePointer.get(), matrixValues); } // Update opacity if necessary. if (updateOpacityRequired) { updateOpacity(); updateOpacityRequired = false; } }
private void drawPlayerIcons(final Player player, double elapsedMillis) { quadVao.bind(); playerTexture.bind(0); uiShader.use(); final FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16); Matrix4f projectionMatrix = new Matrix4f().setOrtho(0, windowWidth, windowHeight, 0, -1, 1); for (int i = 0; i < player.numLives(); i++) { final Matrix4f mat = new Matrix4f(); mat.identity(); mat.translate((float) windowWidth - 100 - i * 60f, 60, 0); mat.translate(25, 25, 0); mat.scale(25, 25, 1); Matrix4f tmp = new Matrix4f(projectionMatrix).mul(mat); tmp.get(matrixBuffer); uiShader.setUniformMatrixF("projMatrix", matrixBuffer); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6); } playerTexture.unbind(); quadVao.unbind(); }
@Override public Matrix4f getModelMatrix() { Matrix4f model = new Matrix4f(); model.translation(0.0f, 100.0f, 0.0f); return model; }
public void setPerspective(float fov, float aspect, float near, float far) { proMat.setPerspective(fov, aspect, near, far); }
public void setOrthographic( float left, float right, float bottom, float top, float near, float far) { proMat.setOrtho(left, right, bottom, top, near, far); }
public void lookAt(float x, float y, float z) { mat.lookAt(this.x, this.y, this.z, x, y, z, 0, 1, 0); }
public void dumpToShader(int viewLocation, int projectionLocation) { mat.get(buf); GL20.glUniformMatrix4fv(viewLocation, false, buf); proMat.get(buf); GL20.glUniformMatrix4fv(projectionLocation, false, buf); }
private void updateMatrix() { mat.identity(); mat.translate(-x, -y, -z); mat.rotate((float) Math.toRadians(-rx), X_AXIS); mat.rotate((float) Math.toRadians(-ry), Y_AXIS); }
/** Update local matrix. */ public void updateLocalMatrix() { localMatrix.identity(); localMatrix.translate(position); localMatrix.rotate(rotation); localMatrix.scale(scale); }