Skip to main content
gamedev.net
🔒 Locked

particles

Started by souldreamer Apr 19, 2004 at 1:15 PM 2 replies 400+ views
Original Post
souldreamer
souldreamer
revamping my particle engine (moving from point sprites to actual billboards. added functionality). i'm having problems computing the particle corners. i have the current position of the particle, the last position it had, and a size variable. i want to be able to stretch the particle from its last position to its current position, and it should have a width of size units. by the way: the (position-lastPos) vector should be perpendicular to the two sides it joins (the ones in black), and these sides in turn, should have a constant z coordinate (they are contained by planes that are parallel to the XY plane). here's a diagram: i tried using the (not so rigorous) linear algebra i know, and it quickly turned ugly. too many instructions to be done for each particle, each frame... could somebody help me? btw: lastPos.z isn't necessarily equal to position.z [edited by - souldreamer on April 19, 2004 2:18:27 PM]
M3d10n
M3d10n
1) Calculate the vector from oldPos to Pos, and normalize it. That''s the direction the particle moved.

2) Calculate the cross product between the direction and the camera front axis. That''ll give you a vector perpendicular to both.

3) multiply each component in cross product (X, Y, Z) by the desired particle width. That''ll give you the vector you need.

4) Now it''s easy:

p1 = lastPos + magicVector
p2 = lastPos - magicVector
p3 = pos - magicVector
p4 = pos + magicVector


souldreamer
souldreamer
my actual problem was computing that magicVector...
Lutz
Lutz
Hey!

The result of 3) M3d10n wrote is the Magic Vector.
If lastPos and position are both 2D, e.g. after transforming the 3D coords to window coords, then you compute:

// Vector lastpos -> position
d.xy = position.xy - lastPos.xy

// Rotate d by 90 degrees
magic.x = d.y
magic.y = -d.x

Normalize magic to size, well, "size"
Compute p1-p4 as M3d10n writes.

If you find a way to do everything in a vertex program, you can use the window coordinates computed there. Otherwise, you''ll have to do the transform on the CPU.

Are u doing a starfield?

Lutz

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.