Beispiel #1
0
void Chassis::calculateForces(double dt) {
    if (wheels.size() > 0) {
        distributeWeigth();
        setWheelsSpeed();
        setWheelsReaction();
        distributeTorque();
    }
    sumForces(dt);
}
void Simulation::runOneIteration(sf::RenderWindow &window, sf::Time &elapsed, double gravConst)
{
	eventHandler(window);
	collisionResolution();		//Each of these functions modifies the members of planetList in a specific way.
	sumForces(gravConst);
	update(elapsed);

	drawToWindow(window);
}
void timeStep(int step) {
   // animation code goes here
   // This function is called for each frame of animation
   double t = (double) (frame - startFrame) / (endFrame - startFrame);
   for (int i=0; i<NUM_PARTICLES; i++) 
	{
	   if (pos[i][1] <= -20 || pos[i][1] >= 16.5 || pos[i][0] <= -4 || pos[i][0] >= 5)
	   {
			  mass[i] = 1.0;
		      sizes[i] = (((float)rand()/RAND_MAX))/3;
			  maxsizes[i] = sizes[i] + .3;

			  pos[i][0] = 0.0;
			  pos[i][1] = 0.0;
			  pos[i][2] = 0.0;
		   
			  
			  vel[i][2] = 0.0;

			  if (sizes[i] > .2)
			  {
				vel[i][0] = ((((float)rand()/RAND_MAX)*2)-1)*3 + 3;
				vel[i][1] = ((((float)rand()/RAND_MAX)*2))*15 + 6;
			  }
			  else if (sizes[i] > .1)
			  {
				vel[i][0] = ((((float)rand()/RAND_MAX)*2)-1)*2 + 2;
				vel[i][1] = ((((float)rand()/RAND_MAX)*2))*15 + 4;
			  }
			  else
			  {
				vel[i][0] = ((((float)rand()/RAND_MAX)*2)-1)*1;
				vel[i][1] = ((((float)rand()/RAND_MAX)*2))*5 + 2;
			  }
		      
			  acc[i][0] = 0.0;
			  acc[i][1] = 0.0;
			  acc[i][2] = 0.0;
		      
			  force[i][0] = 0.0;
			  force[i][1] = 0.0;
			  force[i][2] = 0.0;

			  colors[i][0] = 0.0;
			  colors[i][1] = (rand()%100)*.01 - .5;
			  colors[i][2] = (rand()%100)*.01 + .5;
	   }
   }
   for (int j=0; j<NUM_PARTICLES; j++) 
   {
	   if (sizes[j] <= maxsizes[j])
		{
			sizes[j] += .02;
		}
   }
   // do the particle system stuff
   sumForces();
   EulerIntegrate(t);
   if (frame == endFrame) increment = -1;
   else if (frame == startFrame) increment = 1;
    
   frame = frame + increment;

   display();

   glutTimerFunc(10,timeStep, 0);

}
void timeStep(int step) {
   // animation code goes here
   
   // This function is called for each frame of animation
   double t = (double) (frame - startFrame) / (endFrame - startFrame);
	//translate player 2
     if(keys[0]==true)
     {
		  if (lockflag2 == 0 && playerflag == true)
		  {
          t2trans[0] -= 0.3;
          if(t2trans[0] < 4)
          {
               t2trans[0] += 0.3;
          }
		  }
     }
     if(keys[1] == true)
     {
		  if (lockflag2 == 0 && playerflag == true)
		  {
          t2trans[0]+= 0.3;
          if(t2trans[0] > 18)
          {
               t2trans[0] -= 0.3;
          }
		  }
	  }
	  //rotate player 2
	  if(keys[2] == true)
     {
		  if (lockflag2 == 0 && playerflag == true)
		  {
          t2rotate -= 2;
			 ang2 += 2;
			 //print player 2's angle
			 printf("\b");//backspaces on char
			 printf("\r");//return to beginning of line
			 printf("%d", ang2);
          if(t2rotate < -108)
          {
               t2rotate += 2;
					ang2 -= 2;
          }
		  }
     }
	  if(keys[3]==true)
     {
		  if (lockflag2 == 0 && playerflag == true)
		  {
          t2rotate += 2;
			 ang2 -= 2;
			 //print player 2's angle
			 printf("\b");//backspaces on char
			 printf("\r");//return to beginning of line
			 printf("%d", ang2);
          if(t2rotate > -24)
          {
               t2rotate -= 2;
					ang2 += 2;
          }
		  }
     }
	  //translate player 1
	  if(keys[4]==true)
     {
		  if (lockflag == 0 && playerflag == false)
		  {
          t1trans[0] -= 0.3;
          if(t1trans[0] < -18)
          {
               t1trans[0] +=0.3;
          }
		  }
     }
     if(keys[5] == true)
     {
		  if (lockflag == 0 && playerflag == false)
		  {
          t1trans[0] += 0.3;
          if(t1trans[0] > -4)
          {
               t1trans[0] -=0.3;
          }
		  }
     }
	  //rotate player 1
	  if(keys[6] == true)
     {
		  if (lockflag == 0 && playerflag == false)
		  {
          t1rotate += 1;
			 ang1 += 1;
			 //print player 1's angle
			 printf("\b");//backspaces on char
			 printf("\r");//return to beginning of line
			 printf("%d", ang1);
          if(t1rotate > 228)
          {
               t1rotate -= 1;
					ang1 -= 1;
          }
		  }
     }
	  if(keys[7]==true)
     {
		  if (lockflag == 0 && playerflag == false)
		  {
          t1rotate -= 1;
			 ang1 -= 1;
			 //print player 1's angle
			 printf("\b");//backspaces on char
			 printf("\r");//return to beginning of line
			 printf("%d", ang1);
          if(t1rotate < 140)
          {
               t1rotate += 1;
					ang1 += 1;
          }
		  }
     }
   if (keys[8] == true)
   {
		if (lockflag == 0 && playerflag == false)
		{
			//powerct += 1;
			if (tcount-initpow >= .5)
			{
					 //powerct = 100;
					 endpow = .5;
			}
			else
			{
				//print player 1's power
				printf("\b");//backspaces on char
				printf("\r");//return to beginning of line
				//printf("%d", powerct);
				printf("%.0f", (tcount-initpow)*200);
			}
		}
   }
   if (keys[9] == true)
   {
		if (lockflag2 == 0 && playerflag == true)
		{
			//powerct2 += 1;
			if (tcount2-initpow2 >= .5)
			{
			//		powerct2 = 100;
					endpow2 = .5;
			}
			else
			{
				//print player 2's power
				printf("\b");//backspaces on char
				printf("\r");//return to beginning of line
				//printf("%d", powerct2);
				printf("%.0f", (tcount2-initpow2)*200);
			}
		}
   }
	sheet1trans[1] = 3 + t * (3 - (8));
	int i;
	if (lockflag == 1  && playerflag == false)
	{
		for (i=0; i<NUM_PARTICLES; i++) 
		{
			//printf("pos[i][1]: %f\n", pos[i][1]);
			//printf("sheet[1]: %f\n", sheet1trans[1]);
			//printf("dif Y: %f\n", abs(pos[i][1] - sheet1trans[1]));
			//printf("dif X: %f\n", abs(pos[i][0] - sheet1trans[0]));
			if (((abs(pos[i][1] - sheet1trans[1]) < 5) && (abs(pos[i][0] - sheet1trans[0]) < .4)))
			{
				//printf("\nHIT SCREEN\n");
				mass[i] = 1.0;

				vel[i][0] *= -1;

				hitflag = 0;
				stopflag1 = 1;
			}
			else if (pos[i][1] < -1 || (pos[i][0] < -20) || (pos[i][0] > 20)) 
			{
				playerflag = true;
				printf("\nPLAYER 2's TURN\n");
				mass[i] = 1.0;

				//pos[i][0] = 0.0;
				//pos[i][1] = 0.0;
				//pos[i][2] = 0.0;
				acc[i][0] = 0.0;
				acc[i][1] = 0.0;
				acc[i][2] = 0.0;
      
				force[i][0] = 0.0;
				force[i][1] = 0.0;
				force[i][2] = 0.0;

				bulletflag1 = 0;
				lockflag = 0;
				hitflag = 0;
				stopflag1 = 1;

			}
		}
	}
   if (lockflag2 == 1  && playerflag == true)
	{
		for (i=0; i<NUM_PARTICLES; i++) 
		{
			if ((abs(pos2[i][1] - sheet1trans[1]) < 5) && (abs(pos2[i][0] - sheet1trans[0]) < .4))
			{
				mass2[i] = 1.0;

				vel2[i][0] *= -1;

				hitflag2 = 0;
				stopflag2 = 1;	
			}
			else if (pos2[i][1] < -1 || (pos2[i][0] > 20)|| (pos2[i][0] < -20))
			{
				playerflag = false;
				printf("\nPLAYER 1's TURN\n");
				mass2[i] = 1.0;

				acc2[i][0] = 0.0;
				acc2[i][1] = 0.0;
				acc2[i][2] = 0.0;
      
				force2[i][0] = 0.0;
				force2[i][1] = 0.0;
				force2[i][2] = 0.0;

				bulletflag2 = 0;
				lockflag2 = 0;
				hitflag2 = 0;
				stopflag2 = 1;
			}
		}
	}

	if (lockflag == 1 && playerflag == false)
	{
		sumForces();
		EulerIntegrate();
	}
	
	if (lockflag2 == 1 && playerflag == true)
	{
		sumForces2();
		EulerIntegrate2();
	}

   if (frame == endFrame) increment = -1;
   else if (frame == startFrame) increment = 1;
    
   frame = frame + increment;


   tcount += .01;
	tcount2 += .01;
	//printf("tcount = %f\n", tcount);

   display();

   glutTimerFunc(50,timeStep, 0);

}
Beispiel #5
0
void Particles::drawParticles() {
    sumForces();
    EularIntegrate();

    static int lock = 0;

    // draw all the particles

    for (int i=0; i<NUM_PARTICLES; i++) {
        // for each particle

        // save the transformation state
        glPushMatrix();

        glRotatef(rotate[i], 0, 0, 1);
        // this translation will be used to animate the particle
        glTranslatef(pos[i][0], pos[i][1], pos[i][2]);
        glShadeModel(GL_SMOOTH);						           // Enables Smooth Shading
        glClearColor(0.0f,0.0f,0.0f,0.0f);					     // Black Background
        glClearDepth(1.0f);							              // Depth Buffer Setup
        glDisable(GL_DEPTH_TEST);						           // Disables Depth Testing
        glEnable(GL_BLEND);							              // Enable Blending
        glBlendFunc(GL_SRC_ALPHA,GL_ONE);					     // Type Of Blending To Perform
        glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);	  // Really Nice Perspective Calculations
        glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);				  // Really Nice Point Smoothing
        glEnable(GL_TEXTURE_2D);						           // Enable Texture Mapping
        // each particle is just a glPoint
//     glBegin(GL_POINTS);
        //      glColor3f(color[i][0], color[i][1], color[i][2]);
        //       glVertex3f(0.0, 0.0, 0.0);
//     glEnd();
//	glDisable(GL_LIGHTING);
//	glEnable(GL_TEXTURE_2D);
        glEnable(GL_LIGHTING);
        // this is just for fun dynamic particles and mixing
        if (lock == 0) {
//     if(num == 1) {
            glBindTexture(GL_TEXTURE_2D, weapon_type);
            //    } else if (num == 2) {
            //      glBindTexture(GL_TEXTURE_2D, testMap2);
            //   } else if (num == 3) {
            //      glBindTexture(GL_TEXTURE_2D, testMap3);
            //   } else if (num == 4) {
            //      glBindTexture(GL_TEXTURE_2D, testMap4);
            //   }

            lock = 1;
        } else {
            //   if(num == 1) {
            glBindTexture(GL_TEXTURE_2D, weapon_type);
            //   } else if (num == 2) {
            //      glBindTexture(GL_TEXTURE_2D, testMap2);
            //   } else if (num == 3) {
            //      glBindTexture(GL_TEXTURE_2D, testMap3);
            //   } else if (num == 4) {
            //      glBindTexture(GL_TEXTURE_2D, testMap4);
            //   }
            lock = 0;
        }

        setMaterial(White);
        billboardSphericalBegin();
        glBegin(GL_QUADS);
        glTexCoord2f(0.0,1.0);
        glVertex2f(0.0, 0.0);
        glTexCoord2f(1.0,1.0);
        glVertex2f(particle_size, 0.0);
        glTexCoord2f(1.0,0.0);
        glVertex2f(particle_size, particle_size);
        glTexCoord2f(0.0,0.0);
        glVertex2f(0.0, particle_size);
        glEnd();
        billboardSphericalEnd();


        glBindTexture(GL_TEXTURE_2D, 0);
        glDisable(GL_TEXTURE_2D);
        glDisable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        glShadeModel(SHADING_MODE);
        //glEnable(GL_LIGHTING); // <-- this makes it look amazing

        // recover the transform state
        glPopMatrix();
    }

    return;
}