Hi everyone!
I have a little problem here and it might be something realy stupid but i do not understand why this is not working as i thought it would...
I am currently working on particle emitters and i am trying to implement something like a maximum angle in which a particle could be emitted. And i want to randomly choose a direction to distribute a particle. So they would all be in some sort of "emission cone" from the origin of the particle emitter.
I tried it following this idea: Random Vector (The answer from ktodisco)
This is my code for it:
Display All
the function setOrientationFromAxisAndAngle is like this:
Display All
The function follows the definition for the rotation matrix from an axis and an angle in the wikipedia .here
And it does not work. For small values for the angle the distribution seems to be more focused and for realy small values of 1.0 and lower its very focused. But it seems to be distributed everywhere from 5.0 and up. Nothing i could work with as it is not determined what happens when. And i can not figure out what i am doing wrong. So if someone could take a look at that code and maybe point out why i am stupid i would be happy
Thank you!
I have a little problem here and it might be something realy stupid but i do not understand why this is not working as i thought it would...
I am currently working on particle emitters and i am trying to implement something like a maximum angle in which a particle could be emitted. And i want to randomly choose a direction to distribute a particle. So they would all be in some sort of "emission cone" from the origin of the particle emitter.
I tried it following this idea: Random Vector (The answer from ktodisco)
This is my code for it:
Source Code
- randomVector.setX(float((rand() % 2000) / 1000.0) - 1.0);
- randomVector.setY(float((rand() % 2000) / 1000.0) - 1.0);
- randomVector.setZ(float((rand() % 2000) / 1000.0) - 1.0);
- randomVector.normalize();
- projectedVector = randomVector - ( emitterDirection * ( emitterDirection * randomVector ) );
- randomAngle = float(rand() % int(open * 1000.0)) / 1000.0;
- rotation.setOrientationFromAxisAndAngle(randomAngle, projectedVector);
- dirVector = emitterDirection;
- dirVector = rotation.transform(dirVector);
- dirVector.normalize();
- emittedParticle->setVelocity(dirVector * 10.0);
the function setOrientationFromAxisAndAngle is like this:
Source Code
- void setOrientationFromAxisAndAngle (const float angle, const cge::Vector3D axis) {
- float cosA = cos(angle);
- float sinA = sin(angle);
- float ux = axis.x();
- float uy = axis.y();
- float uz = axis.z();
- data[0] = cosA + ( ux * ux * ( 1 - cosA ) );
- data[1] = (ux * uy * ( 1 - cosA )) - (uz * sinA);
- data[2] = (ux * uz * (1 - cosA)) + (uy * sinA);
- data[3] = (uy * ux * ( 1 - cosA )) + (uz * sinA);
- data[4] = cosA + ( uy * uy * ( 1 - cosA ) );
- data[5] = (uy * uz * ( 1 - cosA )) - (ux * sinA);
- data[6] = (uz * ux * ( 1 - cosA )) - (uy * sinA);
- data[7] = (uz * uy * ( 1 - cosA )) + (ux * sinA);
- data[8] = cosA + ( uz * uz * ( 1 - cosA ) );
- }
The function follows the definition for the rotation matrix from an axis and an angle in the wikipedia .here
And it does not work. For small values for the angle the distribution seems to be more focused and for realy small values of 1.0 and lower its very focused. But it seems to be distributed everywhere from 5.0 and up. Nothing i could work with as it is not determined what happens when. And i can not figure out what i am doing wrong. So if someone could take a look at that code and maybe point out why i am stupid i would be happy
Thank you!