Jump to content
  • Advertisement
Sign in to follow this  

Opengl 2D Particle System Problems

This topic is 4336 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

Hey all, back again with another problem :P, I havent been programming for awhile so i thought id pick up where i left off, particle systems. I couldnt find a simple particle system tutorial, so i started to make my own. It started off well enough cParticle test( 3 (size), 10 (Particles), (Pos) ); That works Fine, but if i put anymore particles above 10 into it the program will either compile and not run (or maybe for a 1/2 secound), or it does but as a blank screen or as a big red long quad ? Class.h

class cPos
{
      
      public:
             
      int xPos;
      int yPos;
      
      cPos operator + ( cPos );
      cPos operator + ( int );
           
      cPos() : xPos( 0 ), yPos( 0 )
      {}
      
      cPos( int a, int b ) : xPos(a), yPos(b)
      {}
           
      
};

class cParticle 
{
      
      cQuad Part[20];
      
      cPos origin;
      cPos end;
      
      int maxP;
      int size;
      
      public:
             
      void Init( int );
      void InitParticles();
                  
      void Display();

      cParticle( int s, int m, cPos a ) : maxP(m), size(s)
      {
               
           origin.xPos = a.xPos;
           origin.yPos = a.yPos; 
           
           end.xPos = 100;
           end.yPos = 100;
           
           InitParticles();
           
      }
};


Class.cpp
cPos cPos::operator + ( cPos c )
{
     
     int a = xPos + c.xPos;
     int b = yPos + c.yPos;
     
     return cPos(a,b);
}

cPos cPos::operator + ( int c )
{
     
     int a = xPos + c;
     int b = yPos;
     
     return cPos(a,b);
}
///////
void cParticle::Init( int i )
{

     Part.setPos( origin + (10*i) );
     Part.setSize( size );
     Part.alive = true;
             
}

void cParticle::InitParticles()
{
     
     for( int i = 0; i < maxP; i++ )
     {
          Init(i);
     }
}

void cParticle::Display()
{
     
     cPos End( 0, 0 );
     cPos End2( 200, 200 );
     cPos End3( 500, 0 );
     cPos EndAll( 100, 100 );
          
     for( int i = 0; i < maxP; i++ )
     {         
          Part.Draw();
     }
          
         
}



Any and all help is greatly apreciated ;)

Share this post


Link to post
Share on other sites
Advertisement
Well one possible error is your array of cQuads has a set size of 20. You should look into std::vector for a resizable list.

Share this post


Link to post
Share on other sites
Yea but the thing is that i actually had an array of 100 quads when i first did it, i only put 20 in as an example, and now that im try it again, when i put in 20, nothing displays? :P. Only if i have 10 ... i dont understand the difference in the array size but meh, ill switch to vectors. Thanks ;)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!