Holrin

04-24-2004, 03:37 PM

I have following problem with billboarding:

I have a bunch of objects placed on their local origins.

For facing objects to camera view i'm using following function

void doBillboarding(float *cam, float *worldPos) {

float lookAt[3]={0,0,1},objToCamProj[3],upAux[3],angleCosine;

// objToCamProj is the vector in world coordinates from the local origin to the camera

// projected in the XZ plane

objToCamProj[0] = cam[0] - worldPos[0] ;

objToCamProj[1] = 0;

objToCamProj[2] = cam[2] - worldPos[2] ;

// normalize both vectors to get the cosine directly afterwards

mathsNormalize(objToCamProj);

// easy fix to determine wether the angle is negative or positive

// for positive angles upAux will be a vector pointing in the

// positive y direction, otherwise upAux will point downwards

// effectively reversing the rotation.

mathsCrossProduct(upAux,lookAt,objToCamProj);

// compute the angle

angleCosine = mathsInnerProduct(lookAt,objToCamProj);

// perform the rotation. The if statement is used for stability reasons

// if the lookAt and v vectors are too close together then |aux| could

// be bigger than 1 due to lack of precision

if ((angleCosine < 0.99990) && (angleCosine > -0.9999))

glRotatef(acos(angleCosine)*180/3.14,upAux[0], upAux[1], upAux[2]);

}This is straight from Lighthouse3D billboarding tutorial.

When i'm drawing my billboards:

doBillboarding(Camera.Position, Object.origin);

object.draw()

glPopMatrix();

The problem is that damn billboards flying around the scene not just rotating the Y axis of their local origins.

I have tried all (modelview matrix modification etc.). What's wrong ??? (stupid thing i suppose :) )

Thanks for ANY help.

Best Regards.

I have a bunch of objects placed on their local origins.

For facing objects to camera view i'm using following function

void doBillboarding(float *cam, float *worldPos) {

float lookAt[3]={0,0,1},objToCamProj[3],upAux[3],angleCosine;

// objToCamProj is the vector in world coordinates from the local origin to the camera

// projected in the XZ plane

objToCamProj[0] = cam[0] - worldPos[0] ;

objToCamProj[1] = 0;

objToCamProj[2] = cam[2] - worldPos[2] ;

// normalize both vectors to get the cosine directly afterwards

mathsNormalize(objToCamProj);

// easy fix to determine wether the angle is negative or positive

// for positive angles upAux will be a vector pointing in the

// positive y direction, otherwise upAux will point downwards

// effectively reversing the rotation.

mathsCrossProduct(upAux,lookAt,objToCamProj);

// compute the angle

angleCosine = mathsInnerProduct(lookAt,objToCamProj);

// perform the rotation. The if statement is used for stability reasons

// if the lookAt and v vectors are too close together then |aux| could

// be bigger than 1 due to lack of precision

if ((angleCosine < 0.99990) && (angleCosine > -0.9999))

glRotatef(acos(angleCosine)*180/3.14,upAux[0], upAux[1], upAux[2]);

}This is straight from Lighthouse3D billboarding tutorial.

When i'm drawing my billboards:

doBillboarding(Camera.Position, Object.origin);

object.draw()

glPopMatrix();

The problem is that damn billboards flying around the scene not just rotating the Y axis of their local origins.

I have tried all (modelview matrix modification etc.). What's wrong ??? (stupid thing i suppose :) )

Thanks for ANY help.

Best Regards.