PDA

View Full Version : "Flare" problem

KRONOS
09-20-2000, 11:46 PM
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....

BwB
09-21-2000, 03:36 AM
I forget the name of the post, but this was just answered a few days ago... oh well, I'll answer it again. http://www.opengl.org/discussion_boards/ubb/smile.gif
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 );

-BwB

KRONOS
09-22-2000, 01:15 PM
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;

BwB
09-24-2000, 06:50 AM
Oops, your correct about the p is supposed to be pPos http://www.opengl.org/discussion_boards/ubb/smile.gif

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).]

Kilam Malik
09-25-2000, 03:43 AM
Just an idea:

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

E.g., is this:

render

as fast/slow as this:

rotate/translate scene
render

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:

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.

KRONOS
09-27-2000, 12:52 AM
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:

gluLookAt();
draw_world();
apply_lights();
draw_flares();
SwapBuffers();

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?

Thanks.....

Kilam Malik
09-27-2000, 05:35 AM
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:

gluLookAt();

glPush()
draw_world();
glPop();

apply_lights();
draw_flares();
SwapBuffers();

Hope that helps.

BwB
09-27-2000, 08:42 AM
The above post is probably the correct answer, you might need to put your setup lights function in between the push and pop though http://www.opengl.org/discussion_boards/ubb/smile.gif

The sequence that I use in my engine is:

zgCamera->SetProjection(); // set the projection matrix
zgCamera->TranslateWorld(); // set modelview for world to camera translation
glPushMatrix();
DrawWorld(); // actually this contains the push/pop but...
glPopMatrix();
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 http://www.opengl.org/discussion_boards/ubb/smile.gif