示例#1
0
void
collideBullets(void)
{
  int i,j,k1,k2;
  float dx,dy;
  float x,y,r;
  float xv,yv,e;

  for (i=0; i<MAX_BULLETS; i++)
    if (bullet[i].inuse)
      for (j=0; j<MAX_ROCKS; j++)
        if (rock[j].inuse) {
          x = rock[j].x;
          y = rock[j].y;
          r = rock[j].radius;
          dx = abs(bullet[i].x - x);
          dy = abs(bullet[i].y - y);
          if (dx + dy < r) {    /* quick manhattan metric */
            xv = rock[j].xv;
            yv = rock[j].yv;
            /* remove bullet and rock from circulation */
            rock[j].inuse = bullet[i].inuse = 0;
            if (r > 1.2) {
              /* split larger asteroids into two smaller ones */
              k1 = allocRock();
              if (k1 >= 0) {
                initRock(k1, r/2.0 + frand(0.5) - 0.3);
                rock[k1].x = x + frand(r) - r/2.0;
                rock[k1].y = y + frand(r) - r/2.0;
              }  
              k2 = allocRock();
              if (k2 >= 0) {
                initRock(k2, r/2.0 + frand(0.5) - 0.2);
                rock[k2].x = x + frand(r) - r/2.0;
                rock[k2].y = y + frand(r) - r/2.0;
              }
              if (k1 + k2 >= 0) {
                /* conserve momentum assuming equal masses */
                e = rock[k1].xv + rock[k2].xv - xv;
                rock[k1].xv -= e/2.0;
                rock[k2].xv -= e/2.0;
                e = rock[k1].yv + rock[k2].yv - yv;
                rock[k1].yv -= e/2.0;
                rock[k2].yv -= e/2.0;
              }
            }
            j = MAX_ROCKS;
          }
        }
}
示例#2
0
void
initRocks(void)
{
  int i;

  for (i=0; i<4; i++) {
        initRock(i, 1.0 + frand(3.0));
  }
}
示例#3
0
文件: Project.cpp 项目: WenboL/OpenGL
//Draw the rocks out
void drawRocks()
{

    glPushMatrix();
    glTranslated(planepos[0], planepos[1], planepos[2]);                                 // change the position of terrain to make it shows infront of camera
    glRotatef(180, 0, 1, 0);
    drawplane();                                               
    glPopMatrix();
    
    
    
	for (int i = 0; i < 9; i++) {
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'A');
        initRock();
        if(rocks[i].age > 0){
            
            
            
            rocks[i].age -= 1.5;
            rockpos=(float) (rand() %10 );
		glPushMatrix();
        rocks[i].pos[2] += speed;
        glColor3f(rocks[i].color[0], rocks[i].color[1], rocks[i].color[2]);
		glMaterialfv(GL_FRONT, GL_AMBIENT, colorBlue);
		glTranslatef(rocks[i].pos[0], rocks[i].pos[1], rocks[i].pos[2]);
		//rocks[i].pos[0] += rocks[i].velo[0];
        //glutSolidCube(10);
            glutSolidSphere(10, 15, 15);
		glPopMatrix();
                            
                

            
            
            
        }
    }
}