示例#1
0
void ssgVtxTableShadow::draw_geometry ()
{
  int num_colours   = getNumColours   () ;
  int num_normals   = getNumNormals   () ;
  int num_vertices  = getNumVertices  () ;
  int num_texcoords = getNumTexCoords () ;


  sgVec3 *vx = (sgVec3 *) vertices  -> get(0) ;
  sgVec3 *nm = (sgVec3 *) normals   -> get(0) ;
  sgVec2 *tx = (sgVec2 *) texcoords -> get(0) ;
  sgVec4 *cl = (sgVec4 *) colours   -> get(0) ;

  glDepthMask(GL_FALSE);
  glPolygonOffset(-15.0f, -20.0f);
  glEnable(GL_POLYGON_OFFSET_FILL);
  //glEnable(GL_CULL_FACE);

  glBegin ( gltype ) ;

  if ( num_colours == 0 ) glColor4f   ( 1.0f, 1.0f, 1.0f, 1.0f ) ;
  if ( num_colours == 1 ) glColor4fv  ( cl [ 0 ] ) ;
  if ( num_normals == 1 ) glNormal3fv ( nm [ 0 ] ) ;

  for ( int i = 0 ; i < num_vertices ; i++ )
  {
    if ( num_colours   > 1 ) glColor4fv    ( cl [ i ] ) ;
    if ( num_normals   > 1 ) glNormal3fv   ( nm [ i ] ) ;
    if ( num_texcoords > 1 ) glTexCoord2fv ( tx [ i ] ) ;

    glVertex3fv ( vx [ i ] ) ;
  }
 
  glEnd () ;
  glDisable(GL_POLYGON_OFFSET_FILL);
  glDepthMask(GL_TRUE);
}
示例#2
0
void ofxMesh::invertNormals() {
    for (int i=0; i<getNumNormals(); i++) {
        getNormals()[i] *= -1;
    }
}
示例#3
0
void ssgVtxTableSmoke::draw_geometry ()
{
	int num_colours = getNumColours();
	int num_normals = getNumNormals();
	float alpha;
	GLfloat modelView[16];
	sgVec3 A, B, C, D;
	sgVec3 right, up, offset;

	sgVec3 *vx = (sgVec3 *) vertices->get(0);
	sgVec3 *nm = (sgVec3 *) normals->get(0);
    sgVec4 *cl = (sgVec4 *) colours->get(0);
	alpha =  0.9f - ((float)(cur_life/max_life));
	glDepthMask(GL_FALSE);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	/*glPolygonOffset(-5.0f, +10.0f);*/
	/*glEnable(GL_POLYGON_OFFSET_FILL);*/

	// the principle is to have a right and up vector
	// to determine how the points of the quadri should be placed
	// orthogonaly to the view, parallel to the screen.

	/* get the matrix */
	// TODO: replace that, glGet stalls rendering pipeline (forces flush).
	glGetFloatv(GL_MODELVIEW_MATRIX, modelView);

	// get the up and right vector from the matrice view

	offset[0] = offset[1] = offset[2] = 0.0f;

	int i;
	for (i = 0; i < 3; i++) {
		int j = i;
		int k;
		for (k = 0; k < 4; k++, j+=4) {
			if (k != 3) {
				offset[i] += modelView[j] * vx[0][k];
			} else {
				offset[i] += modelView[j];
			}
		}
	}
	//printf ("%f %f %f\n", offset[0], offset[1], offset[2]);

	tdble dist = sqrt(offset[0]*offset[0]
		+ offset[1]*offset[1]
		+ offset[2]*offset[2]);

	up[0] = modelView[1];
	up[1] = modelView[5];
	up[2] = modelView[9];

	right[0] = modelView[0];
	right[1] = modelView[4];
	right[2] = modelView[8];

	// compute the coordinates of the four points of the quadri.

	// up and right points
	C[0] = right[0]+up[0];
	C[1] = right[1]+up[1];
	C[2] = right[2]+up[2];

	// left and up
	D[0] = -right[0]+up[0];
	D[1] = -right[1]+up[1];
	D[2] = -right[2]+up[2];

	// down and left
	A[0] = -right[0]-up[0];
	A[1] = -right[1]-up[1];
	A[2] = -right[2]-up[2];

	// right and down
	B[0] = right[0]-up[0];
	B[1] = right[1]-up[1];
	B[2] = right[2]-up[2];

	glBegin ( gltype ) ;

	if (dist < 50.0f) {
		alpha *= (1.0f - exp(-0.1f * dist));
	}

	glColor4f(cur_col[0],cur_col[1],cur_col[2],alpha);
	if (num_colours == 1) {
		glColor4fv(cl[0]);
	}
	if (num_normals == 1) {
		glNormal3fv(nm[0]);
	}

	// the computed coordinates are translated from the smoke position with the x, y, z speed
	glTexCoord2f(0,0);
	glVertex3f(vx[0][0]+sizex*A[0],vx[0][1]+sizey*A[1], vx[0][2]+sizez*A[2]);
	glTexCoord2f(0,1);
	glVertex3f(vx[0][0]+sizex*B[0],vx[0][1]+sizey*B[1], vx[0][2]+sizez*B[2]);
	glTexCoord2f(1,0);
	glVertex3f(vx[0][0]+sizex*D[0],vx[0][1]+sizey*D[1], vx[0][2]+sizez*D[2]);
	glTexCoord2f(1,1);
	glVertex3f(vx[0][0]+sizex*C[0],vx[0][1]+sizey*C[1], vx[0][2]+sizez*C[2]);
	glEnd();

	glDisable(GL_POLYGON_OFFSET_FILL);
	glDepthMask(GL_TRUE);
	glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
}
示例#4
0
void ssgVtxTableCarlight::draw_geometry ()
{
	if (on == 0) {
		return;
	}

	int num_normals = getNumNormals();
	float alpha;
	GLfloat modelView[16];
	sgVec3 A, B, C, D;
	sgVec3 right, up;
	sgVec3 axis;
	sgMat4 mat;
	sgMat4 mat3;
	sgVec3 *vx = (sgVec3 *) vertices->get(0);
	sgVec3 *nm = (sgVec3 *) normals->get(0);

	alpha = 0.75f;
	glDepthMask(GL_FALSE);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	glPolygonOffset(-15.0f, -20.0f);
	glEnable(GL_POLYGON_OFFSET_FILL);
	// get the matrix.
	glGetFloatv(GL_MODELVIEW_MATRIX, modelView);

	// get the up and right vector from the matrice view.
	up[0] = modelView[1];
	up[1] = modelView[5];
	up[2] = modelView[9];

	right[0] = modelView[0];
	right[1] = modelView[4];
	right[2] = modelView[8];

	// compute the coordinates of the four points of the quadri.

	// up and right points
	C[0] = right[0] + up[0];
	C[1] = right[1] + up[1];
	C[2] = right[2] + up[2];

	// left and up
	D[0] = -right[0] + up[0];
	D[1] = -right[1] + up[1];
	D[2] = -right[2] + up[2];

	// down and left
	A[0] = -right[0] - up[0];
	A[1] = -right[1] - up[1];
	A[2] = -right[2] - up[2];

	// right and down
	B[0] = right[0] - up[0];
	B[1] = right[1] - up[1];
	B[2] = right[2] - up[2];
	axis[0] = 0;
	axis[1] = 0;
	axis[2] = 1;

	if (grMaxTextureUnits > 1) {
		glActiveTextureARB (GL_TEXTURE0_ARB);
	}

	sgMakeRotMat4(mat, ((float)rand()/(float)RAND_MAX)*45, axis);
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity ();
	sgMakeTransMat4(mat3, 0.5, 0.5, 0);
	glMultMatrixf((float *)mat3);
	glMultMatrixf((float *)mat);
	sgMakeTransMat4(mat3, -0.5, -0.5, 0);
	glMultMatrixf((float *)mat3);
	glMatrixMode(GL_MODELVIEW);

	for (int I = 0; I < on; I++)
	{
		glBegin(gltype) ;
		glColor4f(0.8, 0.8, 0.8, alpha);
		if (num_normals == 1) {
			glNormal3fv(nm[0]);
		}
		// the computed coordinates are translated from the smoke position with the x,y,z speed.
		glTexCoord2f(0, 0);
		glVertex3f(vx[0][0] + factor*size*A[0], vx[0][1] + factor*size*A[1], vx[0][2] + factor*size*A[2]);
		glTexCoord2f(0, 1);

		glVertex3f(vx[0][0] + factor*size*B[0], vx[0][1] + factor*size*B[1], vx[0][2] + factor*size*B[2]);
		glTexCoord2f(1, 0);

		glVertex3f(vx[0][0] + factor*size*D[0], vx[0][1] + factor*size*D[1], vx[0][2] + factor*size*D[2]);
		glTexCoord2f(1, 1);

		glVertex3f(vx[0][0]+factor*size*C[0],vx[0][1]+factor*size*C[1], vx[0][2]+factor*size*C[2]);

		glEnd();
	}
	glDisable(GL_POLYGON_OFFSET_FILL);

	if (grMaxTextureUnits > 1) {
		glActiveTextureARB (GL_TEXTURE0_ARB);
	}

	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	glDepthMask(GL_TRUE);
}