EDIT: Just tried the demo, and this isn’t very relevant I guess…
It’s pretty easy. Most 3D games want to render 2D sprites that always face the screen since that’s how you render particles! You’ll have to project your sprite positions into view space and then draw your quad there.
- Read back (or calculate) your OpenGL modelview matrix into a Matrix4f.
- Reset the modelview matrix with glLoadIdentity() so that vertices are only transformed by the projection matrix.
For each 3D sprite:
3. Load the sprite’s position into a Vector4f.
4. Transform the sprite’s position by the modelview matrix using
Matrix4f.transform(modelviewMatrix, spritePosition, spritePosition);
5. Draw the sprite’s quad relative to the transformed sprite position. The coordinates for the top left and bottom right corners:
x1 = spritePosition.x - width/2
y1 = spritePosition.y - height/2
z1 = spritePosition.z
x2 = spritePosition.x + width/2
y2 = spritePosition.y + height/2
z2 = spritePosition.z
To understand why this works you’ll need to understand how OpenGL transforms 3D coordinates into screen coordinates. The modelview matrix takes coordinates from world space to view space. In view space the “camera” is always located at (0, 0, 0) looking towards -z (I think :P). By creating our quad here we can guarantee that it always faces the screen, but it will still be processed by the projection matrix so it also gets smaller the farther away it is, etc.