public Matrix4f modelMatrix() { Matrix4f mat = new Matrix4f(); // make a new identitiy 4x4 matrix mat.translate(position.x, position.y, position.z); mat.rotate(rotationX, 1.0f, 0.0f, 0.0f); mat.rotate(rotationY, 0.0f, 1.0f, 0.0f); mat.rotate(rotationZ, 0.0f, 0.0f, 1.0f); mat.scale(scale, scale, scale); return mat; }
void updateProjectionMatrices() { mVpConsts = new ScriptField_VpConsts(mRS, 1, Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_CONSTANTS); ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item(); Matrix4f mvp = new Matrix4f(); mvp.loadOrtho(0, mRS.getWidth(), mRS.getHeight(), 0, -1, 1); i.MVP = mvp; mVpConsts.set(i, 0, true); }
@Override public void onSurfaceChanged(GL10 gl10, int w, int h) { GLES20.glViewport(0, 0, w, h); Matrix4f perspective = new Matrix4f(); perspective.loadPerspective(85.0f, (float)w / (float)h, 1.0f, -150.0f); if(cube != null) { cube.setProjection(perspective); } }
public void updateWithDelta(long dt) { Matrix4f camera2 = new Matrix4f(); camera2.translate(0.0f, 0.0f, -5.0f); cube.setCamera(camera2); cube.setRotationY((float)( cube.rotationY + Math.PI * dt / (ONE_SEC * 0.1f) )); cube.setRotationZ((float)( cube.rotationZ + Math.PI * dt / (ONE_SEC * 0.1f) )); cube.draw(dt); }
public void updateWithDelta(long dt) { final float secsPerMove = 2.0f * ONE_SEC; float movement = (float)(Math.sin(System.currentTimeMillis() * 2 * Math.PI / secsPerMove)); // move camera Matrix4f camera = new Matrix4f(); camera.translate(0.0f, -1.0f * movement, -15.0f); camera.rotate(360.0f * movement, 0.0f, 0.0f, 1.0f); camera.scale(movement, movement, movement); square.setCamera(camera); square.draw(dt); }
@Override public void onSurfaceChanged(GL10 gl10, int w, int h) { GLES20.glViewport(0, 0, w, h); if(square != null) { Matrix4f perspective = new Matrix4f(); perspective.loadPerspective(85.0f, (float)w / (float)h, 1.0f, -150.0f); square.setProjection(perspective); } }
public void updateWithDelta(long dt) { final float secsPerMove = 2.0f * ONE_SEC; float movement = (float)(Math.sin(System.currentTimeMillis() * 2 * Math.PI / secsPerMove)); Matrix4f camera = new Matrix4f(); camera.translate(0.0f, -1.0f * movement, 0.0f); camera.rotate(360.0f * movement, 0.0f, 0.0f, 1.0f); camera.scale(movement, movement, movement); square.setCamera(camera); square.draw(dt); }
public void setCamera(Matrix4f mat) { camera.load(mat); }
public void setProjection(Matrix4f mat) { projection.load(mat); }
public void setUniformMatrix (int location, Matrix4f matrix) { setUniformMatrix(location, matrix, false); }
public void setUniformMatrix (int location, Matrix4f matrix, boolean transpose) { if(location == -1) return; GLES20.glUniformMatrix4fv(location, 1, transpose, matrix.getArray(), 0); }