"Flare" problem

I have a scene where I have a light going around the room. I want to draw a quad “around” that point, like a particle system. The problem is: what calculations must I do so that the quad is always paralel
to the viewer? I was thinking: I always know the point where the light is. Since I use gluLookAt, the first 6 parameters of gluLookAt give me the normal vector of the plane where the quad should be draw, so I can get: ax+by+cz+d=0. The four vertex for the quad must belong on this equation. But how do I get the 4 points out of the equation?

I hope I have explained myself properly…
Please help me…

I forget the name of the post, but this was just answered a few days ago… oh well, I’ll answer it again.
Multiply world position of your particle (a flare I assume) by the view matrix. Then add offsets:

Let p = world position of light
Let m = view matrix (can be obtained with glGetFloatv( GL_MODELVIEW_MATRIX, m ) assuming m is float m[16])
Let cx = half width of particle
Let cy = half height of particle

// transform center point into camera space
Vector3 pPos = p * m;

// add offsets for corners of quads
Vector3 q1 = p + Vector3( -cx, cy, 0 );
Vector3 q2 = p + Vector3( cx, cy, 0 );
Vector3 q3 = p + Vector3( -cx, -cy, 0 );
Vector3 q4 = p + Vector3( cx, -cy, 0 );

q1-q4 now contain your quad verticies


You said:
Vector3 q1 = p + Vector3( -cx, cy, 0 );

Shouldn’t it be:
Vector3 q1 = pPos + Vector3( -cx, cy, 0 );

and another thing:
How do I do the:
Vector3 pPos = p * m;

Oops, your correct about the p is supposed to be pPos

Matrix * Vector (and vice-versa):

zfloat x = v.x * m[ 0] + v.y * m[ 1] + v.z * m[ 2] + m[ 3];
zfloat y = v.x * m[ 4] + v.y * m[ 5] + v.z * m[ 6] + m[ 7];
zfloat z = v.x * m[ 8] + v.y * m[ 9] + v.z * m[10] + m[11];
return( zVector3_t( x, y, z ) );

This is taken right outta my matrix class (operator *).

[This message has been edited by BwB (edited 09-24-2000).]

Just an idea:

Does it affect the speed, if I do any rotates/translates in my code?

E.g., is this:

adjust camera

as fast/slow as this:

adjust camera
rotate/translate scene

I think yes, because the matrix multiplication has to be done with every vertex. It doesn’t matter if I do a rotation or not. So you could do your camera movement with rotates/translates and use a camera with a standard viewing angle (-z e.g.). Then your flares could be drawn always without a matrix multiplication:

adjust camera
draw flares
rotate/translate scene
render scene

If this is really slower, than you should do the calculation like BwB posted it, but push the calculated matrix on the matrix stack. Then you can render all your flares without doing matrix multiplication for every flare.

Ok BwB, what you told me does not work!!
I don’t know what I am doing wrong… I did
everything like you told me to, but… when I turn the camera around, the flares go with me, don’t ask me why…Here’s what I’m doing:


It’s in the draw_flares function I do EVERYTHING you told me…
Just an ideia: is that the proper place to get the matriz with glGetFloatv(), I mean inside draw_flares, AFTER gluLookAt?


When you are in the function to draw the flares, you have to pop all matrices. Thats because you read out the modelview matrix and only multiply your flare vertices with this matrix:




Hope that helps.

The above post is probably the correct answer, you might need to put your setup lights function in between the push and pop though

The sequence that I use in my engine is:

zgCamera->SetProjection(); // set the projection matrix
zgCamera->TranslateWorld(); // set modelview for world to camera translation
DrawWorld(); // actually this contains the push/pop but…
zParticleMngr.Render(); // render particles

As you can see its very much the same as what Kilam Malik suggested.

I just dont use lights… yet… they dont work the way I want them to