• Advertisement

• Popular Now

• 13
• 15
• 27
• 9
• 9
• Advertisement
• Advertisement
• Advertisement

Particle system

Recommended Posts

Im trying to do some particle like system of a disc like shape. More of a cube shape comes out though.

Vertex vertices[1500];

for (unsigned int i = 0; i < 1500; ++i)
{
vertices.Color = (const float*)&Colors::Red;
vertices.Pos.x = GenSpherePointCorrect().x;
vertices.Pos.y = GenSpherePointCorrect().y;
vertices.Pos.z = GenSpherePointCorrect().z;

}
s
GenSpherePointCorrect()
{

float r = IvSqrt(rng.RandomFloat());
float theta = kTwoPI*rng.RandomFloat();
float sintheta, costheta;
IvSinCos(theta, sintheta, costheta);

Vector3 randomPos(2.0f*r*costheta, 2.0f*r*sintheta, 0.0f);
return randomPos;
}

Share this post

Share on other sites
Advertisement

You're picking the X, Y, and Z components from different unrelated positions as each call to GenSpherePointCorrect makes a completely new position.
You need to generate a single Vector3 each loop iteration and assign its components to the vertex position.

Share this post

Share on other sites
Vertex vertices[1500];
for (unsigned int i = 0; i < 1500; ++i)
{
vertices.Color = (const float*)&Colors::Red;
vector3 vertex = GenSpherePointCorrect();
vertices.Pos.x = vertex.x;
vertices.Pos.y = vertex.y;
vertices.Pos.z = vertex.z;
}

Edited by kburkhart84

Share this post

Share on other sites

Alright KburtHard84,Zao, I seem to get it working now. Thx

Edited by terrysworkstations

Share this post

Share on other sites

It's much faster to just generate random points in the unit rectangle, and then discard all points outside the unit circle

Vertex vertices[1500];

for (unsigned int i = 0; i < 1500; ++i) {
float xpos, ypos;
while (true) {
xpos = rng.RandomFloat(); // EDIT: This should give a value in the range [-1.0, +1.0]
ypos = rng.RandomFloat();
if (xpos * xpos + ypos * ypos <= 1.0) break; // inside unit circle, done!

// else try again
}

vertices[i].Color = (const float*)&Colors::Red;
vertices[i].Pos.x = xpos;
vertices[i].Pos.y = ypos;
vertices[i].Pos.z = 0.0f;
}

cos, sin, and sqrt computations are expensive (although sqrt not so much anymore).

Edited by Alberth

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

• Advertisement