@Nanoha:Here is what I'm doing:
void GenerateParticle()
{
Particle.Velocity = Velocity;
Particle.Velocity += GetRandVector() * velocityVar;
normalize(Particle.Velocity);
Particle.Velocity *= ParticleSpeed;
// ...
}
From the above code I get the particles moving as a cone shape, and if I increase velocityVar the cone angle will increase
How do I set velocityVar based on certain degree so I can determine the cone angle based on degree?
This might get a bit costly for doing with particles but here goes. I am assuming your particles are travelling in some direction and you want to add a random cone like deviation for them of a specified angle. I haven't really used directx in a very long time so this will be more pseudo code-ish.
First you need to decide what direction the particle is going as if it had no deviation at all
float magnitude = magnitude(Velocity); // magnitude is effectively the particle speed
Vector direction = Velocity/magnitude; // normalizing
// Then you apply your random vector
Particle.Velocity = RandomVector(direction, 45);
// And make use of the magnitude/speed again since RandomVector will return a normalized vector
Particle.Velocity *= magnitude;
RandomVector will look something like this:
// assumes direction is normalized
Vector RandomVector(const Vector& direction, float degrees)
{
// We need an orthogonal vector, we do this by using the cross product of
// direction and 'up' but if direction is up we have a problem so check
Vector axis;
if(direction == UP) // whatever DX calls up
axis = RIGHT; // whatever DX calls right
else
axis = CrossProduct(direction, UP);
float random = Random(0, degrees);
// Apply first rotation,
Quaternion rotation = FromAxisAngle(axis, DegToRad(random));
Vector out = rotation*direction;
random = Random(-Pi, Pi);
rotation = FromAxisAngle(direction, random);
// Apply second rotation
out = rotation*out;
return out;
}
That's a fair chunk of work for each particle though. What it's doing (or what it should be doing..) is imagine you have a clock at shoulder height, you first point at the centre of that clock and then you raise your arm a random amount (the 0 to 45 degrees). You then go around the clock face a random amount either clockwise or anticlockwise. Where your arm now faces is the returned value.
It should work for whatever direction you choose, whether the original is pointing up or left or 45 degrees from the horizontal. There's probably a more efficient method similar to what I believe you were first trying but I think that will get complicated once you need particles go in other directions (it's quite easy to do if you are only going to be looking one axis aligned direction).