Sign in to follow this  
Min0

particles spreading

Recommended Posts

Min0    106
I am building a particle system and my current problem is with spread angle.

I'm not using Vectors, instead I have 2 coordinates.

In initialization phase I m doing:
[code]
float angle = random.Next(0,90);
parts[i].Angle_X = AngleToVector(angle)[0];
parts[i].Angle_Y = AngleToVector(angle)[1];
[/code]


and this the way I m getting vector from angle:

[code]private float[] AngleToVector(float angle)
{
//vector[0] = X;
//vector[1] = Y;
float[] vector = new float[2];
vector[0] = (float)Math.Cos(angle);
vector[1] = (float)Math.Sin(angle);
return vector;


}
[/code]


I update my particles position:

[code]
parts[i].Position_X += parts[i].Angle_X * parts[i].Velocity;
parts[i].Position_Y += parts[i].Angle_Y * parts[i].Velocity;[/code]


what I get after this is :


[url="http://imageshack.us/photo/my-images/825/examplee.png/"][img]http://img825.imageshack.us/img825/6382/examplee.png[/img][/url]


particles are spread not from 0 till 90 but all over the screen.

When I m using random.nextDouble() I m getting spread angle:

[url="http://imageshack.us/photo/my-images/829/example2c.png/"][img]http://img829.imageshack.us/img829/1968/example2c.png[/img][/url]

How can I control the angle, so when angle is from 0 to 90 it would be upper right square, from 90 to 180 - upper left and so on?

Share this post


Link to post
Share on other sites
agelito    102
You need to supply Sin and Cos with an angle in radians. I think you can do MathHelper.ToRadians(float degree) in XNA.

Edit:

And you probably want to do:

[code]
float vector[2] = AngleToVector(angle);
[/code]


Instead of calling AngleToVector() twice. Not sure if the compiler optimize the duplicate call somehow tho.

Share this post


Link to post
Share on other sites
Min0    106
[quote name='agelito' timestamp='1313674461' post='4850753']
You need to supply Sin and Cos with an angle in radians. I think you can do MathHelper.ToRadians(float degree) in XNA.

Edit:

And you probably want to do:

[code]
float vector[2] = AngleToVector(angle);
[/code]


Instead of calling AngleToVector() twice. Not sure if the compiler optimize the duplicate call somehow tho.
[/quote]

It's perfect!
exactly what I wanted. Solution was using radians 8-)
Oh, and calling twice AngleToVector() didn't matter, it gave me the same results doing both ways.

p.s. I m suppose to build this without using XNA so to get radians I used:
[code]double radians = (Math.PI / 180) * angle;[/code]

and the result:

[url="http://imageshack.us/photo/my-images/692/exampl3.png/"][img]http://img692.imageshack.us/img692/4964/exampl3.png[/img][/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this