PDA

View Full Version : Viewer facing particles



fortikur
08-25-2004, 06:29 AM
I have a camera moving around in 3d space and a particle emitter, which sprays quads simulating water. If the camera rotates around this 'fountain' and gets on the side of the emitter I can only see the sides of the particles - which is normal.
My question is: how can I rotate, transform, etc. the particles, so they always fall in the same direction, but always face the viewer?
Shall I draw the particles (quads) perpendicular to the camera, or is there a trick with the camera?

Aeluned
08-25-2004, 07:05 AM
I can't help you out too much with it, but I think you might be interested in 'Point Sprites'.
They make for an efficient way to render particles and I think they also circumvent the problem you discussed.

check out:
http://www.ploksoftware.org/ExNihilo/pages/Tutorialpointsprite.htm

CrazyButcher
08-25-2004, 11:57 AM
if you want to get into vertexprogram extension
there is a nice sample at www.delphi3d.net (http://www.delphi3d.net)
http://www.delphi3d.net/download/vp_sprite.zip

the way I do it atm is I set camera
and grab a copy of modelview matrix

then generate particle geometry, first transform particle pos into viewspace
after that add offset vectors to it and generate 4 vertices per particle

for a quad I use as offsets
-0.5,-0.5,0 lower left
0.5,-0.5,0 lower right
0.5,0.5,0 upper right
-0.5,0.5,0 upper left

when drawing modelview matrix is set to identity, as the particles were transformed before already

the other idea is to transform those offset vectors (just rotation) and add them to the original particle pos
and use the normal modelview matrix to do viewspace transforms

or just use pointsprite ;)

Kunal Vasant Joshi
08-25-2004, 01:04 PM
Although I haven't used them I do believe that the ARB_point_sprite extensions were made specifically for this purpose. I wanted to implement something similar in my program although I wasn't dealing with particles but a single (large) quad with a texture on it. I do believe that this technique could prove to be computationally expensive for a particle system since the calculations would have to be done for almost every particle

1. Suppose initally your camera is facing down the z axis i.e along the vector (0,0,-1). and the particle quad is in the XY plane, hence facing the user.

2. Let the particle position (the center of the quad) and camera position be the vectors 'ppos' and 'cpos' respectively

3. Calculate the dot product between vectors (0,0,1) and the normalized vector joining particle and camera (ppos - cpos). This is essentially the cosine of the angle by which you want to rotate the quad. Find the angle by taking cosine inverse
call it say , theta.

4. Take the cross product between (0,0,1) and the normalized vector joining particle and camera(ppos - cpos) and let the resulting vector be 'rot' . This is the vector about which you want to rotate the quad. Now all thats left is a simple glRotatef command which is
glRotatef(theta, rot.x,rot.y,rot.z)

So basically you'd probably have to do this for each particle each frame. I think you ought to have a look at the point_sprite extension since it's probably more suited for what you're trying to do.

fortikur
08-26-2004, 11:28 PM
Thanks for the ideas.
I've already thought about using the cosine thing, which looks simple, because you just have to do one calculation and re-use it for all the particles. But I thought, that cosine (sine, etc.) calculations take up too much CPU time...
After posting my question, i even thought about the matrix copy, but I wasn't sure these can be effective enough - since it's my first particle engine.
I will try both solutions and will post a result when I'm ready, maybe for next week... got a lot of work to do...

about the point sprites - after reading the article I saw, that this could be the simplest solution, but I'm having trouble using the ARB stuff...
May the best solution win! :D

Thx again

ZbuffeR
08-27-2004, 02:29 AM
Add a single cosine computation per frame is something you won't even notice.

fortikur
08-27-2004, 05:04 AM
Couldn't wait... ;)
I just tried point_sprite. After installing the newest display driver, it worked. It's even faster than calculating the cosine of each particle (must be, because the view bends -> large FOV). Great!