Skip to main content
GameDev.net gamedev.net
🔒 Locked

particle system problems

Started by Gecko Mar 3, 2000 at 12:37 PM 5 replies 950+ views
Original Post
Gecko
Gecko
i''m working on a particle system right now and am having some trouble with the latest part. i''m trying to make the particles always have acceleration towards the cursor position. i''m sure you''ve all seen those little java apps on the net where the particles follow your cursor around and kind of orbit it. i''d appreciate some help
_________________Gecko___ Gecko Design

_________________Gecko___Gecko Design
Novalis
Novalis
Sure thing, It''s easy...

void GetAcceleration(whatever *particle, whatever *mouse, Vector *accel)
{
/* Get the vector from the particle to the mouse. */
VectorSubtract(mouse->origin, particle->origin, accel);

/* Normalize the above vector (ie make it a 1 unit long vector). */
VectorNormalize(accel);

/* Now scale the vector to your rate of acceleration. */
VectorScale(accel, 10.0);
}

Answer your question? I can provide more details if you want... I''m not sure how much help you need
If a man is talking in the forest, and there is no woman there to hear him, is he still wrong?
Gecko
Gecko
Ah, thanks!
where can i find implementation of those functions?


_________________Gecko___
Gecko Design

_________________Gecko___Gecko Design
Spellbound
Spellbound
You have to make them yourself.

Or you can use D3DX
Gecko
Gecko
yes i know i have to make them myself. my question was HOW do i make them. actually the only one i need help with is VectorNormalize.


_________________Gecko___
Gecko Design

_________________Gecko___Gecko Design
chippydip
chippydip
To normalize a vector, all you have to do is divide by its length. For example, if your vector

v = (x, y)

then the length is just

/v/ = sqrt(x^2 + y^2)

thus the normalized vector will be:

(x, y)//v/ = (x//v/, y//v/)

Simple... hope that helps

(There''s some room for optimization in the math... especially in the sqrt() function which could probably just be aproximated with exceptable result.)
chippydip
chippydip
Woah! most of those slashes are supposed to be vertical bars ''/'' I wonder why that happend... Oh, well... they are supposed to be the absolute value (ie, the normalized value) of the v vector.

Topic Locked

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

Sign in to reply to this topic.