PDA

View Full Version : Billboard?



09-18-2000, 08:08 PM
Hi!

Does anyone know how to implement billboard using Visual C++ such that the object is always rotated about an axis to face the camera??

Thanks a lot!!

09-18-2000, 09:44 PM
I have some code that you may use, but it is at work..... Anyway if you could grab the book real time rendering .... thats where I got it from (real slick)

esentially, what you have to do is rotate the normal of the poly to be billboarded so it is the same as the view.....

easier said than done I know but hopefully I will find it?

09-18-2000, 10:48 PM
Hi Mr X,

I do hope that you will be able to find your code on billboarding.

Meanwhile, I will try to look for that book!!

09-18-2000, 10:51 PM
Hi Mr X,

I do hope that you will be able to find your code on billboarding.

Meanwhile, I will try to look for that book!!

09-18-2000, 11:05 PM
yes i got it

static void rotateAVectorToAnother(Vector * s, Vector * t, float mat[16])
{
Vector v;
crossproduct(s, t, &v);
float e=dotproduct(s,t);
float h=(1-e)/dotproduct(&v, &v);

mat[0]=e+h*v.coords[0]*v.coords[0];
mat[1]=h*v.coords[0]*v.coords[1]+v.coords[2];
mat[2]=h*v.coords[0]*v.coords[2]-v.coords[1];
mat[3]=0;
mat[4]=h*v.coords[0]*v.coords[1]-v.coords[2];
mat[5]=e+h*v.coords[1]*v.coords[1];
mat[6]=h*v.coords[1]*v.coords[2]+v.coords[0];
mat[7]=0;
mat[8]=h*v.coords[0]*v.coords[2]+v.coords[1];
mat[9]=h*v.coords[1]*v.coords[2]-v.coords[0];
mat[10]=e+h*v.coords[2]*v.coords[2];
mat[11]=0;
mat[12]=0;
mat[13]=0;
mat[14]=0;
mat[15]=1;
}
}


s should be the normal of your poly

t is the crossproduct of your viewdirection and your up vector then crossproducted again

i.e

Vector temp=crossproduct(view, wup)
t=crossproduct(wup, temp)

mat is the rotation matrix which rotates your poly

which you do as follows

pushmatrix()
translate to the center of your poly
rotate (by calling multmatrix(mat)
translate back (negate the first translation)
render()
popmatrix()

I defined my view as only dependant on yaw (altough I may rotate any way I wish), but I only wanted my billboards to be affected by yaw so my view direction was
(sin(3.1415*yaw/180), 0, cos(3.1415*yaw/180));

and my upVector was 0,1,0

wup is upvector....
anyway you can define your view and up as your please (just make sure that they are perpindicular)

any ?'s just post

BwB
09-19-2000, 02:36 AM
I know that looks like a wonderful method, but its a bit too complicated for my tastes http://www.opengl.org/discussion_boards/ubb/smile.gif I simple multiply the billboard's world position by the view matrix (can be attained with glGetFloatv( GL_MODEL_VIEW ); though I keep track of it myself) then add the offset of the billboard corners like such:

Let p = billBoard World Position
Let m = view Matrix
Let cx = 1/2 width of billboard
Let cy = 1/2 height of billboard

Vector3 bbPos = p * m;
Vector3 bbCorner1 = p + Vector3(-cx, cy, 0);
Vector3 bbCorner2 = p + Vector3( cx, cy, 0);
Vector3 bbCorner3 = p + Vector3(-cx, -cy, 0);
Vector3 bbCorner4 = p + Vector3( cx, -cy, 0);

This works great for me. (See my last post "New OpenGL Demo Posted" it has rain, snow, and (ugly) sparks using this method).