Esempio n. 1
0
////////////////////////////////////////////////////////////////////////////////
// Initialize ALL the particles
void InitPart(particle *part) {
  int i; // Iterator
  
  for (i = 0; i < MAXPART; ++i)
    partinit(part, i);
}
Esempio n. 2
0
////////////////////////////////////////////////////////////////////////////////
// Draw particles
void DrawPart(unsigned int *texture, particle *part, 
	      double x, double y, double z,
	      double s, double r) {
  int i;            // Iterator
  float px, py, pz; // Position

  // Push Attributes for Politness
  glPushAttrib(GL_CURRENT_BIT | GL_POINT_BIT | 
	       GL_LINE_BIT | GL_TEXTURE_BIT);

  // Save transformation
  glPushMatrix();
  // Offset
  glTranslated(x,y,z);
  glRotated(r,0,1,0);
  glScaled(s, s, s);

  // Add Textures
  /* 
  glDisable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  */
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, texture[DIRT]);  

  for (i = 0; i < MAXPART; ++i) {
    if (part[i].active) { // Make sure it's active!
      px = part[i].xp;
      py = part[i].yp;
      pz = part[i].zp;

      if (py < 0)
	partinit(part, i);
      else {
	//glColor4f(part[i].r, part[i].g, part[i].b, 1 /*part[i].life*/);
	
	glBegin(GL_QUADS);
	glNormal3d(0, 0, -1);
	glTexCoord2d(1.0, 0.0); glVertex3f(px + 0.5, py - 0.5, pz - 0.5);
	glTexCoord2d(1.0, 1.0); glVertex3f(px + 0.5, py + 0.5, pz - 0.5);
	glTexCoord2d(0.0, 1.0); glVertex3f(px - 0.5, py + 0.5, pz - 0.5);
	glTexCoord2d(0.0, 0.0); glVertex3f(px - 0.5, py - 0.5, pz - 0.5);

	glNormal3d(0, 0, +1);
	glTexCoord2d(1.0, 0.0); glVertex3f(px + 0.5, py - 0.5, pz + 0.5);
	glTexCoord2d(1.0, 1.0); glVertex3f(px + 0.5, py + 0.5, pz + 0.5);
	glTexCoord2d(0.0, 1.0); glVertex3f(px - 0.5, py + 0.5, pz + 0.5);
	glTexCoord2d(0.0, 0.0); glVertex3f(px - 0.5, py - 0.5, pz + 0.5);

	glNormal3d(0, -1, 0);
	glTexCoord2d(1.0, 0.0); glVertex3f(px + 0.5, py - 0.5, pz - 0.5);
	glTexCoord2d(1.0, 1.0); glVertex3f(px + 0.5, py - 0.5, pz + 0.5);
	glTexCoord2d(0.0, 1.0); glVertex3f(px - 0.5, py - 0.5, pz + 0.5);
	glTexCoord2d(0.0, 0.0); glVertex3f(px - 0.5, py - 0.5, pz - 0.5);      

	glNormal3d(0, +1, 0);
	glTexCoord2d(1.0, 0.0); glVertex3f(px + 0.5, py + 0.5, pz - 0.5);
	glTexCoord2d(1.0, 1.0); glVertex3f(px + 0.5, py + 0.5, pz + 0.5);
	glTexCoord2d(0.0, 1.0); glVertex3f(px - 0.5, py + 0.5, pz + 0.5);
	glTexCoord2d(0.0, 0.0); glVertex3f(px - 0.5, py + 0.5, pz - 0.5);      

	glNormal3d(-1, 0, 0);
	glTexCoord2d(1.0, 0.0); glVertex3f(px - 0.5, py - 0.5, pz + 0.5);
	glTexCoord2d(1.0, 1.0); glVertex3f(px - 0.5, py + 0.5, pz + 0.5);
	glTexCoord2d(0.0, 1.0); glVertex3f(px - 0.5, py + 0.5, pz - 0.5);
	glTexCoord2d(0.0, 0.0); glVertex3f(px - 0.5, py - 0.5, pz - 0.5);
		
	glNormal3d(+1, 0, 0);
	glTexCoord2d(1.0, 0.0); glVertex3f(px + 0.5, py - 0.5, pz + 0.5);
	glTexCoord2d(1.0, 1.0); glVertex3f(px + 0.5, py + 0.5, pz + 0.5);
	glTexCoord2d(0.0, 1.0); glVertex3f(px + 0.5, py + 0.5, pz - 0.5);
	glTexCoord2d(0.0, 0.0); glVertex3f(px + 0.5, py - 0.5, pz - 0.5);
	glEnd();
       
	  /*
	glBegin(GL_TRIANGLE_STRIP);
	glTexCoord2d(0.0, 1.0); glVertex3f(tetra[0][0] + px, tetra[0][1] + py, tetra[0][2] + pz);
	glTexCoord2d(1.0, 0.0); glVertex3f(tetra[1][0] + px, tetra[1][1] + py, tetra[1][2] + pz);
	glTexCoord2d(0.5, 1.0); glVertex3f(tetra[2][0] + px, tetra[2][1] + py, tetra[2][2] + pz);
	glTexCoord2d(0.5, 0.0); glVertex3f(tetra[3][0] + px, tetra[3][1] + py, tetra[3][2] + pz);
	glTexCoord2d(0.0, 1.0); glVertex3f(tetra[0][0] + px, tetra[0][1] + py, tetra[0][2] + pz);
	glTexCoord2d(1.0, 0.0); glVertex3f(tetra[1][0] + px, tetra[1][1] + py, tetra[1][2] + pz);
	glEnd();
	  */

	// Move Particle
	part[i].xp += part[i].xd/(slow*1000); // Move on X-Axis By X Speed
	part[i].yp += part[i].yd/(slow*1000); // Move on Y-Axis By Y Speed
	part[i].zp += part[i].zd/(slow*1000); // Move on Z-Axis By Z Speed
	
	// Add Gravity
	part[i].xd += part[i].xg; // Add X-Axis Gravity
	part[i].yd += part[i].yg; // Add Y-Axis Gravity
	part[i].zd += part[i].zg; // Add Z-Axis Gravity
	
	// Reduce particle Life by 'Fade'
	part[i].life -= part[i].fade;
	
	if (part[i].life < 0)
	  partinit(part, i);
      }
    }
  }

  // Reset Things
  glDisable(GL_BLEND);
  glEnable(GL_DEPTH_TEST);
  // Switch off textures
  glDisable(GL_TEXTURE_2D);
  // Undo transofrmations
  glPopMatrix();
  // Pop Attributes for Politness
  glPopAttrib();
}
Esempio n. 3
0
File: sub.c Progetto: npe9/harvey
void
devinit(Device *d)
{
	for (;;) {
		if(d->init)
			return;
		d->init = 1;
		print("\tdevinit %Z\n", d);
		switch(d->type) {
		default:
			print("devinit unknown device %Z\n", d);
			return;

		case Devro:
			cwinit(d->ro.parent);
			return;

		case Devcw:
			cwinit(d);
			return;

		case Devjuke:
			jukeinit(d);
			return;

		case Devwren:
			wreninit(d);
			return;

		case Devworm:
		case Devlworm:
			return;

		case Devfworm:
			fworminit(d);
			return;

		case Devmcat:
			mcatinit(d);
			return;

		case Devmlev:
			mlevinit(d);
			return;

		case Devmirr:
			mirrinit(d);
			return;

		case Devpart:
			partinit(d);
			return;

		case Devswab:
			d = d->swab.d;
			break;

		case Devnone:
			print("devinit of Devnone\n");
			return;
		}
	}
}