/** * Copies the given matrix into a newly allocated FloatBuffer. * The order of the elements is column major (as used by OpenGL). * * @param m the matrix to copy * @return A new FloatBuffer containing the matrix in column-major form. */ public static FloatBuffer matrixToFloatBuffer(Matrix4f m) { FloatBuffer buffer = BufferUtils.createFloatBuffer(16); matrixToFloatBuffer(m, buffer); return buffer; }
private static FloatBuffer wrap(float[] data) { FloatBuffer buf = BufferUtils.createFloatBuffer(data.length); buf.put(data); buf.rewind(); return buf; }
/** * Copies the given matrix into a newly allocated FloatBuffer. * The order of the elements is column major (as used by OpenGL). * * @param m the matrix to copy * @return A new FloatBuffer containing the matrix in column-major form. */ public static FloatBuffer matrixToFloatBuffer(Matrix3f m) { FloatBuffer buffer = BufferUtils.createFloatBuffer(9); matrixToFloatBuffer(m, buffer); return buffer; }
/** * Removes the rotation and scale part of the current OpenGL matrix. * Can be used to render billboards like particles. */ public static void applyBillboardOrientation() { // Fetch the current modelview matrix final FloatBuffer model = BufferUtils.createFloatBuffer(16); GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, model); // And undo all rotations and scaling for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) { model.put(i * 4 + j, 1.0f); } else { model.put(i * 4 + j, 0.0f); } } } GL11.glLoadMatrix(model); }
public void doRender(List<Vector3f> verts, List<Vector3f> normals) { FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(verts.size() * 6); for (int i = 0; i < verts.size(); ++i) { Vector3f vert = verts.get(i); vertBuffer.put(vert.x * scale.x + translate.x); vertBuffer.put(vert.y * scale.y + translate.y); vertBuffer.put(vert.z * scale.z + translate.z); Vector3f norm = normals.get(i); vertBuffer.put(norm.x); vertBuffer.put(norm.y); vertBuffer.put(norm.z); } vertBuffer.flip(); VertexBufferObjectUtil.bufferVboData(disposalAction.vboPosNormBuffer, vertBuffer, GL15.GL_DYNAMIC_DRAW); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, disposalAction.vboPosNormBuffer); glVertexPointer(VECTOR3_SIZE, GL_FLOAT, STRIDE, 0); glNormalPointer(GL_FLOAT, STRIDE, NORMAL_OFFSET); GL11.glDrawElements(GL11.GL_TRIANGLES, data.getIndices().size(), GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
private void createVertexBuffer(List<TFloatIterator> parts, TIntList partSizes, int vertexCount, int vertexSize) { FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertexSize * vertexCount); for (int v = 0; v < vertexCount; ++v) { for (int partIndex = 0; partIndex < parts.size(); ++partIndex) { TFloatIterator part = parts.get(partIndex); for (int i = 0; i < partSizes.get(partIndex); ++i) { vertexBuffer.put(part.next()); } } } vertexBuffer.flip(); if (disposalAction.vboVertexBuffer == 0) { disposalAction.vboVertexBuffer = disposalAction.bufferPool.get(getUrn().toString()); } VertexBufferObjectUtil.bufferVboData(disposalAction.vboVertexBuffer, vertexBuffer, GL15.GL_STATIC_DRAW); vertexBuffer.flip(); }
sourceToSoundId = new IntMap<Long>(); FloatBuffer orientation = (FloatBuffer)BufferUtils.createFloatBuffer(6) .put(new float[] {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f}).flip(); alListener(AL_ORIENTATION, orientation); FloatBuffer velocity = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip(); alListener(AL_VELOCITY, velocity); FloatBuffer position = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip(); alListener(AL_POSITION, position);
sourceToSoundId = new IntMap<Long>(); FloatBuffer orientation = (FloatBuffer)BufferUtils.createFloatBuffer(6) .put(new float[] {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f}).flip(); alListener(AL_ORIENTATION, orientation); FloatBuffer velocity = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip(); alListener(AL_VELOCITY, velocity); FloatBuffer position = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip(); alListener(AL_POSITION, position);
private void createSamplesBuffer() { ssaoSamples = BufferUtils.createFloatBuffer(SSAO_KERNEL_ELEMENTS * 3); for (int i = 0; i < SSAO_KERNEL_ELEMENTS; ++i) { Vector3f vec = new Vector3f(); vec.x = randomGenerator.nextFloat(-1.0f, 1.0f); vec.y = randomGenerator.nextFloat(-1.0f, 1.0f); vec.z = randomGenerator.nextFloat(); vec.normalize(); vec.scale(randomGenerator.nextFloat(0.0f, 1.0f)); float scale = i / (float) SSAO_KERNEL_ELEMENTS; scale = TeraMath.lerp(0.25f, 1.0f, scale * scale); vec.scale(scale); ssaoSamples.put(vec.x); ssaoSamples.put(vec.y); ssaoSamples.put(vec.z); } ssaoSamples.flip(); }
sourceToSoundId = new IntMap<Long>(); FloatBuffer orientation = (FloatBuffer)BufferUtils.createFloatBuffer(6) .put(new float[] {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f}).flip(); alListenerfv(AL_ORIENTATION, orientation); FloatBuffer velocity = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip(); alListenerfv(AL_VELOCITY, velocity); FloatBuffer position = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip(); alListenerfv(AL_POSITION, position);
sourceToSoundId = new IntMap<Long>(); FloatBuffer orientation = (FloatBuffer)BufferUtils.createFloatBuffer(6) .put(new float[] {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f}).flip(); alListenerfv(AL_ORIENTATION, orientation); FloatBuffer velocity = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip(); alListenerfv(AL_VELOCITY, velocity); FloatBuffer position = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip(); alListenerfv(AL_POSITION, position);
@Override public void updateListener(Vector3f position, Quat4f orientation, Vector3f velocity) { AL10.alListener3f(AL10.AL_VELOCITY, velocity.x, velocity.y, velocity.z); OpenALException.checkState("Setting listener velocity"); Vector3f dir = orientation.rotate(Direction.FORWARD.getVector3f(), new Vector3f()); Vector3f up = orientation.rotate(Direction.UP.getVector3f(), new Vector3f()); FloatBuffer listenerOri = BufferUtils.createFloatBuffer(6).put(new float[] {dir.x, dir.y, dir.z, up.x, up.y, up.z}); listenerOri.flip(); AL10.alListener(AL10.AL_ORIENTATION, listenerOri); OpenALException.checkState("Setting listener orientation"); this.listenerPosition.set(position); AL10.alListener3f(AL10.AL_POSITION, position.x, position.y, position.z); OpenALException.checkState("Setting listener position"); }
@Override protected void doReload(SkeletalMeshData newData) { try { GameThread.synch(() -> { this.data = newData; if (disposalAction.vboPosNormBuffer == 0) { disposalAction.vboPosNormBuffer = disposalAction.bufferPool.get(getUrn().toString()); } IntBuffer indexBuffer = BufferUtils.createIntBuffer(newData.getIndices().size()); indexBuffer.put(newData.getIndices().toArray()); indexBuffer.flip(); if (disposalAction.vboIndexBuffer == 0) { disposalAction.vboIndexBuffer = disposalAction.bufferPool.get(getUrn().toString()); } VertexBufferObjectUtil.bufferVboElementData(disposalAction.vboIndexBuffer, indexBuffer, GL15.GL_STATIC_DRAW); FloatBuffer uvBuffer = BufferUtils.createFloatBuffer(newData.getUVs().size() * 2); for (Vector2f uv : newData.getUVs()) { uvBuffer.put(uv.x); uvBuffer.put(uv.y); } uvBuffer.flip(); if (disposalAction.vboUVBuffer == 0) { disposalAction.vboUVBuffer = disposalAction.bufferPool.get(getUrn().toString()); } VertexBufferObjectUtil.bufferVboData(disposalAction.vboUVBuffer, uvBuffer, GL15.GL_STATIC_DRAW); }); } catch (InterruptedException e) { logger.error("Failed to reload {}", getUrn(), e); } }
@Override public void renderOverlay() { if (entityToRegionOutlineMap.isEmpty()) { return; // skip everything if there is nothing to do to avoid possibly costly draw mode changes } glDisable(GL_DEPTH_TEST); glLineWidth(2); Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition(); FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16); FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12); material.setFloat("sunlight", 1.0f, true); material.setFloat("blockLight", 1.0f, true); material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix()); Vector3f worldPos = new Vector3f(); Vector3f worldPositionCameraSpace = new Vector3f(); worldPositionCameraSpace.sub(worldPos, cameraPosition); Matrix4f matrixCameraSpace = new Matrix4f(new Quat4f(0, 0, 0, 1), worldPositionCameraSpace, 1.0f); Matrix4f modelViewMatrix = MatrixUtils.calcModelViewMatrix(worldRenderer.getActiveCamera().getViewMatrix(), matrixCameraSpace); MatrixUtils.matrixToFloatBuffer(modelViewMatrix, tempMatrixBuffer44); material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true); MatrixUtils.matrixToFloatBuffer(MatrixUtils.calcNormalMatrix(modelViewMatrix), tempMatrixBuffer33); material.setMatrix3("normalMatrix", tempMatrixBuffer33, true); for (RegionOutlineComponent regionOutline: entityToRegionOutlineMap.values()) { material.setFloat3("colorOffset", regionOutline.color.rf(), regionOutline.color.gf(), regionOutline.color.bf(), true); drawRegionOutline(regionOutline); } glEnable(GL_DEPTH_TEST); }
Quat4f inverseWorldRot = new Quat4f(); FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16); FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12);
FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16); FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12);
Vector3f worldPos = new Vector3f(); FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16); FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12);
@Override public void renderTileEntityAt( T te, double x, double y, double z, float partialTicks, int destroyStage ) { Pair<ItemStack, Matrix4f> pair = this.f.apply( te ); if( pair != null && pair.getLeft() != null ) { GlStateManager.pushMatrix(); if( pair.getRight() != null ) { FloatBuffer matrix = BufferUtils.createFloatBuffer( 16 ); pair.getRight().store( matrix ); matrix.flip(); GlStateManager.multMatrix( matrix ); } Minecraft.getMinecraft().getRenderItem().renderItem( pair.getLeft(), TransformType.GROUND ); GlStateManager.popMatrix(); } }
@Nonnull @Override public FloatBuffer createNativeOrderedFloatBuffer(final int numFloats) { return BufferUtils.createFloatBuffer(numFloats); }
public static FloatBuffer asFloatBuffer(Matrix4 matrix4f) { FloatBuffer buffer = BufferUtils.createFloatBuffer(16); matrix4f.set(buffer.array()); return buffer; }