Jump to content
  • Advertisement
Sign in to follow this  
terrysworkstations

Particle system

This topic is 421 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

 

Untitled.png

 

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


Link to 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


Link to 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


Link to 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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!