# billboards in a scene graph

This topic is 3685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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

Ryan

##### 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 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()
{
glPushMatrix();
glTranslatef(nodeX,nodeY,nodeZ);

glRotatef(nodeRotX,1.0f,0.0f,0.0f);
glRotatef(nodeRotY,0.0f,1.0f,0.0f);
glRotatef(nodeRotZ,0.0f,0.0f,1.0f);

for(int i = 0; i < NUMBER_OF_ATTACHMENTS; i++)
attachments->draw();

glPopMatrix();
}

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
{
public:
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

protected:
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.*/

private:
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 on other sites
thanx for the reply but how is that helping me in getting the position of the billboard relative to origin. i still need to rotate it by the correct amount so that it faces the camera

##### 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 on other sites
indeed i need to know the absolute position for another reason as wel so il be reading up on that thnx for your time :P

##### Share on other sites
k i got it working i wrote a function that implements spherical coordination that returns the absolute coordinates for any givin node in my engine and i use that to determine the absolute coordinates of my billbord

##### Share on other sites
no problem - glad you got it working!

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633700
• Total Posts
3013428
×