Making Skidracer's single surface particle system face camera?

Blitz3D Forums/Blitz3D Programming/Making Skidracer's single surface particle system face camera?

ashmantle(Posted 2003) [#1]
Is there a way to do this and does anyone know how?

I have just downloaded Skidracers code from the code archives, but it isn't rotated to face the camera like sprites do, so I obviously need to mod it a little ;)

Please help me with this, as I will release it free to the community when its done :)


skidracer(Posted 2003) [#2]
But they do face the camera.


Rob Farley(Posted 2003) [#3]
... only if the camera never moves.


skidracer(Posted 2003) [#4]
wo, major bug, change CameraEntity to global cam, sheesh...


skidracer(Posted 2003) [#5]
OK, try this one, mousex rotates around smoke, I am such a spoon...

http://www.blitzbasic.com/codearcs/codearcs.php?code=437

and just found 3 more typos, new version much better


sswift(Posted 2003) [#6]
TFormNormal 0,0,1, Camera, 0
Nx# = TFormedX()
Ny# = TFormedY()
Nz# = TFormedZ()

This gives you the normal of the camera view.

Multiply each component by -1, and you have a normal that points back towards the camera.

You then need to rotate each particle polygon so that it's plane is aligned to this vector, using some math I'm not going to figure out for you. :-)


A slower method which is easier to implement is to:

1. Create a pivot.
2. For each particle, position the pivot in space at it's center.
3. Point the pivot at the camera.
4. For each vertex in the particle do this:

TFormPoint Vx#-Px#, Vy#-Py#, Vz#-Pz#, Pivot, 0

TVx# = TFormedX()
TVy# = TFormedY()
TVz# = TFormedZ()

Then re-position the vertex at TVxyz.


It would be a lot faster to animate stored floats than to modify each vertex's location twice. Also do not perform this operation on vertices that you have repositioined once already. All particles must start out each frame facing towards the positive Z axis, then you do this transform to get them to face the camera. Then you start over next frame with particles facing the Z axis again. If you do not, then the particles won't face the camera, and even if you could figure out how to retransform them, they would begin to distort over time. Though particles exist for such short time spans on average that that may not be a big issue.


sswift(Posted 2003) [#7]
Well nevermind then, looks like skidracer's code can do that stuff for you after all with a bug fix. I never looked at his code.


skidracer(Posted 2003) [#8]
cool, even my matrox g400 smokes:)




(tu) ENAY(Posted 2003) [#9]
> embaraced...

Surely you mean embarrassed?
I wouldn't worry, we all make mistakes with our code.
We're only human after all.
Except for me, because I'm a tea spoon.


ashmantle(Posted 2003) [#10]
hehe... cool ;)

Thanks Skidracer, Sswift and all you others ;) Now I can continue with my project..


(tu) ENAY(Posted 2003) [#11]
> I am such a spoon...

Oi. I saw that ;)


Wiebo(Posted 2003) [#12]
I am also trying to expand Skid's code, so it will become a proper particle system with lots of possible uses.

It still needs z-ordering and a proper way to also spin the quads, etc. I have done z-ordering, now I am working on the rotation bits, finally forcing myself to actually learn proper vector math... The joys of 3d coding. ahum


big10p(Posted 2003) [#13]
Wiebo, there are a couple of ways to rotate individual quads in a single surface mesh without getting your hands dirty with the math. Firstly, add a single, unattached vertex to each quad placed at the centre (or wherever you want your point of rotation). Then you can:

1) Create a hidden, scratch pad mesh that contains a single quad then read the verts of the quad from the single surface to this scratch pad, using the centre vert to easily centre the quad in the scratch pad. Then, do the rotations and write the verts back into the single surface, again using the centre vert to make offset adjustments.

2) Create a pivot, rotate it by the amount you want your quad rotated, then use TFormPoint vertx,verty,vertz,pivot,0 to get the new vert coords for the rotated quad. Again, use the centre vert to convert the quad's vert coords to coords relative to the centre vert (if you see what I mean :)).

I've used method 1 before and found it pretty fast, TBH. So, you still don't have to learn vector math - hurrah! :)


Wiebo(Posted 2003) [#14]
big10p: Thanks, I will take a look at your suggestions!