Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.54 KB | None | 0 0
  1.  
  2. #include "particleSystem.h"
  3.  
  4. #include <ctime> // For Clock ticks
  5. #include <cmath> // For sin/cosine functions
  6. #include <cstdlib> // Rand
  7. #include <windows.h>
  8. #include <gl/gl.h>
  9.  
  10. #include <fstream>
  11.  
  12. #define PI 3.14159265
  13.  
  14.  
  15. particleSystem::particle::particle()
  16. {
  17.   active = false;
  18. }
  19.  
  20. particleSystem::particleSystem()
  21. {
  22.   height = 128;
  23.   heightVar = 16;
  24.   radius = 256;
  25.   radiusVar = 16;
  26.   size= 64;
  27.   hz = 0.3125;
  28.   startAlpha = 1.0f;
  29.   endAlpha = -1.0f;
  30.   startRGB = 1.0;
  31.   endRGB = -1.0;
  32.   numParticles = 100;
  33.   phaseGrouping = 1.0;
  34.   startAngle = 0;
  35.   endAngle = 359;
  36.   angleGrouping = 0.0f;
  37.   std::strcpy(shaderBaseName,"textures/ps_test/pstest"); // If This isnt set dont export shaders
  38.   std::strcpy(textureName,"textures/common/caulk.tga");
  39.   zWaveform = WAVE_SIN;
  40.   xyWaveform = WAVE_SAWTOOTH;
  41.   srcBlend = GL_ONE;
  42.   dstBlend = GL_ONE;
  43.   alphagen_waveform = WAVE_CONST;
  44.   rgbgen_waveform = WAVE_SQUARE;
  45.   scale_waveform = WAVE_CONST;
  46.   emitterZvar = 0;
  47.   emitterXYVar = 0;
  48.   masterPhase = 0;
  49.   zPhase = -1;
  50.   xyPhase = 0;
  51.   alphaPhase = 0;
  52.   rgbPhase = 0;
  53.   scalePhase = 0;
  54.   alphagen_phase_option = ALPHA_MASTER;
  55.   rgbgen_phase_option = RGB_MASTER;
  56.   rotSpeed = 0;
  57.   rotSpeedVar = 0;
  58.   startStretch = 1;
  59.   endStretch = 1;
  60.   fireworkMode = false;
  61. }
  62.  
  63. int particleSystem::buildParticles()
  64. {
  65.   srand(time(NULL));
  66.   int i= numParticles;
  67.   particles[i].active = false;
  68.   while (i)
  69.   {
  70.     i--;
  71.     particles[i].active=true;
  72.    
  73.     // Phase
  74.     particles[i].phase = pow( (float) i / (float)numParticles ,phaseGrouping)  + masterPhase;
  75.    
  76.     // Angle
  77.     if ((endAngle - startAngle) == 0) particles[i].angle = startAngle;
  78.     else
  79.     {
  80.       float x = ((float)(rand() % 1000) )/ 1000;
  81.       float WF = angleGrouping*(0.5*pow( 2*(x-0.5) ,3 ) + 0.5 ) + (1-angleGrouping) * x;
  82.       particles[i].angle = (WF * abs(endAngle - startAngle)) + startAngle;
  83.     }
  84.     particles[i].aXRatio = cos((float)particles[i].angle * PI/180);
  85.     particles[i].aYRatio = sin((float)particles[i].angle * PI/180);  
  86.    
  87.     // Height
  88.    
  89.     if (heightVar > 0) particles[i].height = height - heightVar + (rand() % ((int)(2*heightVar)));
  90.     else particles[i].height = height;
  91.    
  92.     /*int hv = (int)((float)height * heightVar);
  93.     if (hv==0) particles[i].height = height;
  94.     else
  95.     {
  96.       hv = rand() % hv;
  97.       particles[i].height = height + hv - (0.5 * ((float)height*heightVar));
  98.     }*/
  99.    
  100.     particles[i].emitterXYBase = particles[i].emitterZBase = 0.0f;
  101.    
  102.     particles[i].ampz = 1.0f;
  103.     if (emitterZvar<=0) particles[i].emitterZBase = 0;
  104.     else
  105.     {
  106.       if (particles[i].height>0) particles[i].emitterZBase = ( (float)(rand() % ((int)(2*emitterZvar))) - emitterZvar) / particles[i].height;
  107.       else
  108.       {
  109.         particles[i].ampz = 0.0f;
  110.         particles[i].height = ( (float)(rand() % ((int)(2*emitterZvar))) - emitterZvar);
  111.         particles[i].emitterZBase = 1.0f;
  112.       }
  113.     }
  114.    
  115.     // Frequency
  116.     particles[i].hz = hz;
  117.    
  118.     // Radius
  119.    
  120.     if (height ==0) particles[i].radius = radius;
  121.     else particles[i].radius = radius * (particles[i].height / height);
  122.     if (radiusVar > 0) particles[i].radius = particles[i].radius - radiusVar + (rand() % ((int) (2*radiusVar)));
  123.    
  124.     if (fireworkMode)
  125.     {
  126.       // radius is a function of height
  127.       // then add radius Var
  128.       //std::ofstream oFile("firew.txt",std::ios::app);
  129.       particles[i].radius = radius;
  130.       float temp = cos( asin( (particles[i].height)/(height+heightVar) ) );
  131.       particles[i].radius *= temp;
  132.       if (radiusVar > 0) particles[i].radius = particles[i].radius - radiusVar + (rand() % ((int) (2*radiusVar)));
  133.       //oFile.close();
  134.     }
  135.    
  136.     /*int rv = (int)((float)radius * radiusVar);
  137.     if (rv>0)
  138.     {
  139.       rv = rand() % rv;
  140.       particles[i].radius = particles[i].radius + rv - (0.5* ((float)radius*radiusVar));
  141.     }*/
  142.     //particles[i].emitterXYBase = 0.0f;
  143.    
  144.    
  145.     // XY Emitter Var
  146.     particles[i].ampxy = 1.0f;
  147.     if (emitterXYVar<=0) particles[i].emitterXYBase = 0;
  148.     else
  149.     {
  150.       if (particles[i].radius>0) particles[i].emitterXYBase = ( (float)(rand() % ((int)(2*emitterXYVar))) - emitterXYVar) / particles[i].radius;
  151.       else
  152.       {
  153.         particles[i].ampxy = 0.0f;
  154.         particles[i].emitterXYBase = 1.0f;
  155.         particles[i].radius = ( (float)(rand() % ((int)(2*emitterXYVar))) - emitterXYVar);
  156.       }
  157.     }
  158.    
  159.     //std::ofstream oFile("emitterxy.txt",std::ios::app);
  160.     //oFile << i << ' ' << particles[i].radius << ' ' << particles[i].emitterXYBase << ' ' << particles[i].ampxy << ' ' << emitterXYVar << '\n';
  161.     //oFile.close();
  162.    
  163.     //Scale / stretch
  164.    
  165.     particles[i].scale_amp  = 0;
  166.     particles[i].scale_base = 1;
  167.  
  168.     if (scale_waveform == WAVE_SIN)
  169.     {
  170.       particles[i].scale_base = startStretch;
  171.       particles[i].scale_amp = endStretch;
  172.     }
  173.     if (scale_waveform == WAVE_SQUARE)
  174.     {
  175.       particles[i].scale_base = (startStretch+endStretch)/2;
  176.       particles[i].scale_amp = (startStretch - endStretch) / 2;
  177.     }
  178.     if (scale_waveform == WAVE_TRIANGLE)
  179.     {
  180.       particles[i].scale_base = startStretch;
  181.       particles[i].scale_amp = endStretch;
  182.     }
  183.     if (scale_waveform == WAVE_SAWTOOTH)
  184.     {
  185.       particles[i].scale_base = startStretch;
  186.       particles[i].scale_amp = endStretch - startStretch;
  187.     }
  188.     if (scale_waveform == WAVE_INVSAWTOOTH)
  189.     {
  190.       particles[i].scale_base = endStretch;
  191.       particles[i].scale_amp = startStretch - endStretch;
  192.     }
  193.     if (scale_waveform == WAVE_CONST)
  194.     {
  195.       particles[i].scale_base = startStretch;
  196.     }
  197.    
  198.     // Rotation
  199.    
  200.     if (rotSpeedVar == 0) particles[i].rotSpeed = rotSpeed;
  201.     else
  202.     {
  203.       particles[i].rotSpeed = rotSpeed - rotSpeedVar + ( rand() % (2*rotSpeedVar) );
  204.     }
  205.    
  206.     // RGBGEN
  207.     if (rgbgen_waveform == WAVE_SIN)
  208.     {
  209.       particles[i].rgbgen_base = startRGB;
  210.       particles[i].rgbgen_amp = endRGB;
  211.     }
  212.     if (rgbgen_waveform == WAVE_SQUARE)
  213.     {
  214.       particles[i].rgbgen_base = (startRGB+endRGB)/2;
  215.       particles[i].rgbgen_amp = (startRGB - endRGB) / 2;
  216.     }
  217.     if (rgbgen_waveform == WAVE_TRIANGLE)
  218.     {
  219.       particles[i].rgbgen_base = startRGB;
  220.       particles[i].rgbgen_amp = endRGB;
  221.     }
  222.     if (rgbgen_waveform == WAVE_SAWTOOTH)
  223.     {
  224.       particles[i].rgbgen_base = startRGB;
  225.       particles[i].rgbgen_amp = endRGB - startRGB;
  226.     }
  227.     if (rgbgen_waveform == WAVE_INVSAWTOOTH)
  228.     {
  229.       particles[i].rgbgen_base = endRGB;
  230.       particles[i].rgbgen_amp = startRGB - endRGB;
  231.     }
  232.     if (rgbgen_waveform == WAVE_CONST)
  233.     {
  234.       particles[i].rgbgen_base = startRGB;
  235.     }
  236.    
  237.     // ALPHAGEN
  238.    
  239.     if (alphagen_waveform == WAVE_SIN)
  240.     {
  241.       particles[i].alphagen_base = startAlpha;
  242.       particles[i].alphagen_amp = endAlpha;
  243.     }
  244.     if (alphagen_waveform == WAVE_SQUARE)
  245.     {
  246.       particles[i].alphagen_base = (startAlpha+endAlpha)/2;
  247.       particles[i].alphagen_amp =  (startAlpha-endAlpha)/2;
  248.     }
  249.     if (alphagen_waveform == WAVE_TRIANGLE)
  250.     {
  251.       particles[i].alphagen_base = startAlpha;
  252.       particles[i].alphagen_amp =  endAlpha;
  253.     }
  254.     if (alphagen_waveform == WAVE_SAWTOOTH)
  255.     {
  256.       particles[i].alphagen_base = startAlpha;
  257.       particles[i].alphagen_amp = endAlpha - startAlpha;
  258.     }
  259.     if (alphagen_waveform == WAVE_INVSAWTOOTH)
  260.     {
  261.       particles[i].alphagen_base = endAlpha;
  262.       particles[i].alphagen_amp = startAlpha - endAlpha;
  263.     }
  264.     if (alphagen_waveform == WAVE_CONST)
  265.     {
  266.       particles[i].alphagen_base = startAlpha;
  267.       particles[i].alphagen_amp = 0;
  268.     }
  269.   }
  270. }
  271.  
  272. particleSystem::~particleSystem()
  273. {
  274. }
  275.  
  276. float particleSystem::calcTimeN()
  277. {
  278.   // Get Ticks Since Begining of Exceqution
  279.   clock_t clockNow = clock();
  280.  
  281.   // Convert to normalised floating point number
  282.   timeN = (float) clockNow / CLOCKS_PER_SEC;
  283.  
  284.   return timeN;
  285. }
  286. void particleSystem::getPositionVector(int i, float &x, float &y, float &z)
  287. {
  288.   // Return position on particle to use in gltTanslatef()
  289.   // x/y = sawtooth wave
  290.   // z = sin wave height*sin (2PIft+phase)
  291.   // double temp; // not used in new system
  292.  
  293.   // **********************************************************
  294.   // Position Vector is DISPLACEMENT VECTOR * WAVEFORM FUNCTION
  295.   // **********************************************************
  296.  
  297.   // SAWTOOTH
  298.   // old system
  299.   //x = (int) ((double)particles[i].aXRatio * (double)particles[i].radius * modf( (double)(hz*timeN + particles[i].phase) ,&temp));
  300.   //y = (int) ((double)particles[i].aYRatio * (double)particles[i].radius * modf( (double) (hz*timeN + particles[i].phase) ,&temp));
  301.   // new waveform system
  302.   x =  ( (float)(particles[i].aXRatio * particles[i].radius) * waveform(xyWaveform, particles[i].emitterXYBase, particles[i].ampxy , particles[i].phase+xyPhase, hz, timeN )  );
  303.   y =  ( (float)(particles[i].aYRatio * particles[i].radius) * waveform(xyWaveform, particles[i].emitterXYBase, particles[i].ampxy , particles[i].phase+xyPhase, hz, timeN )  );
  304.   // SIN
  305.   //z = (int) (particles[i].height * sin( 2*PI* normalise( hz*timeN + particles[i].phase) ) );
  306.   z =  (particles[i].height * waveform(zWaveform, particles[i].emitterZBase+zPhase, particles[i].ampz, particles[i].phase/*+zPhase*/, hz, timeN));
  307.  
  308. }
  309.  
  310. inline float particleSystem::normalise(float f)
  311. {
  312.   double temp;
  313.   return modf(f,&temp);
  314. }
  315.  
  316. void particleSystem::rotateTex(float &x1,float &x2,float &x3,float &x4,float &y1,float &y2,float &y3,float &y4,float angle)
  317. {
  318.   //std::ofstream oFile("rot.txt",std::ios::out);
  319.   //oFile << x1 <<',' << y1 << "  " << x2 << ',' << y2 << "  " << x3 <<',' << y3 << "  " << x4 << ',' << y4 << "   " << angle << '\n';
  320.   float nx1,nx2,nx3,nx4,ny1,ny2,ny3,ny4;
  321.  
  322.   float ca = cos(angle*PI/180);
  323.   float sa = sin(angle*PI/180);
  324.  
  325.   nx1 = x1 * ca - y1 * sa;
  326.   ny1 = y1 * ca + x1 * sa;
  327.  
  328.   nx2 = x2 * ca - y2 * sa;
  329.   ny2 = y2 * ca + x2 * sa;
  330.  
  331.   nx3 = x3 * ca - y3 * sa;
  332.   ny3 = y3 * ca + x3 * sa;
  333.  
  334.   nx4 = x4 * ca - y4 * sa;
  335.   ny4 = y4 * ca + x4 * sa;
  336.  
  337.   //oFile << nx1 <<',' << ny1 << "  " << nx2 << ',' << ny2 << "  " << nx3 << ',' << ny3 << "  " << nx4 << ',' << ny4 << '\n';
  338.  
  339.   x1 = nx1;
  340.   x2 = nx2;
  341.   x3 = nx3;
  342.   x4 = nx4;
  343.   y1 = ny1;
  344.   y2 = ny2;
  345.   y3 = ny3;
  346.   y4 = ny4;
  347.   //oFile.close();
  348. }
  349.  
  350. void particleSystem::drawParticle(int i)
  351. {
  352.  
  353.   float aRange = endAlpha - startAlpha;
  354.   float vAlpha; // = normalise(particles[i].hz * timeN + particles[i].phase) * aRange + startAlpha;
  355.   float rgb;
  356.   float stretch;
  357.  
  358.   vAlpha = waveform(alphagen_waveform, particles[i].alphagen_base, particles[i].alphagen_amp, particles[i].phase+alphaPhase, hz, timeN);
  359.   rgb = waveform(rgbgen_waveform, particles[i].rgbgen_base, particles[i].rgbgen_amp, particles[i].phase+rgbPhase, hz, timeN);
  360.   if (scale_waveform != WAVE_CONST) stretch = waveform(scale_waveform, particles[i].scale_base,particles[i].scale_amp, particles[i].phase+scalePhase, hz , timeN);
  361.   else stretch = 1.0f;
  362.  
  363.   glBlendFunc(srcBlend,dstBlend);
  364.  
  365.   glPushMatrix();
  366.   // Stretch / Rotate Fuctionallity
  367.   glRotatef(particles[i].rotSpeed*timeN,0,0,-1);
  368.  
  369.   if (stretch <= 1) glScalef(stretch,stretch,0);
  370.   else
  371.   {
  372.     // bring in texture coords
  373.   }
  374.  
  375.   glBegin(GL_QUADS);
  376.     // use glColor4f(f,f,f,f) for rgb + alpha
  377.     glColor4f( rgb, rgb, rgb ,vAlpha);
  378.            
  379.     if (stretch > 1.0f)
  380.     {
  381.       stretch = 0.5 - ((float) 1) / (2*stretch);
  382.       glTexCoord2f(0.0+ stretch, 0.0+stretch); glVertex3f( -(size/2), -(size/2),0.0f);
  383.       glTexCoord2f(1.0-stretch, 0.0+stretch); glVertex3f( (size/2), -(size/2), 0.0f );
  384.       glTexCoord2f(1.0-stretch, 1.0-stretch); glVertex3f( (size/2),(size/2),0.0f);
  385.       glTexCoord2f(0.0+stretch, 1.0-stretch); glVertex3f( -(size/2),(size/2),0.0f);
  386.     }
  387.     else
  388.     {
  389.       glTexCoord2f(0.0, 0.0 ); glVertex3f( -(size/2), -(size/2),0.0f);
  390.       glTexCoord2f(1.0, 0.0 ); glVertex3f( (size/2), -(size/2), 0.0f );
  391.       glTexCoord2f(1.0, 1.0); glVertex3f( (size/2),(size/2),0.0f);
  392.       glTexCoord2f(0.0, 1.0); glVertex3f( -(size/2),(size/2),0.0f);
  393.     }
  394.   glEnd();
  395.   glPopMatrix();
  396. }
  397.  
  398. float particleSystem::waveform(int type, float base, float amp, float phase, float freq, float time)
  399. {  
  400.   float value;
  401.   float nom = normalise(freq*time + phase);
  402.   switch (type)
  403.   {
  404.     case WAVE_SIN:
  405.       value = base + amp * sin( 2*PI* nom );
  406.       break;
  407.      
  408.     case WAVE_SQUARE:
  409.       if ( nom < 0.5) value = base + amp;
  410.       else value = base - amp;
  411.       break;
  412.      
  413.     case WAVE_TRIANGLE:
  414.       if (nom<0.25) value = base + 4*amp*nom;
  415.       else if (nom<0.75) value = base + amp - 4*(nom-0.25)*amp;
  416.       else value = base + 4*amp*(nom-1);
  417.      
  418.       break;
  419.      
  420.     case WAVE_SAWTOOTH:
  421.       value = base + amp * nom;
  422.       break;
  423.      
  424.     case WAVE_INVSAWTOOTH:
  425.       value = base + amp - (amp * nom);
  426.       break;
  427.      
  428.     default: // WAVE CONST
  429.       value = base;
  430.       break;
  431.   }
  432.  
  433.   return value;    
  434. }
  435. /*
  436. textures/ps_test/test                             // foldername and shadername are variable later shaders have zz<name>_X
  437. {
  438.     qer_editorimage textures/null_twist/corona.tga  // Variable path
  439.     q3map_cloneshader textures/ps_test/ztest_1      // Generate baased on current number, but not if current = (numParticles -1)
  440.     surfaceparm nonsolid                            // not optional
  441.     surfaceparm trans                               // not optional
  442.     deformVertexes move 0 0 64 sin 0 1 0 1          // Deform 1 remove if (x y z) < 1 or base + amp < 1
  443.     deformVertexes move 0 64 0 sin 0 1 0.25 1       // Deform 2 remove if (x y z) < 1 or base + amp < 1
  444.     deformvertexes autosprite                       // not optional
  445.     cull disable                                    // not optiona
  446.     {
  447.         map textures/null_twist/corona.tga            // you might need clampmap later
  448.         blendfunc add                                 // user specifies both src and dest, so this line will always be full form
  449.         //rgbgen wave sin 0 1 0 1
  450.         //alphagen wave sin 0 1 0 1
  451.     }
  452. }
  453. */
  454.  
  455. bool particleSystem::buildShaderFile(char *filename)
  456. {
  457.   //std::ofstream debug("debug.txt");
  458.  
  459.   // CHecks must be done first
  460.   // like shader name must be set
  461.  
  462.   std::ofstream outFile(filename,std::ios::out);
  463.   if (outFile.is_open())
  464.   {
  465.    
  466.     time_t rawtime;
  467.     tm * timeinfo;
  468.     time( &rawtime );
  469.     timeinfo = localtime( &rawtime );
  470.    
  471.     outFile << "// Generated by Frozen Sand Particle Studio\n// " << asctime(timeinfo);
  472.     outFile << "\n\n";
  473.     char newShaderName[64];
  474.     char sepLocation;
  475.     char shader[64];
  476.     // GO
  477.     for (int i=0; i<numParticles; i++)
  478.     {
  479.       // Shader's Title
  480.       sepLocation = std::strcspn(&shaderBaseName[9],"/");
  481.       std::strncpy(newShaderName,shaderBaseName,sepLocation + 10);
  482.       newShaderName[sepLocation+10]=0; // ADD NULL-TERMINATOR
  483.       std::strcpy(shader,&shaderBaseName[sepLocation+10]);
  484.       std::strcat(newShaderName,"zz");
  485.       std::strcat(newShaderName,shader);
  486.       std::strcat(newShaderName,"_");
  487.      
  488.       if (i == 0) outFile << shaderBaseName << '\n';
  489.       else outFile << newShaderName << i << '\n';
  490.       outFile << "{\n";
  491.       //char tempStr[64];
  492.       //char imageName[64];
  493.       //char basePathLocation;
  494.       //std::strcpy(tempStr,std::strstr(textureName,"q3ut4"));
  495.       //char *strPtr=&tempStr[6];
  496.       //std::strcpy(tempStr,&tempStr[6]);
  497.       // Working on pulling qer_editorimage from image path
  498.       outFile << "\tqer_editorimage " << textureName << '\n';
  499.       if ((i+1)<numParticles) outFile << "\tq3map_cloneshader " << newShaderName << i+1 << '\n';
  500.       outFile << "\tsurfaceparm nonsolid\n\tsurfaceparm trans\n\tsurfaceparm nomarks\n\tsurfaceparm nodlight\n";
  501.       // Z axis movement (Vertical)
  502.       //Deformvertexes 0 0 p.h wave FUNC 0 1 p ps
  503.       outFile << "\tdeformvertexes move 0 0 " << particles[i].height << " ";
  504.       if (zWaveform == WAVE_SIN) outFile << "sin ";
  505.       else if (zWaveform == WAVE_SQUARE) outFile << "square ";
  506.       else if (zWaveform == WAVE_TRIANGLE) outFile << "triangle ";
  507.       else if (zWaveform == WAVE_SAWTOOTH) outFile << "sawtooth ";
  508.       else if (zWaveform == WAVE_INVSAWTOOTH) outFile << "inversesawtooth ";
  509.       outFile << particles[i].emitterZBase+zPhase << ' ' << particles[i].ampz << ' '<< particles[i].phase/*+zPhase*/ << ' ' << hz << '\n';
  510.      
  511.       // XY Plane Movement
  512.       // Deformvertexes X Y 0 wave FUNC 0 1 phase hz
  513.       outFile << "\tdeformvertexes move " << particles[i].aXRatio * particles[i].radius << ' ' << particles[i].aYRatio * particles[i].radius << " 0 ";
  514.       if (xyWaveform == WAVE_SIN) outFile << "sin ";
  515.       else if (xyWaveform == WAVE_SQUARE) outFile << "square ";
  516.       else if (xyWaveform == WAVE_TRIANGLE) outFile << "triangle ";
  517.       else if (xyWaveform == WAVE_SAWTOOTH) outFile << "sawtooth ";
  518.       else if (xyWaveform == WAVE_INVSAWTOOTH) outFile << "inversesawtooth ";
  519.       outFile << particles[i].emitterXYBase << ' ' << particles[i].ampxy << ' ' << particles[i].phase+xyPhase << " " << hz << '\n';
  520.       outFile << "\tdeformvertexes autosprite\n";
  521.      
  522.       outFile << "\tcull disable\n\t{\n\t\tclampmap " << textureName << '\n';
  523.       outFile << "\t\tblendfunc ";
  524.       if (srcBlend == GL_ONE) outFile << "GL_ONE ";
  525.       if (srcBlend == GL_ZERO) outFile << "GL_ZERO ";
  526.       if (srcBlend == GL_DST_COLOR) outFile << "GL_DST_COLOR ";
  527.       if (srcBlend == GL_ONE_MINUS_DST_COLOR) outFile << "GL_ONE_MINUS_DST_COLOR ";
  528.       if (srcBlend == GL_SRC_ALPHA) outFile << "GL_SRC_ALPHA ";
  529.       if (srcBlend == GL_ONE_MINUS_SRC_ALPHA) outFile << "GL_ONE_MINUS_SRC_ALPHA ";
  530.      
  531.       if (dstBlend == GL_ONE) outFile << "GL_ONE\n";
  532.       if (dstBlend == GL_ZERO) outFile << "GL_ZERO\n";
  533.       if (dstBlend == GL_SRC_COLOR) outFile << "GL_SRC_COLOR\n";
  534.       if (dstBlend == GL_ONE_MINUS_SRC_COLOR) outFile << "GL_ONE_MINUS_SRC_COLOR\n";
  535.       if (dstBlend == GL_SRC_ALPHA) outFile << "GL_SRC_ALPHA\n";
  536.       if (dstBlend == GL_ONE_MINUS_SRC_ALPHA) outFile << "GL_ONE_MINUS_SRC_ALPHA\n";
  537.      
  538.       //rgbgen wave FUNC b a p f
  539.       outFile << "\t\trgbgen ";
  540.       if (rgbgen_waveform == WAVE_SIN) outFile << "wave sin ";
  541.       if (rgbgen_waveform == WAVE_SQUARE) outFile << "wave square ";
  542.       if (rgbgen_waveform == WAVE_TRIANGLE) outFile << "wave triangle ";
  543.       if (rgbgen_waveform == WAVE_SAWTOOTH) outFile << "wave sawtooth ";
  544.       if (rgbgen_waveform == WAVE_INVSAWTOOTH) outFile << "wave inversesawtooth ";
  545.       if (rgbgen_waveform == WAVE_CONST)
  546.       {
  547.         outFile << "const ( " << particles[i].rgbgen_base << " " << particles[i].rgbgen_base << " " << particles[i].rgbgen_base << " )\n";
  548.       }
  549.       else
  550.       {
  551.         //base amp phase freq
  552.         outFile << particles[i].rgbgen_base << " " << particles[i].rgbgen_amp << " " << particles[i].phase+rgbPhase << " " << hz << '\n';
  553.       }
  554.      
  555.      
  556.       //alphagen
  557.       outFile << "\t\talphagen ";
  558.       if (alphagen_waveform == WAVE_SIN) outFile << "wave sin ";
  559.       if (alphagen_waveform == WAVE_SQUARE) outFile << "wave square ";
  560.       if (alphagen_waveform == WAVE_TRIANGLE) outFile << "wave triangle ";
  561.       if (alphagen_waveform == WAVE_SAWTOOTH) outFile << "wave sawtooth ";
  562.       if (alphagen_waveform == WAVE_INVSAWTOOTH) outFile << "wave inversesawtooth ";
  563.       if (alphagen_waveform == WAVE_CONST)
  564.       {
  565.         outFile << "const " << particles[i].alphagen_base << "\n" ;
  566.       }
  567.       else
  568.       {
  569.         outFile << particles[i].alphagen_base << " " << particles[i].alphagen_amp << " " << particles[i].phase+alphaPhase << " " << hz << '\n';
  570.       }
  571.      
  572.       // tcmod rotate
  573.      
  574.       if (particles[i].rotSpeed != 0) outFile << "\t\ttcMod rotate " << particles[i].rotSpeed << '\n';
  575.      
  576.       //tcmod stretch
  577.      
  578.       if (scale_waveform != WAVE_CONST)
  579.       {
  580.         outFile << "\t\ttcMod stretch ";
  581.         if (scale_waveform == WAVE_SIN) outFile << "sin ";
  582.         if (scale_waveform == WAVE_SQUARE) outFile << "square ";
  583.         if (scale_waveform == WAVE_TRIANGLE) outFile << "triangle ";
  584.         if (scale_waveform == WAVE_SAWTOOTH) outFile << "sawtooth ";
  585.         if (scale_waveform == WAVE_INVSAWTOOTH) outFile << "inversesawtooth ";
  586.         outFile << particles[i].scale_base << " " << particles[i].scale_amp << " " << particles[i].phase+scalePhase << " " << hz << '\n';
  587.       }
  588.      
  589.       outFile << "\t}\n}\n\n";
  590.      
  591.     }
  592.   }
  593.   else return false;
  594.  
  595.   outFile.close();
  596.   //debug.close();
  597.   return true;
  598. }
  599.  
  600.  
  601. float particleSystem::getSize()
  602. {
  603.   return size;
  604. }
  605.  
  606.  
  607. bool particleSystem::setSize(float s)
  608. {
  609.   if (s > 0) size = s;
  610. }
  611.  
  612. float particleSystem::getHeight()
  613. {
  614.   return height;
  615. }
  616.  
  617. bool particleSystem::setHeight(float h)
  618. {
  619.   if (h >= 0) height = h;
  620. }
  621.  
  622. int particleSystem::getHeightVar()
  623. {
  624.   return heightVar;
  625. }
  626.  
  627. bool particleSystem::setHeightVar(int h)
  628. {
  629.   heightVar = h;
  630. }
  631.  
  632. float particleSystem::getEmitterZ()
  633. {
  634.   return emitterZvar;
  635. }
  636.  
  637. bool particleSystem::setEmitterZ(float h)
  638. {
  639.   if (h >= 0) emitterZvar = h;
  640. }
  641.  
  642. float particleSystem::getFrequency()
  643. {
  644.   return hz;
  645. }
  646.  
  647. bool particleSystem::setFrequency(float h)
  648. {
  649.   if (h >= 0) hz = h;
  650. }
  651.  
  652. float particleSystem::getPhaseGrouping()
  653. {
  654.   return phaseGrouping;
  655. }
  656.  
  657. bool particleSystem::setPhaseGrouping(float h)
  658. {
  659.   if (h >= 0) phaseGrouping = h;
  660. }
  661.  
  662. float particleSystem::getMasterPhase()
  663. {
  664.   return masterPhase;
  665. }
  666.  
  667. bool particleSystem::setMasterPhase(float h)
  668. {
  669.   /*if (h >= 0)*/ masterPhase = h;
  670. }
  671.  
  672. int particleSystem::getZWaveform()
  673. {
  674.   return zWaveform;
  675. }
  676.  
  677. bool particleSystem::setZWaveform(int i)
  678. {
  679.   zWaveform = i;
  680. }
  681.  
  682. bool particleSystem::setXYWaveform(int i)
  683. {
  684.   xyWaveform = i;
  685. }
  686.  
  687. float particleSystem::getRadius()
  688. {
  689.   return radius;
  690. }
  691.  
  692. bool particleSystem::setRadius(float r)
  693. {
  694.   if(r>=0) radius = r;
  695. }
  696.  
  697. int particleSystem::getRadiusVar()
  698. {
  699.   return radiusVar;
  700. }
  701.  
  702. bool particleSystem::setRadiusVar(int r)
  703. {
  704.   radiusVar = r;
  705. }
  706.  
  707. float particleSystem::getEmitterXY()
  708. {
  709.   return emitterXYVar;
  710. }
  711.  
  712. bool particleSystem::setEmitterXY(float h)
  713. {
  714.   if (h >= 0) emitterXYVar = h;
  715. }
  716.  
  717. int particleSystem::getStartAngle()
  718. {
  719.   return startAngle;
  720. }
  721.  
  722. bool particleSystem::setStartAngle(int a) // start angle is always lower
  723. {
  724.   startAngle = a;
  725.   if (startAngle>endAngle) endAngle = startAngle;
  726. }
  727.  
  728. int particleSystem::getEndAngle()
  729. {
  730.   return endAngle;
  731. }
  732.  
  733. bool particleSystem::setEndAngle(int a)
  734. {
  735.   endAngle = a;
  736.   if (endAngle<startAngle) startAngle = endAngle;
  737. }
  738.  
  739. float particleSystem::getXYPhase()
  740. {
  741.   return xyPhase;
  742. }
  743.  
  744. bool particleSystem::setXYPhase(float p)
  745. {
  746.   xyPhase = p;
  747. }
  748.  
  749. int particleSystem::getXYWaveform()
  750. {
  751.   return xyWaveform;
  752. }
  753.  
  754. float particleSystem::getAngleGrouping()
  755. {
  756.   return angleGrouping;
  757. }
  758.  
  759. bool particleSystem::setAngleGrouping(float g)
  760. {
  761.   if ((g>=0)&&(g<=1)) angleGrouping = g;
  762. }
  763.  
  764. float particleSystem::getRGB1()
  765. {
  766.   return startRGB;
  767. }
  768.  
  769. float particleSystem::getRGB2()
  770. {
  771.   return endRGB;
  772. }
  773.  
  774. float particleSystem::particleSystem::getAlpha1()
  775. {
  776.   return startAlpha;
  777. }
  778.  
  779. float particleSystem::particleSystem::getAlpha2()
  780. {
  781.   return endAlpha;
  782. }
  783.  
  784. bool particleSystem::setRGB1(float v)
  785. {
  786.   startRGB = v;
  787. }
  788.  
  789. bool particleSystem::setRGB2(float v)
  790. {
  791.   endRGB = v;
  792. }
  793.  
  794. bool particleSystem::setAlpha1(float v)
  795. {
  796.   startAlpha = v;
  797. }
  798.  
  799. bool particleSystem::setAlpha2(float v)
  800. {
  801.   endAlpha = v;
  802. }
  803.  
  804. int particleSystem::getRGBWave()
  805. {
  806.   return rgbgen_waveform;
  807. }
  808.  
  809. int particleSystem::getAlphaWave()
  810. {
  811.   return alphagen_waveform;
  812. }
  813.  
  814. bool particleSystem::setRGBWave(int i)
  815. {
  816.   rgbgen_waveform = i;
  817. }
  818.  
  819. bool particleSystem::setAlphaWave(int i)
  820. {
  821.   alphagen_waveform = i;
  822. }
  823.  
  824. bool particleSystem::setSrcBlend(int i)
  825. {
  826.   srcBlend = i;
  827. }
  828.  
  829. bool particleSystem::setDstBlend(int i)
  830. {
  831.   dstBlend = i;
  832. }
  833.  
  834.  
  835. int particleSystem::getAlphagenPhaseOption()
  836. {
  837.   return alphagen_phase_option;
  838. }
  839.  
  840. int particleSystem::getRgbgenPhaseOption()
  841. {
  842.   return rgbgen_phase_option;
  843. }
  844.  
  845. bool particleSystem::setAlphagenPhaseOption(int i)
  846. {
  847.   alphagen_phase_option = i;
  848. }
  849.  
  850. bool particleSystem::setRgbgenPhaseOption(int i)
  851. {
  852.   rgbgen_phase_option = i;
  853. }
  854.  
  855. float particleSystem::getRGBPhase()
  856. {
  857.   return rgbPhase;
  858. }
  859.  
  860. bool particleSystem::setRGBPhase(float p)
  861. {
  862.   rgbPhase = p;
  863. }
  864.  
  865. float particleSystem::getAlphaPhase()
  866. {
  867.   return alphaPhase;
  868. }
  869.  
  870. bool particleSystem::setAlphaPhase(float p)
  871. {
  872.   alphaPhase = p;
  873. }
  874.  
  875. float particleSystem::getStretch1()
  876. {
  877.   return startStretch;
  878. }
  879.  
  880. float particleSystem::getStretch2()
  881. {
  882.   return endStretch;
  883. }
  884.  
  885. int particleSystem::getStretchWave()
  886. {
  887.   return scale_waveform;
  888. }
  889.  
  890. float particleSystem::getStretchPhase()
  891. {
  892.   return scalePhase;
  893. }
  894.  
  895. bool particleSystem::setStretch1(float s)
  896. {
  897.   startStretch = s;
  898. }
  899.  
  900. bool particleSystem::setStretch2(float s)
  901. {
  902.   endStretch = s;
  903. }
  904.  
  905. bool particleSystem::setStretchWave(int i)
  906. {
  907.   scale_waveform = i;
  908. }
  909.  
  910. bool particleSystem::setStretchPhase(float p)
  911. {
  912.  scalePhase = p;
  913. }
  914.  
  915. int particleSystem::getRotSpeed()
  916. {
  917.   return rotSpeed;
  918. }
  919.  
  920. int particleSystem::getRotSpeedVar()
  921. {
  922.   return rotSpeedVar;
  923. }
  924.  
  925. bool particleSystem::setRotSpeed(int s)
  926. {
  927.   rotSpeed = s;
  928.   return true;
  929. }
  930.  
  931. bool particleSystem::setRotSpeedVar(int s)
  932. {
  933.   rotSpeedVar = s;
  934.   return true;
  935. }
  936.  
  937. bool particleSystem::setNumParticles(int p)
  938. {
  939.   if (p>0 && p<=4096) numParticles = p;
  940. }
  941. bool particleSystem::getFireworkMode()
  942. {
  943.   return fireworkMode;
  944. }
  945.  
  946. bool particleSystem::setFireworkMode(bool mode)
  947. {
  948.   fireworkMode = mode;
  949. }
  950.  
  951.  
  952.  
  953. float particleSystem::getZPhase()
  954. {
  955.   return zPhase;
  956. }
  957.  
  958. bool  particleSystem::setZPhase(float zp)
  959. {
  960.   zPhase = zp;
  961.   return true;
  962. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement