Jump to content
  • Advertisement
Sign in to follow this  
subflood

degrees to x and y

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm trying to make a particle editor and I have a problem trying to implement the "spread" of particles. It's hard for me to explain what I mean by this so I will show you [smile]. Say I want a spread of 90 degrees: example1 Particles could be anywhere between the two upper 45 degree lines. Here is an example from another particle editor: example2

Share this post


Link to post
Share on other sites
Advertisement
Quote:

What's the question?


spread = 90.0f;

dirextion.x = ?
direction.y = ?

In other words if I have a spread of 90 degrees how do I make sure particles stay between those two upper 45 degree lines in the first picture?

Share this post


Link to post
Share on other sites
spread=pi/2; //90 degrees
angle=random_scalar()*spread;
direction.x=sin(angle);
direction.y=cos(angle);

random_scalar just being a random function spitting out a value in the range of 0-1. A cheap example of that being:
float random_scalar(){
return (float)rand()/RAND_MAX;
}

Share this post


Link to post
Share on other sites
Quote:

random_scalar just being a random function spitting out a value in the range of 0-1. A cheap example of that being:


Wouldn't that only give me answers in the 1st quadrant?

Share this post


Link to post
Share on other sites
Quote:
Original post by subflood
Quote:

random_scalar just being a random function spitting out a value in the range of 0-1. A cheap example of that being:


Wouldn't that only give me answers in the 1st quadrant?

Borrowing random_scalar() from ProPuke:
    angle = min_angle + random_scalar() * ( max_angle - min_angle );
x = cos( angle );
y = sin( angle );
or...
    angle = min_angle + random_scalar() * spread;
x = cos( angle );
y = sin( angle );
or...
    angle = center_angle + ( random_scalar() - 0.5f ) * spread;
x = cos( angle );
y = sin( angle );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!