Hello,
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
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 [i]DistObjectToCam[/i] and [i]Object_UP[/i] to get a perpendicular vector
to my camera.
PerpenVect = CrossProduct( DistObjectToCam, Object_UP ); Normalize( PerpenVect );
[b]Here is what I'm not sure to understand...[/b]
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...
glPushMatrix();
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));
glEnd();
glPopMatrix();
Thanks
Martin