View Full Version : Triangles -=BillBoarding=-

12-21-2001, 01:00 AM
I try to make a Billboarding effect for some triangles, but I'm not totaly sure of what
I need to do and espacialy why http://www.opengl.org/discussion_boards/ubb/wink.gif

Here is what I'm pretty sure :

First, I have to find the distance between my object and the camera
and normalize the reusult, so :

DistObjectToCam = CamPos - ObjectPos;
Normalize( DistObjectToCam );

Secondly, I have to set up an UP vector to my object :

Object_UP = [0.0, 1.0, 0.0 );

Then, I need to make the cross product
of DistObjectToCam and Object_UP to get a perpendicular vector
to my camera.

PerpenVect = CrossProduct( DistObjectToCam, Object_UP );
Normalize( PerpenVect );

Here is what I'm not sure to understand...

I have to get the RIGHT vector of my object (Triangle)

Object_RIGHT.x := PerpenVect.x * (WidthTriangle / 2);
Object_RIGHT.y := PerpenVect.y * (HeightTriangle / 2);
Object_RIGHT.z := PerpenVect.z * (WidthTriangle / 2);

After, I need to get the UP vector of my object :

Object_UP.x = 0.0;
Object_UP.y = 1.0 * (HeightTriangle / 2);
Object_UP.z = 0.0;

To finish, I just have to draw the triangle...
glBegin( GL_TRIANGLES );
glVertex3d( ObjectPos.x - Object_RIGHT.x + Object_UP.x),
ObjectPos.y - Object_RIGHT.y + Object_UP.y),
ObjectPos.z - Object_RIGHT.z + Object_UP.z));

glVertex3d( ObjectPos.x + (Object_RIGHT.x - Object_UP.x),
ObjectPos.y + (Object_RIGHT.y - Object_UP.y),
ObjectPos.z + (Object_RIGHT.z - Object_UP.z));

glVertex3d( ObjectPos.x + (Object_RIGHT.x + Object_UP.x),
ObjectPos.y + (Object_RIGHT.y + Object_UP.y),
ObjectPos.z + (Object_RIGHT.z + Object_UP.z));

Martin http://www.opengl.org/discussion_boards/ubb/smile.gif

12-21-2001, 01:03 AM
Oups... I forgot to specify that I need a sperical BillBording cause my camera move UP and DOWN...

If it's possible, I would like that one helps me with the way that I proceed...

A BIG BIG thanks

12-21-2001, 04:38 AM
check out this link

12-21-2001, 09:59 AM
Thanks, for the link but I already have it. The problem ist that I want to modify the triangle vertex depend the position of the camera.

In the 3D Tech tutorial, It's the camera position that is modify to rotate the object (glRotate*) face to the camera...


12-21-2001, 11:14 AM
There is no "camera" in OpenGL. How you interpret a modelview matrix rotation is really a matter of semantics. What one person calls a rotation of the camera, another could call an opposite rotation of a face.

[This message has been edited by DFrey (edited 12-21-2001).]