Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Billboarding using LWJGL  (Read 2281 times)
0 Members and 1 Guest are viewing this topic.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Posted 2006-01-06 01:44:37 »

ok following method is a nice easy way to get Billboarding into your app, very useful for things like particle effects, player names (such as in football games) also other text in 3d mode, 2d spirites in 3d, etc.

its very simple to use when drawing your 3d objects just do a

GL11.GL_PushMatrix();
run the billboarding matrix changes
draw your stuff which needs to be bill boarded
then GL11.GL_PopMatrix(); to return back to your normal 3d matrix


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
....

GL11.glPushMatrix();

FloatBuffer buf = BufferUtils.createFloatBuffer(16 * 4);
// Get your current model view matrix from OpenGL.
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, buf);
buf.rewind();

buf.put(0, 1.0f);
buf.put(1, 0.0f);
buf.put(2, 0.0f);

buf.put(4, 0.0f);
buf.put(5, 1.0f);
buf.put(6, 0.0f);
         
buf.put(8, 0.0f);
buf.put(9, 0.0f);
buf.put(10, 1.0f);
         
GL11.glLoadMatrix(buf);

// now draw your stuff here that needs billboarding

GL11.glPopMatrix(); // restores the normal matrix

....


if you spot any errors, inefficiencies please don't hesitate to point them out  Smiley

p.s thx to UlfJack for some help on the billboarding and matrices
Offline Vorax

Senior Member


Projects: 1


System shutting down in 5..4..3...


« Reply #1 - Posted 2006-01-06 04:55:25 »

This is ok for simple cases where the sprite in front of you (near center of the screeen), but as the object moves to the sides, above or below, it will start to fail.  To do proper bill boarding you need the sprite to face the camera location, not just it's plane.  For alot of cases, this is ok though.

It can be made simpler and faster If you are going to be translating the object and don't need the current matrix translation applied (basically if you are using world coordintes), you can just do a :

1  
2  
3  
4  
5  
6  
7  
GL11.glPushMatrix();
GL11.glLoadIdentity();

GL11.glTranslatef(...);
.. drawn sprite here

GL11.glPopMatrix();


That will execute faster and have the same effect because there is no call to get the modelview matrix which is a slow operation.

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #2 - Posted 2006-01-06 11:36:17 »

This is ok for simple cases where the sprite in front of you (near center of the screeen), but as the object moves to the sides, above or below, it will start to fail.  To do proper bill boarding you need the sprite to face the camera location, not just it's plane.  For alot of cases, this is ok though.
Actually it depends what effect you're after, as they both have their drawbacks. Billboards facing the camera tend to cut into each other (as they're all at slightly different angles) which can make sorting a pain and add odd artifacts when the camera translates. But it does have the advantage of leaving billboards unchanged if the viewport rotates, as plane aligned will give you annoying popping in this case.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (55 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!