degrees to x and y

Started by
4 comments, last by JohnBolton 18 years, 8 months ago
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
Advertisement
What's the question?
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?
spread=pi/2; //90 degreesangle=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;}
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
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?
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 ); 
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement