# "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…

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)
Let cx = half width of particle
Let cy = half height of particle

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

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

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 + m;
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:

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.

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…

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.

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
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
{"ft_lang_label":"__label__en","ft_lang_prob":0.9287796,"math_prob":0.95799536,"size":603,"snap":"2020-34-2020-40","text_gpt3_token_len":151,"char_repetition_ratio":0.118530884,"word_repetition_ratio":0.0,"special_character_ratio":0.23383084,"punctuation_ratio":0.096296296,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99191874,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-14T23:43:01Z\",\"WARC-Record-ID\":\"<urn:uuid:f275ae24-e897-4999-a2d5-ce1f3c8ae557>\",\"Content-Length\":\"30173\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b00facb1-c63a-41be-87b6-2dffc787f568>\",\"WARC-Concurrent-To\":\"<urn:uuid:9caaf778-fff0-439d-95bc-1b8d2200d42d>\",\"WARC-IP-Address\":\"68.183.55.73\",\"WARC-Target-URI\":\"https://community.khronos.org/t/flare-problem/19090\",\"WARC-Payload-Digest\":\"sha1:LIN6Y5V4AOTGWURX4AVV43P5ZVGRRCZT\",\"WARC-Block-Digest\":\"sha1:KUF2QA6QR3K4LZHFNCAAX5FIQTSYE6JT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439740343.48_warc_CC-MAIN-20200814215931-20200815005931-00535.warc.gz\"}"}