particles spreading

Started by
2 comments, last by agelito 12 years, 8 months ago
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:

float angle = random.Next(0,90);
parts.Angle_X = AngleToVector(angle)[0];
parts.Angle_Y = AngleToVector(angle)[1];



and this the way I m getting vector from angle:

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;


}



I update my particles position:


parts.Position_X += parts.Angle_X * parts.Velocity;
parts.Position_Y += parts.Angle_Y * parts.Velocity;



what I get after this is :


examplee.png


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

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

example2c.png

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?
Advertisement
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:


float vector[2] = AngleToVector(angle);



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

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:


float vector[2] = AngleToVector(angle);



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


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:
double radians = (Math.PI / 180) * angle;

and the result:

exampl3.png
Excellent! I'm glad it worked. smile.gif

This topic is closed to new replies.

Advertisement