Sign in to follow this  

billboards in a scene graph

Recommended Posts

hey. ive recently implemented billboards in my 3D engine and it works perfectly fine if the billboards position is relative to the origin but i what if i wanted to bind my billbord to another node in my scene graph? in order for me to know what direction the billboard must face i need to take into account the billboards position and the cameras position but if the billboard isnt relitive to the origin anymore i think i somehow also have to take into account the position and angle of the projection matrix right before i draw the billboard. Is this the right way of thinking about it? if so how can i get the current position and angle? if not how should i go about making billboards work in a scene graph? thnx [Edited by - EternityZA on November 7, 2008 2:17:26 AM]

Share this post

Link to post
Share on other sites
Hi there.

If I understand your problem right this should do it: First subtract the location of the node your locking onto from the location of your billboard. Give the billboard this new position but keep track of the old one too.

Second - treat it as if it were locked onto the origin. Calculate the direction it should face.

Finally - give the billboard back its old coordinates. Hope that helps :D


Share this post

Link to post
Share on other sites
yes that makes sense the only problem is that i dont know the possition of the node its locking onto.

for example node A is relative to origin by 20,0,50 but is also rotated around origin by 30 degrees on y axis. node B is relative to node A by 12,0,7 and is rotated by -20 degreees around node A on the y axis. and the billboard is connected to node B

how do i get the absolute position of node B?

Share this post

Link to post
Share on other sites
What you could do is setup each node to have an array of attached objects. Then you can set it up so that all attached objects are drawn after an transformations to the node have been done. For example:

void draw()


for(int i = 0; i < NUMBER_OF_ATTACHMENTS; i++)


So you need to give both your nodes and your attachable objects a method to draw. Now the location of the billiboard will need to be set to be relative to node B. Then you setup a very similar draw method for the billiboard - the push and pop matrix functions are key! Perhaps you should make an attachable class from which everything inherits? For example:

class AttachableObject
AttachableObject(Coordinate c); //If attached to something - this position will be relative to that object. Else it is relative to the origin.

void draw(); //this would be the function above essentially
void attach(AttachableObject* obj); //Add to a std::map of AttachableObjects

virtual void doDraw()=0; /*This is where the actual drawing of the object would take place. This would be called from the public draw method. By separating them - you don't have to re-code the translation and rotation part which will be the same for all attachableobjects.*/

Coordinate c;
float xrot,yrot,zrot;

While I didn't put everything in there (like the get/set methods) I think that that code gets the idea across. Tell me what you think!

Share this post

Link to post
Share on other sites
If you call the draw function of nodeA - it will be translated and rotated properly. If nodeB is attached - it will be translated and rotated relative to nodeA. If the Billiboard is attached to node B - it will be translated and rotated relative to where nodeB was translated and rotated! You don't need to know the absolute position.

If you really wanted to get the absolute position though - you'd want to look at spherical coordinate. I'm no expert on them though. You could have a pointer for attachableobjects that point to whatever they attach to. Then you could have a calculate real position that would traverse the linked nodes to the origin and from there go one at a time and calculate the real position. Again - if you want to do this spherical coordinates will be your friend.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this