i’ve been trying for a while to get billboarding to work with lwjgl, i have been stuck trying to get the code below to work, especially with the vectors, with the code below i’m almost there but a bit stuck with it, i have tried to use the vector class that comes with lwjgl but probably doing it wrong, i’ve attached the code below any help would be appreciated
thx
import org.lwjgl.opengl.GL11;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.util.vector.Vector3f;
...
public void draw(int x, int y, int z) {
// setup variables
Vector3f center = null; // this will be the center point of the quad
Vector3f right = null, up = null; // used to hold the x-right and y-up vectors
Vector3f a, b, c, d; // four corners of the quad
// set location of quad
GL11.glTranslatef(x, y, z);
GL11.glPushMatrix();
FloatBuffer buf = BufferUtils.createFloatBuffer(16 * 4);
// Get your current model view matrix from OpenGL.
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, buf);
// rewind the buffer
buf.rewind();
// build vectors from model matrix
right.set(buf.get(0), buf.get(4), buf.get(8));
up.set(buf.get(1), buf.get(5), buf.get(9));
// setup center variable, this is center point of the quad
center.set(buf.get(12), buf.get(13), buf.get(14));
// setup corners of quad to face camera
a = center - (right + up) * size;
b = center + (right - up) * size;
c = center + (right + up) * size;
d = center - (right - up) * size;
// bind the texture of image to be displayed on quad
texture.bind();
GL11.glBegin(GL11.GL_QUADS); // Build Quad
GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3fv(a); // Bottom Left
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3fv(b); // Bottom Right
GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3fv(c); // Top Right
GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3fv(d); // Top Left
GL11.glEnd(); // Done Building Quad
GL11.glPopMatrix();
}