예제 #1
0
void SS3DWidget::paintGL()
{
	static const GLfloat bgmat_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
	static const GLfloat bgmat_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
	static const GLfloat bgmat_specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
	static const GLfloat bgmat_shininess = 1.0f;

	//_FillArray(property("-Base Material Diffuse").value<QColor>(), bgmat_diffuse);
	//_FillArray(property("-Base Material Ambient").value<QColor>(), bgmat_ambient);
	//_FillArray(property("-Base Material Specular").value<QColor>(), bgmat_specular);
	//bgmat_shininess = property("-Base Material Shininess").toDouble();
		
	static GLfloat mat_diffuse[] = {0.4f, 0.4f, 0.4f, 1.0f};
	static GLfloat mat_ambient[] = {0.4f, 0.4f, 0.4f, 0.8f};
	static GLfloat mat_specular[] = {0.2f, 0.2f, 0.2f, 0.8f};
	static GLfloat mat_shininess = 1.0f;

	_FillArray(property("-Terrain Material Diffuse").value<QColor>(), mat_diffuse);
	_FillArray(property("-Terrain Material Ambient").value<QColor>(), mat_ambient);
	_FillArray(property("-Terrain Material Specular").value<QColor>(), mat_specular);
	mat_shininess = property("-Terrain Material Shininess").toDouble();

	// Йтее
	static GLfloat light_position[] = {-1.5f, 1.5f, 1.5f, 0.0f};
	static GLfloat light_ambient[] = {.5f, .5f, .5f, 1.0f};
	static GLfloat light_diffuse[] = {.5f, .5f, .5f, 1.0f};
	static GLfloat light_specular[] = {0.5f, 0.5f, 0.5f, 0.2f};

	_FillArray(property("-Light Material Diffuse").value<QColor>(), light_diffuse);
	_FillArray(property("-Light Material Ambient").value<QColor>(), light_ambient);
	_FillArray(property("-Light Material Specular").value<QColor>(), light_specular);


	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

	qglClearColor(Qt::gray);
	glClearDepth(1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
	glLoadIdentity();

	m_cammat.setToIdentity();
	m_cammat.lookAt(m_cam_eye, m_cam_center, m_cam_up);
	glMultMatrixd(m_cammat.constData());
	glMultMatrixd(m_modelmat.constData());


	glMaterialfv(GL_FRONT, GL_AMBIENT, bgmat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, bgmat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, bgmat_specular);
	glMaterialf(GL_FRONT, GL_SHININESS, bgmat_shininess);

	glBegin(GL_LINES);
	glNormal3d(0, 0, 1);
	glVertex3d(- m_mapSize.width()/2.0, - m_mapSize.height()/2.0, -10);
	glVertex3d(- m_mapSize.width()/2.0, m_mapSize.height()/2.0, -10);
	glVertex3d(- m_mapSize.width()/2.0, m_mapSize.height()/2.0, -10);
	glVertex3d(m_mapSize.width()/2.0, m_mapSize.height()/2.0, -10);
	glVertex3d(m_mapSize.width()/2.0, m_mapSize.height()/2.0, -10);
	glVertex3d(m_mapSize.width()/2.0, - m_mapSize.height()/2.0, -10);
	glVertex3d(m_mapSize.width()/2.0, - m_mapSize.height()/2.0, -10);
	glVertex3d(- m_mapSize.width()/2.0, - m_mapSize.height()/2.0, -10);
	glEnd();

	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialf(GL_FRONT, GL_SHININESS, mat_shininess);

	paintTerrain();

	glPopMatrix();
}
예제 #2
0
void BaseBuilding::creerToitPyramideCoupe()
{
	double largeurBord = (double) UNIT*0.2;
	double hauteurBord = (double) UNIT*0.2;
	double air = Quadrangle(listPoints[0],listPoints[1],listPoints[2],listPoints[3]).Area();
	bool airMini = air > 8*(largeurBord*largeurBord);

	if(airMini)
	{
		float zTriangle = listPoints[0][2] + (float) windowHeight*2;
		Vector centre(0,0,0);

		for(unsigned int i = 0; i < listPoints.size(); i++) centre += listPoints[i];
		centre /= listPoints.size();
		double& z = centre[2]; 
		z = zTriangle; // mise à jour de Z

		//-------------------------Quadrangle supérieur --------------------------------------------------->
		std::vector<Vector> quadrangleIn; //la liste des points du quadrangle supérieur

		double onConserve = (double)(rand()%15)/100;
		for(unsigned int i = 0; i < listPoints.size(); i++)
		{
			Vector in = listPoints[i] + (centre - listPoints[i])*(onConserve + 0.5);
			double& z = in[2];
			z = zTriangle;
			quadrangleIn.push_back(in);
		}

		glBegin(GL_QUADS);
			glNormal3d(0,0,1.0f);
			glColor3ub(Vector::col1,Vector::col2,Vector::col3);
			glVertex3f(quadrangleIn[0][0], quadrangleIn[0][1], quadrangleIn[0][2]);
			glVertex3f(quadrangleIn[1][0], quadrangleIn[1][1], quadrangleIn[1][2]);
			glVertex3f(quadrangleIn[2][0], quadrangleIn[2][1], quadrangleIn[2][2]);
			glVertex3f(quadrangleIn[3][0], quadrangleIn[3][1], quadrangleIn[3][2]);

			for(int i=0; i<4;i++)
			{
				for(int j =0;j<3;j++)
				{
					ToitPyramideCoupe.push_back(quadrangleIn[i][j]);
				}
			}
			
		glEnd(); 
		//--------------------------------------------------------------------------------------------------<


		//----------------------------Faces de la "pyramide coupée"-----------------------------------------<  
		glBegin(GL_QUADS);
			glColor3ub(Vector::col1,Vector::col2,Vector::col3);
			for(unsigned int i = 0; i < 4; i++)
			{	
				glVertex3f(quadrangleIn[i%4][0], quadrangleIn[i%4][1], quadrangleIn[i%4][2]); // point Haut-Gauche
				glVertex3f(listPoints[i%4][0], listPoints[i%4][1], listPoints[i%4][2]); // point Bas-Gauche
				glVertex3f(listPoints[(i+1)%4][0], listPoints[(i+1)%4][1], listPoints[(i+1)%4][2]); //point Bas-Droite
				glVertex3f(quadrangleIn[(i+1)%4][0], quadrangleIn[(i+1)%4][1], quadrangleIn[(i+1)%4][2]); //point Haut-Droite
			}

			int j;
			for (int i=0; i<=3 ;i++)
			{
				for(j=0;j<=2;j++)
					ToitPyramideCoupe.push_back(quadrangleIn[i%4][j]);
				for(j=0;j<=2;j++)
			   	    ToitPyramideCoupe.push_back(listPoints[i%4][j]);
			    for(j=0;j<=2;j++)
				    ToitPyramideCoupe.push_back(listPoints[(i+1)%4][j]);
			    for(j=0;j<=2;j++)
			        ToitPyramideCoupe.push_back(quadrangleIn[(i+1)%4][j]);
			}


		glEnd();
		//--------------------------------------------------------------------------------------------------<

		listPoints.clear();
		for(unsigned int i = 0; i < quadrangleIn.size(); i++) listPoints.push_back(quadrangleIn[i]);
 PrismQuad(quadrangleIn[0],quadrangleIn[1],quadrangleIn[2],quadrangleIn[3], ((double) UNIT)*0.2).Render();
	}
	
}
예제 #3
0
파일: NaDbSurface.cpp 프로젝트: cybaj/NAK
void NaDbSurface::DrawShaded()
{
    NaGePoint3D curP; NaGePoint3D N;
    double uparts, vparts, istep, jstep;
    double fUPar, lUPar, fVPar, lVPar;

    double i, j;

    fUPar = pSurf->FirstUParameter();
    lUPar = pSurf->LastUParameter();

    fVPar = pSurf->FirstVParameter();
    lVPar = pSurf->LastVParameter();

    uparts = vparts = SMOOTH/15;

    istep = fabs(lUPar-fUPar)/uparts;
    jstep = fabs(lVPar-fVPar)/vparts;

    CListIteratorOfListOfPoint3D myListIterP(pointList);
    CListIteratorOfListOfPoint3D myListIterN(normalList);
    myListIterP.Init();
    myListIterN.Init();


    if(displayMode == GLSHADED) 
	glColor3ub(itsShadeRed, itsShadeGreen, itsShadeBlue);
    //else HLR

    glFrontFace(GL_CW);
    for(j = fVPar; j < lVPar; j += jstep)
    {
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glBegin(GL_TRIANGLE_STRIP);
		for(i = fUPar; i < lUPar; i += istep)
		{
			curP = myListIterP.Current();
			N = myListIterN.Current();
			glNormal3d(N.GetX(), N.GetY(), N.GetZ());
			glVertex3d(curP.GetX(), curP.GetY(), curP.GetZ());
			myListIterP.Next();
			myListIterN.Next();

			curP = myListIterP.Current();
			N = myListIterN.Current();
			glNormal3d(N.GetX(), N.GetY(), N.GetZ());
			glVertex3d(curP.GetX(), curP.GetY(), curP.GetZ());
			myListIterP.Next();
			myListIterN.Next();
		}
		curP = myListIterP.Current();
		N = myListIterN.Current();
		glNormal3d(N.GetX(), N.GetY(), N.GetZ());
		glVertex3d(curP.GetX(), curP.GetY(), curP.GetZ());
		myListIterP.Next();
		myListIterN.Next();

		curP = myListIterP.Current();
		N = myListIterN.Current();
		glNormal3d(N.GetX(), N.GetY(), N.GetZ());
		glVertex3d(curP.GetX(), curP.GetY(), curP.GetZ());
		myListIterP.Next();
		myListIterN.Next();

		glEnd();
    }
    glFrontFace(GL_CCW);
}
예제 #4
0
void World::Draw()
{
	static GLUquadricObj *quadObj = gluNewQuadric();

    float white[4] = {1.0,1.0,1.0,1.0};
    float grey[4] = {0.8,0.8,0.8,1.0};
    float black[4] = {0.0,0.0,0.0,1.0};
	float red[4] = {1.0,0.0,0.0,1.0};
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, grey);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black);
    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);

    for (unsigned int i = 0; i < m_shapes.size(); i++)
    {
        vec3 pos = m_shapes[i]->pos;
        if (m_shapes[i]->GetType() == SPHERE)
        {
            Sphere* c = (Sphere*) m_shapes[i];
            glPushMatrix();
            glTranslatef(pos[0], pos[1], pos[2]);
	        glutSolidSphere(c->r, 20, 20);   
            glPopMatrix();
        }
        else if (m_shapes[i]->GetType() == CUBE)
        {
            Cube* c = (Cube*) m_shapes[i];
            glPushMatrix();
            glTranslatef(pos[0], pos[1], pos[2]);
            glScalef(c->hx*2, c->hy*2, c->hz*2);
	        glutSolidCube(1.0);   
            glPopMatrix();
        }
        else if (m_shapes[i]->GetType() == CYLINDER)
        {
            Cylinder* c = (Cylinder*) m_shapes[i];
            vec3 forward = c->end - c->start;
            double height = forward.Length();
            double radius = c->r;

            forward.Normalize();

            vec3 left = vec3(0,1,0)^forward;
            vec3 up;
            if (left.Length() < 0.0001)
            {
                up = forward^vec3(1,0,0);
                left = up^forward;
            }
            else
            {
                up = forward^left;
            }

            float m[16];
            m[0] = left[0]; m[4] = up[0]; m[8] = forward[0];  m[12] = 0; 
            m[1] = left[1]; m[5] = up[1]; m[9] = forward[1];  m[13] = 0; 
            m[2] = left[2]; m[6] = up[2]; m[10] = forward[2]; m[14] = 0; 
            m[3] = 0.0;  m[7] = 0.0;  m[11] = 0.0;  m[15] = 1.0;

	        glPushMatrix();
			glTranslated(c->start[0], c->start[1], c->start[2]);
            glMultMatrixf(m); 
	        gluQuadricDrawStyle(quadObj, GLU_FILL);
	        gluQuadricNormals(quadObj, GLU_SMOOTH);
	        gluCylinder(quadObj, radius, radius, height, 12, 12);            
			//endCaps
			glPushMatrix();
			gluDisk(quadObj, 0, radius, 12, 12);
			glTranslated(0, 0, height);
			gluDisk(quadObj, 0, radius, 12, 12);
			glPopMatrix();
			glPopMatrix();
        }
        else if (m_shapes[i]->GetType() == GROUND)
        {
            glBegin(GL_QUADS);
                glNormal3d(0,1,0);
                glVertex3f(100, 0.0, -100.0);
                glVertex3f(100, 0.0, 100.0);
                glVertex3f(-100, 0.0, 100);
                glVertex3f(-100, 0.0, -100);
            glEnd();
        }
    }
}
예제 #5
0
/**
  Draw the polyhedron.
 */
void PolyhedronGeom::drawGL()
{
  // No tesselation object allocated yet? Then do so once and for all...
  if (tess==0)
  {
    tess = gluNewTess();
    if (tess==0)
      return;
  }

  // Set flag to 0 (i.e. no variables are present so far)
  tess_data_flag = 0;
  PrimVarAccess<vec3d> normals(*this, std::string("N"), NORMAL, 1, std::string("Nfaces"));
  PrimVarAccess<double> texcoords(*this, std::string("st"), FLOAT, 2, std::string("stfaces"));
  PrimVarAccess<vec3d> colors(*this, std::string("Cs"), COLOR, 1, std::string("Csfaces"));
  vec3d* N;
  vec3d* Cs;
  GLfloat glcol[4] = {0,0,0,1};
  double* st;
  vec3d* vertsptr = verts.dataPtr();
  int i,j;
  int nfloats=3;

  // Check which variables has to be passed to the vertex callback
  // (this is the case when mode is > 2)
  if (normals.mode>2)
  {
    tess_data_flag |= 0x01;
    nfloats += 3;
  }
  if (texcoords.mode>2)
  {
    tess_data_flag |= 0x02;
    nfloats += 2;
  }
  if (colors.mode>2)
  {
    tess_data_flag |= 0x04;
    nfloats += 3;
  }

  dataMemManager.setDataSize(nfloats*sizeof(GLdouble));

  gluTessCallback(tess, GLU_TESS_BEGIN, (TessCallback)(&onTessBegin));
  gluTessCallback(tess, GLU_TESS_END, (TessCallback)(&onTessEnd));
  gluTessCallback(tess, GLU_TESS_VERTEX, (TessCallback)(&onTessVertex));
    
  gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE);
  gluTessProperty(tess, GLU_TESS_TOLERANCE, 0);
  gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);

  // Iterate over all polygons...
  for(i=0; i<getNumPolys(); i++)
  {
    dataMemManager.reset();

    // No normals? Then a face normal has to be calculated...
    if (normals.mode==0)
    {
      vec3d Ng;
      computeNormal(i, Ng);
      glNormal3d(Ng.x, Ng.y, Ng.z);      
    }

    // Process uniform variables...
    if (normals.onFace(N))
      glNormal3d(N->x, N->y, N->z);
    if (texcoords.onFace(st))
      glTexCoord2dv(st);
    if (colors.onFace(Cs))
    {
      glcol[0] = GLfloat(Cs->x);
      glcol[1] = GLfloat(Cs->y);
      glcol[2] = GLfloat(Cs->z);
      glMaterialfv(GL_FRONT, GL_DIFFUSE, glcol);
    }

    gluTessBeginPolygon(tess, 0);
    // Iterate over all loops of polygon i...
    for(j=0; j<getNumLoops(i); j++)
    {
      gluTessBeginContour(tess);
      LoopIterator it = loopBegin(i, j);
      LoopIterator itend = loopEnd(i, j);
      vec3d* v;
      for( ; it!=itend; it++)
      {
	int vidx = (*it);
	v = vertsptr + vidx;
	GLdouble* data = (GLdouble*)dataMemManager.newDataPtr();
	GLdouble* p = data+3;
	data[0] = v->x;
	data[1] = v->y;
	data[2] = v->z;
	if (normals.onVertex(vidx, N))
	{
	  p[0] = N->x;
	  p[1] = N->y;
	  p[2] = N->z;
	  p += 3;
	}
	if (texcoords.onVertex(vidx, st))
	{
	  p[0] = st[0];
	  p[1] = st[1];
	  p += 2;
	}
	if (colors.onVertex(vidx, Cs))
	{
	  p[0] = Cs->x;
	  p[1] = Cs->y;
	  p[2] = Cs->z;
	}
	gluTessVertex(tess, data, data);
      }
      gluTessEndContour(tess);
    }
    gluTessEndPolygon(tess);
  }

  /*  for(i=0; i<getNumPolys(); i++)
  {
    for(j=0; j<getNumLoops(i); j++)
    {
      LoopIterator it = loopBegin(i, j);
      LoopIterator itend = loopEnd(i, j);
      vec3d* v;
      glBegin(GL_LINE_LOOP);
      for( ; it!=itend; it++)
      {
	v = vertsptr + (*it);
	glVertex3d(v->x, v->y, v->z);
      }
      glEnd();
    }
    }*/
}
void Batiment::creerToitPyramide()
{
	double largeurBord = (double) UNITE*0.2;
	double hauteurBord = (double) UNITE*0.2;
	double air = Quadrangle(listePoints[0],listePoints[1],listePoints[2],listePoints[3]).Area();
	bool airMini = air > 8*(largeurBord*largeurBord);
	int j;

	if(airMini)
	{
		double hauteurPyramide = hauteurEtage*2;
		Vector monterEnZ(0,0,hauteurPyramide);
		Vector centre(0,0,0);

		for(unsigned int i = 0; i < listePoints.size(); i++) centre += listePoints[i];
		centre /= listePoints.size();
		centre += monterEnZ;// mise à jour de Z


		glBegin(GL_TRIANGLES); // Debut du dessin de la pyramide
			glColor3ub(Vector::col1,Vector::col2,Vector::col3);
			for(unsigned int i = 0; i < 4; i++)
			{
				glNormal3d(0,0,1.0f);
				glVertex3f(centre[0], centre[1], centre[2]); // Haut du triangle de face
				glVertex3f(listePoints[i%4][0], listePoints[i%4][1], listePoints[i%4][3]); // Bas gauche du triangle de face
				glVertex3f(listePoints[(i+1)%4][0], listePoints[(i+1)%4][1], listePoints[(i+1)%4][3]); // Bas droit du triangle de face

				for(j=0;j<=2;j++)
			   	    ToitPyramide.push_back(centre[j]);
			    for(j=0;j<=1;j++)
				    ToitPyramide.push_back(listePoints[i%4][j]);
				if(j==2)
					ToitPyramide.push_back(listePoints[i%4][j+1]);
			    for(j=0;j<=1;j++)
			        ToitPyramide.push_back(listePoints[(i+1)%4][j]);
				if(j==2)
					ToitPyramide.push_back(listePoints[(i+1)%4][j+1]);

			}
		glEnd(); // Fin du dessin de la pyramide

		//ajout d'une antenne
		if(rand()%100 > 30)
		{
			//"0.9*" pour enterrer l'antenne dans la pyramide
			Vector enterrer(0,0, -0.15*hauteurPyramide);

			std::vector<Vector> quadrangleIn;

			// la base de l'antenne
			for(unsigned int i = 0; i < listePoints.size(); i++)
			{
				Vector in = (listePoints[i] + monterEnZ) + (centre - (listePoints[i] + monterEnZ))*0.97 + enterrer;
				quadrangleIn.push_back(in);
			}
			
			PrismQuad(quadrangleIn[0], quadrangleIn[1], quadrangleIn[2], quadrangleIn[3], hauteurEtage).Render();


			// l'antenne
			for(unsigned int i = 0; i < listePoints.size(); i++)
				quadrangleIn[i] = quadrangleIn[i] + (centre - quadrangleIn[i])*0.5;
			
			PrismQuad(quadrangleIn[0], quadrangleIn[1], quadrangleIn[2], quadrangleIn[3], hauteurPyramide*1.5).Render();
		}

	}
}
예제 #7
0
void myUnitCube::drawTextures()
{
	glPushMatrix();
	glTranslated(-0.5,-0.5,-0.5);

	//face de tras
	glPushMatrix();
	glRotated(180,0,1,0);
	glTranslated(-1,0,0);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();


	//face da frente
	glPushMatrix();
	glTranslated(0,0,1);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();


	//face de baixo
	glPushMatrix();
	glRotated(90,1,0,0);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();

	//face de cima
	glPushMatrix();
	glRotated(-90,1,0,0);
	glTranslated(0,-1,1);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();



	//face da esquerda
	glPushMatrix();
	glRotated(-90,0,1,0);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();

	//face da direita
	glPushMatrix();
	glRotated(90,0,1,0);
	glTranslated(-1,0,1);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();
	glPopMatrix();


}
예제 #8
0
void MeshModelRender::DrawModelSolidAndWireframe()
{
    // Draw solid smooth model
    glEnable(GL_POLYGON_SMOOTH);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(2.0, 2.0);
	
    CoordArray& vCoord = kernel->GetVertexInfo().GetCoord();
    NormalArray& vNormal = kernel->GetVertexInfo().GetNormal();
    PolyIndexArray& fIndex = kernel->GetFaceInfo().GetIndex();

    size_t nFace = fIndex.size();
    size_t i, j, n;

    if(!kernel->GetModelInfo().IsGeneralMesh())
    {
        if(kernel->GetModelInfo().IsTriMesh())  // Triangle mesh
            glBegin(GL_TRIANGLES);
        else if(kernel->GetModelInfo().IsQuadMesh())    // Quadangle mesh
            glBegin(GL_QUADS);
        else
            return;

        for(i = 0; i < nFace; ++ i)
        {
            IndexArray& face = fIndex[i];
            n = face.size();
            for(j = 0; j < n; ++ j)
            {
                VertexID& vID = face[j];
                Coord& v = vCoord[vID];
                Normal& n = vNormal[vID];
                glNormal3d(n[0], n[1], n[2]);
                glVertex3d(v[0], v[1], v[2]);
            }
        }
        glEnd();
    }

    else    // General polygonal mesh
    {
        for(i = 0; i < nFace; ++ i)
        {
            IndexArray& face = fIndex[i];
            n = face.size();
            glBegin(GL_POLYGON);
            for(j = 0; j < n; ++ j)
            {
                VertexID vID = face[j];
                Coord& v = vCoord[vID];
                Normal& n = vNormal[vID];
                glNormal3d(n[0], n[1], n[2]);
                glVertex3d(v[0], v[1], v[2]);
            }
            glEnd();
        }
    }
    glDisable(GL_POLYGON_OFFSET_FILL);
    glDisable(GL_POLYGON_SMOOTH);

    // Draw wireframe
    glDisable(GL_LIGHTING);
    glDepthFunc(GL_LEQUAL);

    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    glLineWidth(m_DftEdgeWidth);
    
    Color c = BLUE*0.70;
    glColor3d(c[0], c[1], c[2]);

    glBegin(GL_LINES);
    for(i = 0; i < nFace; ++ i)
    {
        IndexArray& f = fIndex[i];
        n = f.size();
        for(j = 0; j < n; ++ j)
        {
            Coord& v1 = vCoord[f[j]];
            Coord& v2 = vCoord[f[(j+1)%n]];
            glVertex3d(v1[0], v1[1], v1[2]);
            glVertex3d(v2[0], v2[1], v2[2]);
        }
    }
    glEnd();

    glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
    glDisable(GL_BLEND);
    glDisable(GL_LINE_SMOOTH);
    glEnable(GL_LIGHTING);
    glDepthFunc(GL_LESS);
    glEnable(GL_LIGHTING);
}
예제 #9
0
void MeshModelRender::DrawModelTextureMapping()
{
	CoordArray& vCoord = kernel->GetVertexInfo().GetCoord();
	TexCoordArray& tCoord = kernel->GetVertexInfo().GetTexCoord();
	NormalArray& vNormal = kernel->GetVertexInfo().GetNormal();
	PolyIndexArray& fIndex = kernel->GetFaceInfo().GetIndex();

	if (tCoord.empty())
	{
		return;
	}

	glEnable(GL_POLYGON_SMOOTH);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(2.0, 2.0);
	glDepthFunc(GL_LEQUAL);
	//glShadeModel(GL_SMOOTH);
	size_t nFace = fIndex.size();
	size_t i, j, n;

	// set texture env here.
	glEnable(GL_TEXTURE_2D);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	//glBindTexture(GL_TEXTURE_1D, texName);

	if(!kernel->GetModelInfo().IsGeneralMesh())
	{
		if(kernel->GetModelInfo().IsTriMesh())  // Triangle mesh
			glBegin(GL_TRIANGLES);
		else if(kernel->GetModelInfo().IsQuadMesh())    // Quadangle mesh
			glBegin(GL_QUADS);
		else
			return;

		for(i = 0; i < nFace; ++ i)
		{
			IndexArray& face = fIndex[i];
			n = face.size();
			for(j = 0; j < n; ++ j)
			{
				VertexID& vID = face[j];
				Coord& v = vCoord[vID];
				Coord2D& t = tCoord[vID];
				Normal& n = vNormal[vID];
				glNormal3d(n[0], n[1], n[2]);
				glTexCoord2d(t[0], t[1]);
				glVertex3d(v[0], v[1], v[2]);
			}
		}
		glEnd();
	}
	else    // General polygonal mesh
	{
		for(i = 0; i < nFace; ++ i)
		{
			IndexArray& face = fIndex[i];
			n = face.size();
			glBegin(GL_POLYGON);
			for(j = 0; j < n; ++ j)
			{
				VertexID vID = face[j];
				Coord& v = vCoord[vID];
				Coord2D& t = tCoord[vID];
				Normal& n = vNormal[vID];
				glNormal3d(n[0], n[1], n[2]);
				glTexCoord2d(t[0], t[1]);
				glVertex3d(v[0], v[1], v[2]);
			}
			glEnd();
		}
	}

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_POLYGON_OFFSET_FILL);
	glDisable(GL_POLYGON_SMOOTH);
}
예제 #10
0
void batter(double x, double y, double z){
	/* 色 */
	GLfloat white[] = { 1.f, 1.f, 1.f, 1.f };
	GLfloat blue[] = { 0.f, 0.0f, 1.0f, 1.f };
	GLfloat beige[] = { 1.f, 0.9f, 0.7f, 1.f };
	GLfloat black[] = { 0.f, 0.f, 0.f, 0.f };

	/* 腕と手 */

	glPushMatrix();
	glTranslated(x + 0.1, y + 0.58, z);
	glRotated(-90, 1.0, 0.0, 0.0);
	glRotated(bat_angle - 70, 0.0, 0.0, 1.0);
	glTranslated(-0.1, -0.24, 0);
	glEnable(GL_NORMALIZE);
	glScalef(0.3f, 1.f, 0.3f);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue);
	displaySphere(0.2f, 0.9f, 0.6f, 0.6f, 0.2f, 0.2f, 0.2f, 10.f);/* 腕 */
	glTranslated(0, -0.2, 0);
	glScalef(1.f, 0.3f, 1.f);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, beige);
	displaySphere(0.3f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f); /* 手 */
	glDisable(GL_NORMALIZE);
	glPopMatrix();

	glPushMatrix();
	glTranslated(x + 0.3, y + 0.58, z);
	glRotated(-90, 1.0, 0.0, 0.0);
	glRotated(bat_angle - 110, 0.0, 0.0, 1.0);
	glTranslated(0.2, -0.4, 0);
	//glTranslated(0, -0.2, 0);
	glEnable(GL_NORMALIZE);
	glScalef(0.3f, 1.f, 0.3f);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue);
	displaySphere(0.2f, 0.9f, 0.6f, 0.6f, 0.2f, 0.2f, 0.2f, 10.f);/* 腕 */
	glTranslated(0, -0.2, 0);
	glScalef(1.f, 0.3f, 1.f);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, beige);
	displaySphere(0.3f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f); /* 手 */
	glDisable(GL_NORMALIZE);
	glPopMatrix();

	/* 胴体 */
	glPushMatrix();
	glTranslated(x + 0.16, y, z - 0.1);
	myCylinder(0.15, 0.6, 1000);
	glPopMatrix();

	/* 頭 */
	glPushMatrix();
	glTranslated(x+0.18, y + 0.8, z - 0.1);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, beige);
	displaySphere(0.2f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f);/* 顔面 */
	glPopMatrix();

	glPushMatrix();
	glTranslated(x+0.18, y + 0.88, z - 0.1);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
	//glScalef(1.f, 0.3f, 1.f); //はちまきっぽいなんか
	glScalef(1.f, 0.7f, 1.f);
	displaySphere(0.21f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f);/* 帽子 */
	glPopMatrix();

	glPushMatrix();
	glTranslated(x+0.18, y + 0.8, z - 0.2);
	glScalef(0.3f, 0.07f, 1.f);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, black);
	glNormal3d(0.0, 0.0, 1.0);
	displaySphere(0.8f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f);/* 帽子のつば */
	glPopMatrix();
}
예제 #11
0
void MeshModelRender::DrawModelFaceTexture()
{
	glEnable(GL_POLYGON_SMOOTH);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(2.0, 2.0);
	glDepthFunc(GL_LEQUAL);
	//glShadeModel(GL_SMOOTH);

	CoordArray& vCoord = kernel->GetVertexInfo().GetCoord();
	TexCoordArray& vTexCoord = kernel->GetVertexInfo().GetTexCoord();
	PolyTexCoordArray& fTexCoord = kernel->GetFaceInfo().GetTexCoord();
	NormalArray& fNormal = kernel->GetFaceInfo().GetNormal();
	PolyIndexArray& fIndex = kernel->GetFaceInfo().GetIndex();
	PolyIndexArray& ftIndex = kernel->GetFaceInfo().GetTexIndex();

	if(fTexCoord.size() ==0) return;

	size_t nFace = fIndex.size();
	size_t i, j, n;

	// set texture env here.
	glEnable(GL_TEXTURE_2D);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	//glBindTexture(GL_TEXTURE_1D, texName);

	if(!kernel->GetModelInfo().IsGeneralMesh())
	{
		if(kernel->GetModelInfo().IsTriMesh())  // Triangle mesh
			glBegin(GL_TRIANGLES);
		else if(kernel->GetModelInfo().IsQuadMesh())    // Quadangle mesh
			glBegin(GL_QUADS);
		else
			return;

		for(i = 0; i < nFace; ++ i)
		{
			IndexArray& face = fIndex[i];
			IndexArray& tex_index = ftIndex[i];
			TexCoordArray& f_tex = fTexCoord[i];
			Normal& fn = fNormal[i];

			n = face.size();
			for(j = 0; j < n; ++ j)
			{
				VertexID& vID = face[j];
				Coord& v = vCoord[vID];
				const TexCoord& tex = vTexCoord[tex_index[j]];
				glNormal3d(fn[0], fn[1], fn[2]);
				glTexCoord2d(tex[0], tex[1]);
				//glTexCoord2d(f_tex[j][0], f_tex[j][1]);
				glVertex3d(v[0], v[1], v[2]);
			}
		}
		glEnd();
	}

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_POLYGON_OFFSET_FILL);
	glDisable(GL_POLYGON_SMOOTH);
}
예제 #12
0
void OpenGL::DrawCylinder2(double radius, double height)
{
	//多角形で近似して円筒を描く
	double th=0;
	double div=8;//分割数
	double dth=2*PI/div;
	double x,y,z;
	int i;

	glPushMatrix();
		glTranslated( (GLdouble)0,(GLdouble)0, (GLdouble)(-0.5*height) );
	//上面
	glBegin(GL_TRIANGLE_FAN);
		glNormal3d((GLdouble)0,(GLdouble)0,(GLdouble)1);
		for(i=0;i<div;i++)
		{
			th=dth*i;
			x=radius*cos(th);
			y=radius*sin(th);
			z=height;
			glVertex3d((GLdouble)x,(GLdouble)y,(GLdouble)z);
		}
	glEnd();

	//側面
		for(i=0;i<div;i++)
		{
			th=dth*i;
			//glBegin(GL_POLYGON);
			glBegin(GL_TRIANGLE_FAN);
			//glBegin(GL_TRIANGLE_STRIP);
			glNormal3d((GLdouble)cos(th),(GLdouble)sin(th),(GLdouble)0);
			z=0;
			x=radius*cos(th);
			y=radius*sin(th);
			glVertex3d((GLdouble)x,(GLdouble)y,(GLdouble)z);
			x=radius*cos(th+dth);
			y=radius*sin(th+dth);
			glVertex3d((GLdouble)x,(GLdouble)y,(GLdouble)z);
			z=height;
			glVertex3d((GLdouble)x,(GLdouble)y,(GLdouble)z);
			x=radius*cos(th);
			y=radius*sin(th);
			glVertex3d((GLdouble)x,(GLdouble)y,(GLdouble)z);
			z=0;
			glVertex3d((GLdouble)x,(GLdouble)y,(GLdouble)z);
			glEnd();
		}


	//下面
	glBegin(GL_TRIANGLE_FAN);
	//glBegin(GL_POLYGON);
		glNormal3d((GLdouble)0,(GLdouble)0,(GLdouble)-1);
		//for(i=0;i<div;i++)
		for(i=div-1;i>=0;i--)
		{
			th=dth*i;
			x=radius*cos(th);
			y=radius*sin(th);
			z=0;
			glVertex3d((GLdouble)x,(GLdouble)y,(GLdouble)z);
		}
	glEnd();

		//gluCylinder(quad, (GLdouble)radius, (GLdouble)radius, (GLdouble)height, (GLint)16, (GLint)1 );
		//gluDisk(quad, (GLdouble)0, (GLdouble)radius, (GLint)16, (GLint)1 );
		//glTranslated( (GLdouble)0,0, (GLdouble)height );
		//gluDisk(quad, (GLdouble)0, (GLdouble)radius, (GLint)16, (GLint)1 );
	glPopMatrix();

	return;
}
예제 #13
0
void processNode(Object* object){

	//Transformacoes
	glPushMatrix();
	glMultMatrixf(object->m_object);

	//Material
	if(object->material->id == "null"){
		if(materials.empty())
			cout << "Erro! Não há materiais na stack!" << endl;
		else{
			Material* mat = materials.top();
			mat->setMaterial();
		}
	} else{
		object->material->setMaterial();
		materials.push(object->material);
	}
	
	if(object->type == "simple"){ //Desenhar os poligonos
		Simple* simple = (Simple*)object;
		
		//Texturas
		if(object->texture->id != "null")
			textures.push(object->texture);
		if((object->texture->id != "clear") && (textures.top()->id != "clear")){
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, textures.top()->number);
		}
		
		//Triangulo
		if(simple->polygon->type == "triangle"){
			Triangle* triangle = (Triangle*)simple->polygon;
			float* n = newell(triangle);
			
			float length_A = sqrt((triangle->x2-triangle->x1)*(triangle->x2-triangle->x1) + (triangle->y2-triangle->y1)*(triangle->y2-triangle->y1) + (triangle->z2-triangle->z1)*(triangle->z2-triangle->z1));
			float length_B = sqrt((triangle->x3-triangle->x1)*(triangle->x3-triangle->x1) + (triangle->y3-triangle->y1)*(triangle->y3-triangle->y1) + (triangle->z3-triangle->z1)*(triangle->z3-triangle->z1));
			float length_N = sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);

			double height = length_N / length_A;

			double width = sqrt(length_B*length_B - height*height);
	
			glBegin(GL_POLYGON);
				glNormal3f(n[0],n[1],n[2]);
				glTexCoord2d(triangle->x1/textures.top()->length_s, triangle->y1/textures.top()->length_t); glVertex3d(triangle->x1, triangle->y1, triangle->z1);
				glTexCoord2d((triangle->x1 + length_A)/textures.top()->length_s, triangle->y1/textures.top()->length_t); glVertex3d(triangle->x2, triangle->y2, triangle->z2);
				glTexCoord2d((triangle->x1 + width)/textures.top()->length_s, (triangle->y1 + height)/textures.top()->length_t);glVertex3d(triangle->x3, triangle->y3, triangle->z3);
			glEnd();
		}
		//Rectangulo
		if(simple->polygon->type == "rectangle"){
			Rectangle* rect = (Rectangle*)simple->polygon;
			float s = mapText(rect->x1, rect->x2, textures.top()->length_s);
			float t = mapText(rect->y1, rect->y2, textures.top()->length_t);
			glBegin(GL_POLYGON);
				glNormal3d(0.0,0.0,1.0);
				glTexCoord2f(0.0,0.0);glVertex2d(rect->x1, rect->y1);
				glTexCoord2f(s  ,0.0);glVertex2d(rect->x2, rect->y1);
				glTexCoord2f(s  ,t  );glVertex2d(rect->x2, rect->y2);
				glTexCoord2f(0.0,t  );glVertex2d(rect->x1, rect->y2);
			glEnd();
		}

		if(simple->polygon->type == "cylinder"){
			Cylinder* cyl = (Cylinder*)simple->polygon;
			gluCylinder(glQ, cyl->base, cyl->top, cyl->height, cyl->slices, cyl->stacks);
		}
		if(simple->polygon->type == "sphere"){
			Sphere* sphere = (Sphere*)simple->polygon;
			gluSphere(glQ, sphere->radius, sphere->slices, sphere->stacks);
		}
		if(simple->polygon->type == "disk"){
			Disk* disk = (Disk*)simple->polygon;
			gluDisk(glQ, disk->inner, disk->outer, disk->slices, disk->loops);
		}
		glDisable(GL_TEXTURE_2D);
		
	}else if(object->type == "compound"){
		if(object->texture->id != "null"){
			textures.push(object->texture);
		}
		Compound* compound = (Compound*)object;
		vector<Object*>::iterator it = compound->childrenObj.begin();
		for( ; it != compound->childrenObj.end(); it++){
			processNode(*it);
		}
	}
	if(object->material->id != "null") materials.pop();
	if(object->texture->id != "null") textures.pop(); 
	glPopMatrix();	
}
예제 #14
0
//===========================================================================
void cShapeBox::render(cRenderOptions& a_options)
{
    /////////////////////////////////////////////////////////////////////////
    // Render parts that use material properties
    /////////////////////////////////////////////////////////////////////////
    if (SECTION_RENDER_PARTS_WITH_MATERIALS(a_options, m_useTransparency))
    {
        // render material properties
        if (m_useMaterialProperty)
        {
            m_material->render(a_options);
        }


        if (!m_displayList.render(m_useDisplayList))
        {
            // create display list if requested
            m_displayList.begin(m_useDisplayList);

            // render box
            glBegin(GL_POLYGON);
            glNormal3d(1.0, 0.0, 0.0);
            glVertex3d(m_hSizeX, m_hSizeY, m_hSizeZ);
            glVertex3d(m_hSizeX,-m_hSizeY, m_hSizeZ);
            glVertex3d(m_hSizeX,-m_hSizeY,-m_hSizeZ);
            glVertex3d(m_hSizeX, m_hSizeY,-m_hSizeZ);
            glEnd();

            glBegin(GL_POLYGON);
            glNormal3d(-1.0, 0.0, 0.0);
            glVertex3d(-m_hSizeX, m_hSizeY,-m_hSizeZ);
            glVertex3d(-m_hSizeX,-m_hSizeY,-m_hSizeZ);
            glVertex3d(-m_hSizeX,-m_hSizeY, m_hSizeZ);
            glVertex3d(-m_hSizeX, m_hSizeY, m_hSizeZ);
            glEnd();

            glBegin(GL_POLYGON);
            glNormal3d(0.0, 1.0, 0.0);
            glVertex3d( m_hSizeX, m_hSizeY,-m_hSizeZ);
            glVertex3d(-m_hSizeX, m_hSizeY,-m_hSizeZ);
            glVertex3d(-m_hSizeX, m_hSizeY, m_hSizeZ);
            glVertex3d( m_hSizeX, m_hSizeY, m_hSizeZ);
            glEnd();

            glBegin(GL_POLYGON);
            glNormal3d(0.0,-1.0, 0.0);
            glVertex3d( m_hSizeX,-m_hSizeY, m_hSizeZ);
            glVertex3d(-m_hSizeX,-m_hSizeY, m_hSizeZ);
            glVertex3d(-m_hSizeX,-m_hSizeY,-m_hSizeZ);
            glVertex3d( m_hSizeX,-m_hSizeY,-m_hSizeZ);
            glEnd();

            glBegin(GL_POLYGON);
            glNormal3d(0.0, 0.0, 1.0);
            glVertex3d( m_hSizeX, m_hSizeY, m_hSizeZ);
            glVertex3d(-m_hSizeX, m_hSizeY, m_hSizeZ);
            glVertex3d(-m_hSizeX,-m_hSizeY, m_hSizeZ);
            glVertex3d( m_hSizeX,-m_hSizeY, m_hSizeZ);
            glEnd();
            glBegin(GL_POLYGON);
            glNormal3d(0.0, 0.0,-1.0);
            glVertex3d( m_hSizeX,-m_hSizeY,-m_hSizeZ);
            glVertex3d(-m_hSizeX,-m_hSizeY,-m_hSizeZ);
            glVertex3d(-m_hSizeX, m_hSizeY,-m_hSizeZ);
            glVertex3d( m_hSizeX, m_hSizeY,-m_hSizeZ);
            glEnd();

            // finalize display list
            m_displayList.end(true);
        }
    }
}
예제 #15
0
void Score::buildBoardScore(){

	int dimX = 6.0;
	int dimY = 6.0;
	int dimZ = 1.0;

	vector<int> pontuacao(3,0);
	parserScore(pontuacao);

	vector<int> time(2,0);
	parserTime(time);

	glEnable(GL_COLOR_MATERIAL);
	//glColor3f(0.2,0.5,0.7);
	glColor3f(0.9,0.9,0.9);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,10);
	//Face frente (dividida em 4 partes)
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,0.0,1.0);
		glTexCoord2f(0.0,0.0);glVertex3d(0.0,dimY-(dimY/4),dimZ);
		glTexCoord2f(1.0,0.0);glVertex3d(dimX,dimY-(dimY/4),dimZ);
		glTexCoord2f(1.0,1.0);glVertex3d(dimX,dimY,dimZ);
		glTexCoord2f(0.0,1.0);glVertex3d(0.0,dimY,dimZ);
	glEnd();
	glDisable(GL_TEXTURE_2D);
	
	//Numero de pontos, divido em 3 partes
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,pontuacao[2]);
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,0.0,1.0);
		glTexCoord2f(0.0,0.0);glVertex3d(0.0,dimY-(dimY/4)*2,dimZ);
		glTexCoord2f(1.0,0.0);glVertex3d(dimX-(dimX/3)*2,dimY-(dimY/4)*2,dimZ);
		glTexCoord2f(1.0,1.0);glVertex3d(dimX-(dimX/3)*2,dimY-(dimY/4),dimZ);
		glTexCoord2f(0.0,1.0);glVertex3d(0.0,dimY-(dimY/4),dimZ);
	glEnd();
	glDisable(GL_TEXTURE_2D);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,pontuacao[1]);
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,0.0,1.0);
		glTexCoord2f(0.0,0.0);glVertex3d(dimX-(dimX/3)*2,dimY-(dimY/4)*2,dimZ);
		glTexCoord2f(1.0,0.0);glVertex3d(dimX-(dimX/3),dimY-(dimY/4)*2,dimZ);
		glTexCoord2f(1.0,1.0);glVertex3d(dimX-(dimX/3),dimY-(dimY/4),dimZ);
		glTexCoord2f(0.0,1.0);glVertex3d(dimX-(dimX/3)*2,dimY-(dimY/4),dimZ);
	glEnd();
	glDisable(GL_TEXTURE_2D);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,pontuacao[0]);
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,0.0,1.0);
		glTexCoord2f(0.0,0.0);glVertex3d(dimX-(dimX/3),dimY-(dimY/4)*2,dimZ);
		glTexCoord2f(1.0,0.0);glVertex3d(dimX,dimY-(dimY/4)*2,dimZ);
		glTexCoord2f(1.0,1.0);glVertex3d(dimX,dimY-(dimY/4),dimZ);
		glTexCoord2f(0.0,1.0);glVertex3d(dimX-(dimX/3),dimY-(dimY/4),dimZ);
	glEnd();
	glDisable(GL_TEXTURE_2D);

	/**************************************************************/
	
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,11);
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,0.0,1.0);
		glTexCoord2f(1.0,0.0);glVertex3d(dimX,dimY-(dimY/4)*3,dimZ);
		glTexCoord2f(0.0,0.0);glVertex3d(0.0,dimY-(dimY/4)*3,dimZ);
		glTexCoord2f(0.0,1.0);glVertex3d(0.0,dimY-(dimY/4)*2,dimZ);
		glTexCoord2f(1.0,1.0);glVertex3d(dimX,dimY-(dimY/4)*2,dimZ);
	glEnd();
	glDisable(GL_TEXTURE_2D);
	
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,time[1]);
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,0.0,1.0);
		glTexCoord2f(0.0,0.0); glVertex3d(0.0,0.0,dimZ);
		glTexCoord2f(1.0,0.0); glVertex3d(dimX-(dimX/2),0.0,dimZ);
		glTexCoord2f(1.0,1.0); glVertex3d(dimX-(dimX/2),dimY-(dimY/4)*3,dimZ);
		glTexCoord2f(0.0,1.0); glVertex3d(0.0,dimY-(dimY/4)*3,dimZ);
	glEnd();
	glDisable(GL_TEXTURE_2D);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,time[0]);
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,0.0,1.0);
		glTexCoord2f(0.0,0.0); glVertex3d(dimX-(dimX/2),0.0,dimZ);
		glTexCoord2f(1.0,0.0); glVertex3d(dimX,0.0,dimZ);
		glTexCoord2f(1.0,1.0); glVertex3d(dimX,dimY-(dimY/4)*3,dimZ);
		glTexCoord2f(0.0,1.0); glVertex3d(dimX-(dimX/2),dimY-(dimY/4)*3,dimZ);
	glEnd();
	glDisable(GL_TEXTURE_2D);
	
	
	//Lado esquerdo
	glBegin(GL_POLYGON);
	    glNormal3d(-1.0,0.0,0.0);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(0.0,0.0,dimZ);
		glVertex3d(0.0,dimY,dimZ);
		glVertex3d(0.0,dimY,0.0);
	glEnd();

	//Lado direito
	glBegin(GL_POLYGON);
	    glNormal3d(1.0,0.0,0.0);
		glVertex3d(dimX,0.0,0.0);
		glVertex3d(dimX,0.0,dimZ);
		glVertex3d(dimX,dimY,dimZ);
		glVertex3d(dimX,dimY,0.0);
	glEnd();

	//Atrás
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,0.0,-1.0);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(dimX,0.0,0.0);
		glVertex3d(dimX,dimY,0.0);
		glVertex3d(0.0,dimY,0.0);
	glEnd();

	//Topo
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,1.0,0.0);
		glVertex3d(0.0,dimY,dimZ);
		glVertex3d(dimX,dimY,dimZ);
		glVertex3d(dimX,dimY,0.0);
		glVertex3d(0.0,dimY,0.0);
	glEnd();

	//Baixo
	glBegin(GL_POLYGON);
	    glNormal3d(0.0,-1.0,0.0);
		glVertex3d(0.0,0.0,dimZ);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(dimX,0.0,0.0);
		glVertex3d(dimX,0.0,dimZ);
	glEnd();

	glDisable(GL_COLOR_MATERIAL);
}
예제 #16
0
void MeshModelRender::DrawModelFaceColor()
{
    CoordArray& vCoord = kernel->GetVertexInfo().GetCoord();
    NormalArray& vNormal = kernel->GetVertexInfo().GetNormal();
    ColorArray& fColor = kernel->GetFaceInfo().GetColor();
    PolyIndexArray& fIndex = kernel->GetFaceInfo().GetIndex();

    if(fColor.size() != fIndex.size())
        return;

    // Get previous material diffuse components
    float ambient[4], diffuse[4], specular[4], emission[4], shininess;
    glGetMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
    glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
    glGetMaterialfv(GL_FRONT, GL_SPECULAR, specular);
    glGetMaterialfv(GL_FRONT, GL_EMISSION, emission);
    glGetMaterialfv(GL_FRONT, GL_SHININESS, &shininess);


	glDisable(GL_LIGHTING);
	glShadeModel(GL_SMOOTH);

//  glEnable(GL_POLYGON_SMOOTH);
//  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// 	glEnable(GL_POLYGON_OFFSET_FILL);
// 	glPolygonOffset(2.0, 2.0);
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_DIFFUSE);

    size_t nFace = fIndex.size();
    size_t i, j, n;

    if(!kernel->GetModelInfo().IsGeneralMesh())
    {
        if(kernel->GetModelInfo().IsTriMesh())  // Triangle mesh
            glBegin(GL_TRIANGLES);
        else if(kernel->GetModelInfo().IsQuadMesh())    // Quadangle mesh
            glBegin(GL_QUADS);
        else
            return;

        for(i = 0; i < nFace; ++ i)
        {			
			IndexArray& face = fIndex[i];
            n = face.size();
            Color& c = fColor[i];
            glColor3d(c[0], c[1], c[2]);			
            for(j = 0; j < n; ++ j)
            {
                VertexID& vID = face[j];
                Coord& v = vCoord[vID];
                Normal& n = vNormal[vID];
                glNormal3d(n[0], n[1], n[2]);
                glVertex3d(v[0], v[1], v[2]);
            }
        }
        glEnd();
    }

    else    // General polygonal mesh
    {
        for(i = 0; i < nFace; ++ i)
        {
            IndexArray& face = fIndex[i];
            n = face.size();
            Color& c = fColor[i];
            glColor3d(c[0], c[1], c[2]);
            glBegin(GL_POLYGON);
            for(j = 0; j < n; ++ j)
            {
                VertexID vID = face[j];
                Coord& v = vCoord[vID];
                Normal& n = vNormal[vID];
                glNormal3d(n[0], n[1], n[2]);
                glVertex3d(v[0], v[1], v[2]);
            }
            glEnd();
        }
    }
    glDisable(GL_COLOR_MATERIAL);
    glDisable(GL_POLYGON_OFFSET_FILL);
    glDisable(GL_POLYGON_SMOOTH);
	glEnable(GL_LIGHTING);

    // Reset previous material diffuse components
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
}
예제 #17
0
GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius,
                          GLdouble outerRadius, GLdouble thickness,
                          GLdouble toothSize, GLint toothCount)
{
    const double Pi = 3.14159265358979323846;

    GLuint list = glGenLists(1);
    glNewList(list, GL_COMPILE);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, reflectance);

    GLdouble r0 = innerRadius;
    GLdouble r1 = outerRadius - toothSize / 2.0;
    GLdouble r2 = outerRadius + toothSize / 2.0;
    GLdouble delta = (2.0 * Pi / toothCount) / 4.0;
    GLdouble z = thickness / 2.0;
    int i, j;

    glShadeModel(GL_FLAT);

    for (i = 0; i < 2; ++i) {
        GLdouble sign = (i == 0) ? +1.0 : -1.0;

        glNormal3d(0.0, 0.0, sign);

        glBegin(GL_QUAD_STRIP);
        for (j = 0; j <= toothCount; ++j) {
            GLdouble angle = 2.0 * Pi * j / toothCount;
	    glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
	    glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
	    glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
	    glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta),
                       sign * z);
        }
        glEnd();

        glBegin(GL_QUADS);
        for (j = 0; j < toothCount; ++j) {
            GLdouble angle = 2.0 * Pi * j / toothCount;
	    glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
	    glVertex3d(r2 * cos(angle + delta), r2 * sin(angle + delta),
                       sign * z);
	    glVertex3d(r2 * cos(angle + 2 * delta), r2 * sin(angle + 2 * delta),
                       sign * z);
	    glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta),
                       sign * z);
        }
        glEnd();
    }

    glBegin(GL_QUAD_STRIP);
    for (i = 0; i < toothCount; ++i) {
        for (j = 0; j < 2; ++j) {
            GLdouble angle = 2.0 * Pi * (i + (j / 2.0)) / toothCount;
            GLdouble s1 = r1;
            GLdouble s2 = r2;
            if (j == 1)
                qSwap(s1, s2);

	    glNormal3d(cos(angle), sin(angle), 0.0);
	    glVertex3d(s1 * cos(angle), s1 * sin(angle), +z);
	    glVertex3d(s1 * cos(angle), s1 * sin(angle), -z);

	    glNormal3d(s2 * sin(angle + delta) - s1 * sin(angle),
                       s1 * cos(angle) - s2 * cos(angle + delta), 0.0);
	    glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), +z);
	    glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), -z);
        }
    }
    glVertex3d(r1, 0.0, +z);
    glVertex3d(r1, 0.0, -z);
    glEnd();

    glShadeModel(GL_SMOOTH);

    glBegin(GL_QUAD_STRIP);
    for (i = 0; i <= toothCount; ++i) {
	GLdouble angle = i * 2.0 * Pi / toothCount;
	glNormal3d(-cos(angle), -sin(angle), 0.0);
	glVertex3d(r0 * cos(angle), r0 * sin(angle), +z);
	glVertex3d(r0 * cos(angle), r0 * sin(angle), -z);
    }
    glEnd();

    glEndList();

    return list;
}
예제 #18
0
void Box::updateCache()
{
    if (!cache)
        cache = glGenLists(1);
    glNewList( cache, GL_COMPILE );
    glColor3f( color.redF(), color.greenF(), color.blueF() );
    Math::Point3 halfSize = size_ / 2.0;
//     qDebug() << "Box" << pos_ << halfSize;
    glBegin(GL_QUADS);
    // bottom
    if ( sides & BottomSide )
    {
        glNormal3d( 0, 0,-1 );
        glTexCoord2d( 0, 0 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() - halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 0, 1 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() + halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 1, 1 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() + halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 1, 0 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() - halfSize.y(), pos_.z() - halfSize.z() );
    }
    // top
    if ( sides & TopSide )
    {
        glNormal3d( 0, 0, 1 );
        glTexCoord2d( 0, 0 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() - halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 1, 0 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() - halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 1, 1 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() + halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 0, 1 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() + halfSize.y(), pos_.z() + halfSize.z() );
    }
    // front
    if ( sides & FrontSide )
    {
        glNormal3d( 1,-1, 0 );
        glTexCoord2d( 0, 0 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() - halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 1, 0 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() - halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 1, 1 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() - halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 0, 1 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() - halfSize.y(), pos_.z() + halfSize.z() );
    }
    // back
    if ( sides & BackSide )
    {
        glNormal3d( 1, 1, 0 );
        glTexCoord2d( 0, 0 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() + halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 0, 1 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() + halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 1, 1 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() + halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 1, 0 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() + halfSize.y(), pos_.z() - halfSize.z() );
    }
    // left
    if ( sides & LeftSide )
    {
        glNormal3d(-1, 0, 0 );
        glTexCoord2d( 0, 0 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() - halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 0, 1 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() - halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 1, 1 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() + halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 1, 0 ); glVertex3d( pos_.x() - halfSize.x(), pos_.y() + halfSize.y(), pos_.z() - halfSize.z() );
    }
    // right
    if ( sides & RightSide )
    {
        glNormal3d( 1, 0, 0 );
        glTexCoord2d( 0, 0 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() - halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 1, 0 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() + halfSize.y(), pos_.z() - halfSize.z() );
        glTexCoord2d( 1, 1 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() + halfSize.y(), pos_.z() + halfSize.z() );
        glTexCoord2d( 0, 1 ); glVertex3d( pos_.x() + halfSize.x(), pos_.y() - halfSize.y(), pos_.z() + halfSize.z() );
    }
    glEnd();
    glEndList();
}
예제 #19
0
void glDrawHalfWorm(const Vector3D& p0, const Vector3D& p1,
                                  const Vector3D& p2, const Vector3D& p3,
                                  double radius, bool cap1, bool cap2,
                                  double tension, float renderDetailLevel)
{
    int i, j, k, m, offset=0;
    Vector3D R1, R2, Qt, p, dQt, H, V;
    double len, MG[4][3], T[4], t, prevlen=0.0, cosj, sinj;
    GLfloat *Nx=NULL, *Ny=NULL, *Nz=NULL, *Cx=NULL, *Cy=NULL, *Cz=NULL,
        *pNx=NULL, *pNy=NULL, *pNz=NULL, *pCx=NULL, *pCy=NULL, *pCz=NULL, *tmp;

    /*
    * The Hermite matrix Mh.
    */
    static double Mh[4][4] = {
        { 2, -2,  1,  1},
        {-3,  3, -2, -1},
        { 0,  0,  1,  0},
        { 1,  0,  0,  0}
    };

    /*
    * Variables that affect the curve shape
    *   a=b=0 = Catmull-Rom
    */
    double a = tension,         /* tension    (adjustable)  */
        c = 0,                  /* continuity (should be 0) */
        b = 0;                  /* bias       (should be 0) */

    int wormSegments = 10 * renderDetailLevel;
    int wormSides = 10 * renderDetailLevel;

    /*
    if (wormSides % 2) {
        WARNINGMSG("worm sides must be an even number");
        ++wormSides;
    }
    */

    GLfloat *fblock = NULL;

    /* First, calculate the coordinate points of the center of the worm,
    * using the Kochanek-Bartels variant of the Hermite curve.
    */
    R1 = 0.5 * (1 - a) * (1 + b) * (1 + c) * (p1 - p0) + 0.5 * (1 - a) * (1 - b) * (1 - c) * ( p2 - p1);
    R2 = 0.5 * (1 - a) * (1 + b) * (1 - c) * (p2 -  p1) + 0.5 * (1 - a) * (1 - b) * (1 + c) * (p3 - p2);

    /*
    * Multiply MG=Mh.Gh, where Gh = [ P(1) P(2) R(1) R(2) ]. This
    * 4x1 matrix of vectors is constant for each segment.
    */
    for (i = 0; i < 4; ++i) {   /* calculate Mh.Gh */
        MG[i][0] = Mh[i][0] * p1.x + Mh[i][1] * p2.x + Mh[i][2] * R1.x + Mh[i][3] * R2.x;
        MG[i][1] = Mh[i][0] * p1.y + Mh[i][1] * p2.y + Mh[i][2] * R1.y + Mh[i][3] * R2.y;
        MG[i][2] = Mh[i][0] * p1.z + Mh[i][1] * p2.z + Mh[i][2] * R1.z + Mh[i][3] * R2.z;
    }

    for (i = 0; i <= wormSegments; ++i) {

        /* t goes from [0,1] from P(1) to P(2) (and we want to go halfway only),
        and the function Q(t) defines the curve of this segment. */
        t = (0.5 / wormSegments) * i;
        /*
        * Q(t)=T.(Mh.Gh), where T = [ t^3 t^2 t 1 ]
        */
        T[0] = t * t * t;
        T[1] = t * t;
        T[2] = t;
        //T[3] = 1;
        Qt.x = T[0] * MG[0][0] + T[1] * MG[1][0] + T[2] * MG[2][0] + MG[3][0] /* *T[3] */ ;
        Qt.y = T[0] * MG[0][1] + T[1] * MG[1][1] + T[2] * MG[2][1] + MG[3][1] /* *T[3] */ ;
        Qt.z = T[0] * MG[0][2] + T[1] * MG[1][2] + T[2] * MG[2][2] + MG[3][2] /* *T[3] */ ;

        if (radius == 0.0) {
            if (i > 0) {
                glBegin(GL_LINES);
                glVertex3d(p.x, p.y, p.z);
                glVertex3d(Qt.x, Qt.y, Qt.z);
                glEnd();
            }
            /* save to use as previous point for connecting points together */
            p = Qt;

        } else {
            /* construct a circle of points centered at and
            in a plane normal to the curve at t - these points will
            be used to construct the "thick" worm */

            /* allocate single block of storage for two circles of points */
            if (!Nx) {
                fblock = new GLfloat[12 * wormSides];
                Nx = fblock;
                Ny = &Nx[wormSides];
                Nz = &Nx[wormSides * 2];
                Cx = &Nx[wormSides * 3];
                Cy = &Nx[wormSides * 4];
                Cz = &Nx[wormSides * 5];
                pNx = &Nx[wormSides * 6];
                pNy = &Nx[wormSides * 7];
                pNz = &Nx[wormSides * 8];
                pCx = &Nx[wormSides * 9];
                pCy = &Nx[wormSides * 10];
                pCz = &Nx[wormSides * 11];
            }

            /*
            * The first derivative of Q(t), d(Q(t))/dt, is the slope
            * (tangent) at point Q(t); now T = [ 3t^2 2t 1 0 ]
            */
            T[0] = t * t * 3;
            T[1] = t * 2;
            //T[2] = 1;
            //T[3] = 0;
            dQt.x = T[0] * MG[0][0] + T[1] * MG[1][0] + MG[2][0] /* *T[2] + T[3]*MG[3][0] */ ;
            dQt.y = T[0] * MG[0][1] + T[1] * MG[1][1] + MG[2][1] /* *T[2] + T[3]*MG[3][1] */ ;
            dQt.z = T[0] * MG[0][2] + T[1] * MG[1][2] + MG[2][2] /* *T[2] + T[3]*MG[3][2] */ ;

            /* use cross product of [1,0,0] x normal as horizontal */
            H.set(0.0, -dQt.z, dQt.y);
            if (H.length() < 0.000001) /* nearly colinear - use [1,0.1,0] instead */
                H.set(0.1 * dQt.z, -dQt.z, dQt.y - 0.1 * dQt.x);
            H.normalize();

            /* and a vertical vector = normal x H */
            V = vector_cross(dQt, H);
            V.normalize();

            /* finally, the worm circumference points (C) and normals (N) are
            simple trigonometric combinations of H and V */
            for (j = 0; j < wormSides; ++j) {
                cosj = cos(2 * PI * j / wormSides);
                sinj = sin(2 * PI * j / wormSides);
                Nx[j] = H.x * cosj + V.x * sinj;
                Ny[j] = H.y * cosj + V.y * sinj;
                Nz[j] = H.z * cosj + V.z * sinj;
                Cx[j] = Qt.x + Nx[j] * radius;
                Cy[j] = Qt.y + Ny[j] * radius;
                Cz[j] = Qt.z + Nz[j] * radius;
            }

            /* figure out which points on the previous circle "match" best
            with these, to minimize envelope twisting */
            if (i > 0) {
                for (m = 0; m < wormSides; ++m) {
                    len = 0.0;
                    for (j = 0; j < wormSides; ++j) {
                        k = j + m;
                        if (k >= wormSides)
                            k -= wormSides;
                        len += (Cx[k] - pCx[j]) * (Cx[k] - pCx[j]) +
                            (Cy[k] - pCy[j]) * (Cy[k] - pCy[j]) +
                            (Cz[k] - pCz[j]) * (Cz[k] - pCz[j]);
                    }
                    if (m == 0 || len < prevlen) {
                        prevlen = len;
                        offset = m;
                    }
                }
            }

            /* create triangles from points along this and previous circle */
            if (i > 0) {
                glBegin(GL_TRIANGLE_STRIP);
                for (j = 0; j < wormSides; ++j) {
                    k = j + offset;
                    if (k >= wormSides) k -= wormSides;
                    glNormal3d(Nx[k], Ny[k], Nz[k]);
                    glVertex3d(Cx[k], Cy[k], Cz[k]);
                    glNormal3d(pNx[j], pNy[j], pNz[j]);
                    glVertex3d(pCx[j], pCy[j], pCz[j]);
                }
                glNormal3d(Nx[offset], Ny[offset], Nz[offset]);
                glVertex3d(Cx[offset], Cy[offset], Cz[offset]);
                glNormal3d(pNx[0], pNy[0], pNz[0]);
                glVertex3d(pCx[0], pCy[0], pCz[0]);
                glEnd();
            }

            /* put caps on the end */
            if (cap1 && i == 0) {
                dQt.normalize();
                glBegin(GL_POLYGON);
                glNormal3d(-dQt.x, -dQt.y, -dQt.z);
                for (j = wormSides - 1; j >= 0; --j) {
                        glVertex3d(Cx[j], Cy[j], Cz[j]);
                }
                glEnd();
            }
            else if (cap2 && i == wormSegments) {
                dQt.normalize();
                glBegin(GL_POLYGON);
                glNormal3d(dQt.x, dQt.y, dQt.z);
                for (j = 0; j < wormSides; ++j) {
                    k = j + offset;
                    if (k >= wormSides) k -= wormSides;
                        glVertex3d(Cx[k], Cy[k], Cz[k]);
                }
                glEnd();
            }

            /* store this circle as previous for next round; instead of copying
            all values, just swap pointers */
#define SWAPPTR(p1,p2) tmp=(p1); (p1)=(p2); (p2)=tmp
            SWAPPTR(Nx, pNx);
            SWAPPTR(Ny, pNy);
            SWAPPTR(Nz, pNz);
            SWAPPTR(Cx, pCx);
            SWAPPTR(Cy, pCy);
            SWAPPTR(Cz, pCz);
        }
    }

    delete[] fblock;
}
예제 #20
0
inline void glNormal(Vector2d const &v, double &z) {
	glNormal3d(v.c[0], v.c[1], z);
}
예제 #21
0
int main( int argc, char** argv )
{
  if ( argc < 2 ) {
    std::cerr<<"Usage : "<<argv[0]<<" input.obj"<<std::endl;
    return -1;
  }
  std::cerr<<argv[1]<<std::endl;

  LG::PolygonMesh mesh;
  mesh.read(argv[1]);

  //// instantiate 4 vertex handles
  //LgMesh::PolygonMesh::Vertex v0,v1,v2,v3;

  //// add 4 vertices
  //v0 = mesh.add_vertex(LgMesh::Vec3(0,0,0));
  //v1 = mesh.add_vertex(LgMesh::Vec3(1,0,0));
  //v2 = mesh.add_vertex(LgMesh::Vec3(0,1,0));
  //v3 = mesh.add_vertex(LgMesh::Vec3(0,0,1));

  //// add 4 triangular faces
  //mesh.add_triangle(v0,v1,v3);
  //mesh.add_triangle(v1,v2,v3);
  //mesh.add_triangle(v2,v0,v3);
  //mesh.add_triangle(v0,v2,v1);

  mesh.update_face_normals();
  mesh.update_vertex_normals();

  std::cout << "vertices: " << mesh.n_vertices() << std::endl;
  std::cout << "edges: "    << mesh.n_edges()    << std::endl;
  std::cout << "faces: "    << mesh.n_faces()    << std::endl;

  //if ( !mesh.read(argv[1]) ) return -2;
  Eigen::Vector3d bmin(-1, -1, -1);
  Eigen::Vector3d bmax(1, 1, 1);
  //mesh.getBoundingBox(bmin, bmax);
  Camera camera(std::stod(std::string(argv[2])));
  camera.init( bmin, bmax );


  if ( glfwInit() == GL_FALSE ) return -1;
  Window win( 640, 480, "hello world" );
  if ( !win ) return -1;
  GLFWwindow* window = win.getWindow();

  initGL();
  while ( !glfwWindowShouldClose( window ) ) {

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    double fov, zNear, zFar;
    camera.getPerspective( fov, zNear, zFar );
    gluPerspective( fov, win.getAspectRatio(),  zNear, zFar );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    Eigen::Vector3d eye, center, up;
    camera.getLookAt( eye, center, up );
    gluLookAt( eye.x(), eye.y(), eye.z(), center.x(), center.y(), center.z(), up.x(), up.y(), up.z() );

    //オブジェクトの宙鮫
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    LG::PolygonMesh::Face_iterator   fit;
    LG::PolygonMesh::Vertex_around_face_circulator vfc, vfc_end;
    LG::PolygonMesh::Face_attribute<LG::Vec3> f_normals = mesh.get_face_attribute<LG::Vec3>("f:normal");

    for (fit = mesh.faces_begin(); fit != mesh.faces_end(); ++fit)
    {
      glBegin(GL_TRIANGLES);
      LG::Vec3 n = f_normals[*fit];
      glNormal3d(n.x(), n.y(), n.z());

      vfc = mesh.vertices(*fit);
      vfc_end = vfc;

      do 
      {
        LG::Vec3 vp = mesh.position((*vfc));
        glVertex3d ( vp.x(), vp.y(), vp.z());
      } while (++vfc != vfc_end);

      glEnd();

    }
    glfwSwapBuffers( window );


    //マウスイベントの函誼
    glfwWaitEvents();
    double oldx, oldy, newx, newy;
    win.getMousePosition( oldx, oldy, newx, newy );
    if ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_1 ) != GLFW_RELEASE ) {
      camera.rotate( oldx, oldy, newx, newy );
    }
  }
  return 0;
}
예제 #22
0
파일: Castle.cpp 프로젝트: psyyz10/Castle
void Castle::DrawMainHead()
{
	glColor3ub(0, 100, 0);

	glPushMatrix();
	{
		glScaled(1, 1.2, 1);
		Draw3DBrick(0.75);
	}
	glPopMatrix();


	glPushMatrix(); // draw window
	{
		glTranslated(0, -0.1, 0.4);
		//glColor3ub(10, 10, 10);
		glScaled(0.3, 0.35, 0.01); 

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texId2);    // Tell openGL which texture buffer to apply as texture
		glColor3f(1.0, 1.0, 1.0);          // Set the base colour of the quad

		//glutSolidCube(0.3);
		glBegin(GL_QUADS);
		glNormal3d(0, 0, 1);
		glTexCoord2d(0.38, 1);   // Texture coordinate index into the top left sprite coord
		glVertex3d(-1, 1, 0);
		glTexCoord2d(0.38, 0.4);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(-1, -1, 0);
		glTexCoord2d(0.62, 0.4);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(1, -1, 0);
		glTexCoord2d(0.62, 1);   // Texture coordinate index into the top right sprite coord
		glVertex3d(1, 1, 0);
		glEnd();
		glBindTexture(GL_TEXTURE_2D, 0); // Bind to the blank buffer to stop ourselves accidentaly using the wrong texture in the next draw call
		glDisable(GL_TEXTURE_2D);	
	}
	glPopMatrix();

	glColor3ub(0, 100, 0);
	glTranslated(0, 0.5, 0);


	glPushMatrix();
	{
		glScaled(1, 0.3, 1);
		Draw3DBrick(1);
	}
	glPopMatrix();

	glColor3ub(0, 100, 0);
	for(float i = -0.4; i <= 0.5; i += 0.4)
	{
		glPushMatrix();
		{
			glTranslated(i, 0.1, 0.5);
			glScaled(0.2, 0.5, 0.05);
			Draw3DBrick(1);
		}
		glPopMatrix();
	}

	for(float i = -0.4; i <= 0.5; i += 0.4)
	{
		glPushMatrix();
		{
			glTranslated(i, 0.1, 0.5);
			glScaled(0.2, 0.5, 0.05);
			Draw3DBrick(1);
		}
		glPopMatrix();
	}
	for(float i = -0.4; i <= 0.5; i += 0.4)
	{
		glPushMatrix();
		{
			glTranslated(0.5, 0.1, i);
			glRotatef(90,0,1,0);
			glScaled(0.2, 0.5, 0.05);
			Draw3DBrick(1);
		}
		glPopMatrix();
	}
	for(float i = -0.4; i <= 0.5; i += 0.4)
	{
		glPushMatrix();
		{
			glTranslated(-0.5, 0.1, i);
			glRotatef(90,0,1,0);
			glScaled(0.2, 0.5, 0.05);
			Draw3DBrick(1);
		}
		glPopMatrix();
	}

	glPushMatrix();
	{
		glTranslated(-0.5, 0.2, 0.5);
		glScaled(0.1, 0.7, 0.1);
		Draw3DBrick(1);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glTranslated(-0.5, 0.2, -0.5);
		glScaled(0.1, 0.7, 0.1);
		Draw3DBrick(1);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glTranslated(0.5, 0.2, 0.5);
		glScaled(0.1, 0.7, 0.1);
		Draw3DBrick(1);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glTranslated(0.5, 0.2, -0.5);
		glScaled(0.1, 0.7, 0.1);
		Draw3DBrick(1);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glTranslated(0, 0.2, 0.5);
		glScaled(0.1, 0.7, 0.1);
		Draw3DBrick(1);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glTranslated(0, 0.2, -0.5);
		glScaled(0.1, 0.7, 0.1);
		Draw3DBrick(1);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glTranslated(0.5, 0.2, 0);
		glScaled(0.1, 0.7, 0.1);
		Draw3DBrick(1);
	}
	glPopMatrix();

	glPushMatrix();
	{
		glTranslated(-0.5, 0.2, 0);
		glScaled(0.1, 0.7, 0.1);
		Draw3DBrick(1);
	}
	glPopMatrix();


}
예제 #23
0
파일: normal.hpp 프로젝트: urp/urban-robots
 inline void Normal( GLdouble x, GLdouble y, GLdouble z )  { glNormal3d( x, y, z ); }
예제 #24
0
파일: Castle.cpp 프로젝트: psyyz10/Castle
void Castle::DrawWall()
{
	glPushMatrix();
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texId);    // Tell openGL which texture buffer to apply as texture
		glColor3f(1.0, 1.0, 1.0);          // Set the base colour of the quad
		glBegin(GL_QUADS);

		glNormal3d(0, 0, -1);
		glTexCoord2d(0, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(1, 1, -1);
		glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(1, -1, -1);
		glTexCoord2d(2, 0);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(-1, -1, -1);
		glTexCoord2d(2, 2);   // Texture coordinate index into the top right sprite coord
		glVertex3d(-1, 1, -1);

		glNormal3d(1, 0, 0);
		glTexCoord2d(0, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(1, 1, 1);
		glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(1, -1, 1);
		glTexCoord2d(2, 0);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(1, -1, -1);
		glTexCoord2d(2, 2);   // Texture coordinate index into the top right sprite coord
		glVertex3d(1, 1, -1);

		glNormal3d(-1, 0, 0);
		glTexCoord2d(0, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(-1, 1, -1);
		glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(-1, -1, -1);
		glTexCoord2d(2, 0);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(-1, -1, 1);
		glTexCoord2d(2, 2);   // Texture coordinate index into the top right sprite coord
		glVertex3d(-1, 1, 1);

		glNormal3d(0, 0, 1);
		glTexCoord2d(0, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(-1, 1, 1);
		glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(-1, -1, 1);
		glTexCoord2d(0.8, 0);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(-0.2, -1, 1);
		glTexCoord2d(0.8, 2);   // Texture coordinate index into the top right sprite coord
		glVertex3d(-0.2, 1, 1);

		glNormal3d(0, 0, 1);
		glTexCoord2d(0, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(0.2, 1, 1);
		glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(0.2, -1, 1);
		glTexCoord2d(0.8, 0);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(1, -1, 1);
		glTexCoord2d(0.8, 2);   // Texture coordinate index into the top right sprite coord
		glVertex3d(1, 1, 1);

		glNormal3d(0, 0, 1);
		glTexCoord2d(0.8, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(-0.2, 1, 1);
		glTexCoord2d(0.8, 1.2);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(-0.2, 0.2, 1);
		glTexCoord2d(0.9, 1.5);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(-0.1, 0.5, 1);
		glTexCoord2d(0.9, 2);   // Texture coordinate index into the top right sprite coord
		glVertex3d(-0.1, 1, 1);

		glNormal3d(0, 0, 1);
		glTexCoord2d(0.9, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(-0.1, 1, 1);
		glTexCoord2d(0.9, 1.5);   // Texture coordinate index into the top left sprite coord
		glVertex3d(-0.1, 0.5, 1);
		glTexCoord2d(1.1, 1.5);   // Texture coordinate index into the top left sprite coord
		glVertex3d(0.1, 0.5, 1);
		glTexCoord2d(1.1, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(0.1, 1, 1);

		glNormal3d(0, 0, 1);
		glTexCoord2d(1.1, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(0.1, 1, 1);
		glTexCoord2d(1.1, 1.5);   // Texture coordinate index into the top left sprite coord
		glVertex3d(0.1, 0.5, 1);
		glTexCoord2d(1.2, 1.2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(0.2, 0.2, 1);
		glTexCoord2d(1.2, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(0.2, 1, 1);

		/*
		glNormal3d(0, 1, 0);
		glVertex3d(-1, 1, -1);
		glVertex3d(-1, 1, 1);
		glVertex3d(1, 1, 1);
		glVertex3d(1, 1, -1);
		*/

		glNormal3d(0, 0, -1);
		glTexCoord2d(0, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(-0.2, 1, 0.9);
		glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(-0.2, -1, 0.9);
		glTexCoord2d(2, 0);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(-1, -1, 0.9);
		glTexCoord2d(2, 2);   // Texture coordinate index into the top right sprite coord
		glVertex3d(-1, 1, 0.9);

		glNormal3d(0, 0, -1);
		glTexCoord2d(0, 2);   // Texture coordinate index into the top left sprite coord
		glVertex3d(1, 1, 0.9);
		glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
		glVertex3d(1, -1, 0.9);
		glTexCoord2d(2, 0);   // Texture coordinate index into the bottom right sprite coord
		glVertex3d(0.2, -1, 0.9);
		glTexCoord2d(2, 2);   // Texture coordinate index into the top right sprite coord
		glVertex3d(0.2, 1, 0.9);

		glNormal3d(1, 0, 0);
		glVertex3d(-0.9, 1, 1);
		glVertex3d(-0.9, -1, 1);
		glVertex3d(-0.9, -1, -1);
		glVertex3d(-0.9, 1, -1);

		glNormal3d(-1, 0, 0);
		glVertex3d(0.9, 1, -1);
		glVertex3d(0.9, -1, -1);
		glVertex3d(0.9, -1, 1);
		glVertex3d(0.9, 1, 1);

		glNormal3d(0, 0, 1);
		glVertex3d(-1, 1, -0.9);
		glVertex3d(-1, -1, -0.9);
		glVertex3d(1, -1, -0.9);
		glVertex3d(1, 1, -0.9);


		glNormal3d(1, 0, 0);
		glVertex3d(-0.2, 0.2, 1);
		glVertex3d(-0.2, -1, 1);
		glVertex3d(-0.2, -1, 0.9);
		glVertex3d(-0.2, 0.2, 0.9);

		glNormal3d(-1, 0, 0);
		glVertex3d(0.2, 0.2, 0.9);
		glVertex3d(0.2, -1, 0.9);
		glVertex3d(0.2, -1, 1);
		glVertex3d(0.2, 0.2, 1);

		glNormal3d(0, 0, -1);
		glVertex3d(-0.1, 1, 0.9);
		glVertex3d(-0.1, 0.5, 0.9);
		glVertex3d(-0.2, 0.2, 0.9);
		glVertex3d(-0.2, 1, 0.9);

		glNormal3d(0, 0, -1);
		glVertex3d(0.1, 1, 0.9);
		glVertex3d(0.1, 0.5, 0.9);
		glVertex3d(-0.1, 0.5, 0.9);
		glVertex3d(-0.1, 1, 0.9);

		glNormal3d(0, 0, -1);	
		glVertex3d(0.2, 1, 0.9);
		glVertex3d(0.2, 0.2, 0.9);
		glVertex3d(0.1, 0.5, 0.9);
		glVertex3d(0.1, 1, 0.9);

		glNormal3d(0, -1, 0);	
		glVertex3d(-0.1, 0.5, 0.9);
		glVertex3d(0.1, 0.5, 0.9);
		glVertex3d(0.1, 0.5, 1);
		glVertex3d(-0.1, 0.5, 1);

		glVertex3d(0.1, 0.5, 1);
		glVertex3d(0.1, 0.5, 0.9);
		glVertex3d(0.2, 0.2, 0.9);
		glVertex3d(0.2, 0.2, 1);

		glVertex3d(-0.2, 0.2, 1);
		glVertex3d(-0.2, 0.2, 0.9);
		glVertex3d(-0.1, 0.5, 0.9);
		glVertex3d(-0.1, 0.5, 1);

		glEnd();
		glBindTexture(GL_TEXTURE_2D, 0); // Bind to the blank buffer to stop ourselves accidentaly using the wrong texture in the next draw call
		glDisable(GL_TEXTURE_2D);	
	}
	glPopMatrix();
}
예제 #25
0
파일: gl.cpp 프로젝트: dschaefer/swt-opengl
M(void, glNormal3d, jdouble nx, jdouble ny, jdouble nz) {
	glNormal3d(nx, ny, nz);
}
예제 #26
0
파일: Castle.cpp 프로젝트: psyyz10/Castle
void Castle:: Draw3DBrick(GLfloat size)
{   
	size *= 0.5;
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texId);    // Tell openGL which texture buffer to apply as texture
	glColor3f(1.0, 1.0, 1.0);          // Set the base colour of the quad

	glBegin(GL_QUADS);

	glNormal3d(0, 0, 1);
	glTexCoord2d(0, 1);   // Texture coordinate index into the top left sprite coord
	glVertex3d(-size, size, size);
	glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
	glVertex3d(-size, -size, size);
	glTexCoord2d(0.5, 0);   // Texture coordinate index into the bottom right sprite coord
	glVertex3d(size, -size, size);
	glTexCoord2d(0.5, 1);   // Texture coordinate index into the top right sprite coord
	glVertex3d(size, size, size);

	glNormal3d(0, 0, -1);
	glTexCoord2d(0, 0.5);   // Texture coordinate index into the top left sprite coord
	glVertex3d(size, size, -size);
	glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
	glVertex3d(size, -size, -size);
	glTexCoord2d(0.5, 0);   // Texture coordinate index into the bottom right sprite coord
	glVertex3d(-size, -size, -size);
	glTexCoord2d(0.5, 0.5);   // Texture coordinate index into the top right sprite coord
	glVertex3d(-size, size, -size);

	glNormal3d(1, 0, 0);
	glTexCoord2d(0, 0.5);   // Texture coordinate index into the top left sprite coord
	glVertex3d(size, size, size);
	glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
	glVertex3d(size, -size, size);
	glTexCoord2d(0.5, 0);   // Texture coordinate index into the bottom right sprite coord
	glVertex3d(size, -size, -size);
	glTexCoord2d(0.5, 0.5);   // Texture coordinate index into the top right sprite coord
	glVertex3d(size, size, -size);

	glNormal3d(-1, 0, 0);
	glTexCoord2d(0, 0.5);   // Texture coordinate index into the top left sprite coord
	glVertex3d(-size, size, -size);
	glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
	glVertex3d(-size, -size, -size);
	glTexCoord2d(0.5, 0);   // Texture coordinate index into the bottom right sprite coord
	glVertex3d(-size, -size, size);
	glTexCoord2d(0.5, 0.5);   // Texture coordinate index into the top right sprite coord
	glVertex3d(-size, size, size);

	glNormal3d(0, 1, 0);
	glTexCoord2d(0, 0.5);   // Texture coordinate index into the top left sprite coord
	glVertex3d(-size, size, -size);
	glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
	glVertex3d(-size, size, size);
	glTexCoord2d(0.5, 0);   // Texture coordinate index into the bottom right sprite coord
	glVertex3d(size, size, size);
	glTexCoord2d(0.5, 0.5);   // Texture coordinate index into the top right sprite coord
	glVertex3d(size, size, -size);

	glNormal3d(0, -1, 0);
	glTexCoord2d(0, 0.5);   // Texture coordinate index into the top left sprite coord
	glVertex3d(-size, -size, size);
	glTexCoord2d(0, 0);   // Texture coordinate index into the bottom left sprite coord
	glVertex3d(-size, -size, -size);
	glTexCoord2d(0.5, 0);   // Texture coordinate index into the bottom right sprite coord
	glVertex3d(size, -size, -size);
	glTexCoord2d(0.5, 0.5);   // Texture coordinate index into the top right sprite coord
	glVertex3d(size, -size, size);

	glEnd();
	glBindTexture(GL_TEXTURE_2D, 0); // Bind to the blank buffer to stop ourselves accidentaly using the wrong texture in the next draw call
	glDisable(GL_TEXTURE_2D);	
}
예제 #27
0
static void drawSolidCuboctahedron(void)
{
  glBegin( GL_TRIANGLES );
    glNormal3d( 0.577350269189, 0.577350269189, 0.577350269189); glVertex3d( RADIUS, RADIUS, 0.0 ); glVertex3d( 0.0, RADIUS, RADIUS ); glVertex3d( RADIUS, 0.0, RADIUS );
    glNormal3d( 0.577350269189, 0.577350269189,-0.577350269189); glVertex3d( RADIUS, RADIUS, 0.0 ); glVertex3d( RADIUS, 0.0,-RADIUS ); glVertex3d( 0.0, RADIUS,-RADIUS );
    glNormal3d( 0.577350269189,-0.577350269189, 0.577350269189); glVertex3d( RADIUS,-RADIUS, 0.0 ); glVertex3d( RADIUS, 0.0, RADIUS ); glVertex3d( 0.0,-RADIUS, RADIUS );
    glNormal3d( 0.577350269189,-0.577350269189,-0.577350269189); glVertex3d( RADIUS,-RADIUS, 0.0 ); glVertex3d( 0.0,-RADIUS,-RADIUS ); glVertex3d( RADIUS, 0.0,-RADIUS );
    glNormal3d(-0.577350269189, 0.577350269189, 0.577350269189); glVertex3d(-RADIUS, RADIUS, 0.0 ); glVertex3d(-RADIUS, 0.0, RADIUS ); glVertex3d( 0.0, RADIUS, RADIUS );
    glNormal3d(-0.577350269189, 0.577350269189,-0.577350269189); glVertex3d(-RADIUS, RADIUS, 0.0 ); glVertex3d( 0.0, RADIUS,-RADIUS ); glVertex3d(-RADIUS, 0.0,-RADIUS );
    glNormal3d(-0.577350269189,-0.577350269189, 0.577350269189); glVertex3d(-RADIUS,-RADIUS, 0.0 ); glVertex3d( 0.0,-RADIUS, RADIUS ); glVertex3d(-RADIUS, 0.0, RADIUS );
    glNormal3d(-0.577350269189,-0.577350269189,-0.577350269189); glVertex3d(-RADIUS,-RADIUS, 0.0 ); glVertex3d(-RADIUS, 0.0,-RADIUS ); glVertex3d( 0.0,-RADIUS,-RADIUS );
  glEnd();

  glBegin( GL_QUADS );
    glNormal3d( 1.0, 0.0, 0.0 ); glVertex3d( RADIUS, RADIUS, 0.0 ); glVertex3d( RADIUS, 0.0, RADIUS ); glVertex3d( RADIUS,-RADIUS, 0.0 ); glVertex3d( RADIUS, 0.0,-RADIUS );
    glNormal3d(-1.0, 0.0, 0.0 ); glVertex3d(-RADIUS, RADIUS, 0.0 ); glVertex3d(-RADIUS, 0.0,-RADIUS ); glVertex3d(-RADIUS,-RADIUS, 0.0 ); glVertex3d(-RADIUS, 0.0, RADIUS );
    glNormal3d( 0.0, 1.0, 0.0 ); glVertex3d( RADIUS, RADIUS, 0.0 ); glVertex3d( 0.0, RADIUS,-RADIUS ); glVertex3d(-RADIUS, RADIUS, 0.0 ); glVertex3d( 0.0, RADIUS, RADIUS );
    glNormal3d( 0.0,-1.0, 0.0 ); glVertex3d( RADIUS,-RADIUS, 0.0 ); glVertex3d( 0.0,-RADIUS, RADIUS ); glVertex3d(-RADIUS,-RADIUS, 0.0 ); glVertex3d( 0.0,-RADIUS,-RADIUS );
    glNormal3d( 0.0, 0.0, 1.0 ); glVertex3d( RADIUS, 0.0, RADIUS ); glVertex3d( 0.0, RADIUS, RADIUS ); glVertex3d(-RADIUS, 0.0, RADIUS ); glVertex3d( 0.0,-RADIUS, RADIUS );
    glNormal3d( 0.0, 0.0,-1.0 ); glVertex3d( RADIUS, 0.0,-RADIUS ); glVertex3d( 0.0,-RADIUS,-RADIUS ); glVertex3d(-RADIUS, 0.0,-RADIUS ); glVertex3d( 0.0, RADIUS,-RADIUS );
  glEnd();
}
예제 #28
0
파일: v3dgl.c 프로젝트: hsanjuan/sar2
/*
 *	Sets the given normal with respect to the glinterp values.
 */
static void V3DGLSetNormal(
	v3d_glinterprite_struct *glinterp, mp_vertex_struct *n
)
{
	int coordinate_axis = V3D_GLCOORDINATE_AXIS_SCIENTIFIC;
	int pass_normals = V3D_GLPASS_NORMALS_AS_NEEDED;
	int unitlize_normals = TRUE;
	mp_vertex_struct tn;


	if(n == NULL)
	    return;

	if(glinterp != NULL)
	{
	    if(glinterp->flags & V3D_GLFLAG_COORDINATE_AXIS)
		coordinate_axis = glinterp->coordinate_axis;
	    if(glinterp->flags & V3D_GLFLAG_PASS_NORMALS)
		pass_normals = glinterp->pass_normals;
	    if(glinterp->flags & V3D_GLFLAG_UNITLIZE_NORMALS)
		unitlize_normals = glinterp->unitlize_normals;
	}

	/* Never pass normals? */
	if(pass_normals == V3D_GLPASS_NORMALS_NEVER)
	    return;

	/* Check if normal vector is empty. */
	if((n->x == 0.0) && (n->y == 0.0) && (n->z == 0.0))
	{
	    /* It's empty, check if we should pass empty normal
	     * vectors.
	     */
	    if(pass_normals != V3D_GLPASS_NORMALS_ALWAYS)
		return;
	}

	/* Copy normal to our local target normal for later
	 * manipulation.
	 */
	tn.x = n->x;
	tn.y = n->y;
	tn.z = n->z;

	if(unitlize_normals &&
	   ((tn.x != 0.0) || (tn.y != 0.0) || (tn.z != 0.0))
	)
	{
	    double mag = SQRT(
		(tn.x * tn.x) + (tn.y * tn.y) + (tn.z * tn.z)
	    );
	    if(mag > 0.0)
	    {
		tn.x = tn.x / mag;
		tn.y = tn.y / mag;
		tn.z = tn.z / mag;
	    }
	}

	/* Set by coordinate axis type. */
	switch(coordinate_axis)
	{
	  case V3D_GLCOORDINATE_AXIS_GL:
	    glNormal3d(tn.x, tn.y, tn.z);
	    break;

	  case V3D_GLCOORDINATE_AXIS_SCIENTIFIC:
	    glNormal3d(tn.x, tn.z, -tn.y);
	    break;
	}
}
예제 #29
0
/*
 * Draws a solid sphere
 */
void FGAPIENTRY GLRenderer::glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
{
    int i,j;

    /* Adjust z and radius as stacks are drawn. */

    double z0,z1;
    double r0,r1;

    /* Pre-computed circle */

    double *sint1,*cost1;
    double *sint2,*cost2;

    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );

    fghCircleTable(&sint1,&cost1,-slices);
    fghCircleTable(&sint2,&cost2,stacks*2);

    /* The top stack is covered with a triangle fan */

    z0 = 1.0;
    z1 = cost2[(stacks>0)?1:0];
    r0 = 0.0;
    r1 = sint2[(stacks>0)?1:0];

    glBegin(GL_TRIANGLE_FAN);

        glNormal3d(0,0,1);
        glVertex3d(0,0,radius);

        for (j=slices; j>=0; j--)
        {
            glNormal3d(cost1[j]*r1,        sint1[j]*r1,        z1       );
            glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
        }

    glEnd();

    /* Cover each stack with a quad strip, except the top and bottom stacks */

    for( i=1; i<stacks-1; i++ )
    {
        z0 = z1; z1 = cost2[i+1];
        r0 = r1; r1 = sint2[i+1];

        glBegin(GL_QUAD_STRIP);

            for(j=0; j<=slices; j++)
            {
                glNormal3d(cost1[j]*r1,        sint1[j]*r1,        z1       );
                glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
                glNormal3d(cost1[j]*r0,        sint1[j]*r0,        z0       );
                glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
            }

        glEnd();
    }

    /* The bottom stack is covered with a triangle fan */

    z0 = z1;
    r0 = r1;

    glBegin(GL_TRIANGLE_FAN);

        glNormal3d(0,0,-1);
        glVertex3d(0,0,-radius);

        for (j=0; j<=slices; j++)
        {
            glNormal3d(cost1[j]*r0,        sint1[j]*r0,        z0       );
            glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
        }

    glEnd();

    /* Release sin and cos tables */

    free(sint1);
    free(cost1);
    free(sint2);
    free(cost2);
}
예제 #30
0
int set_vertex(scalar x,scalar y,scalar z, scalar tx,scalar ty,scalar nx, scalar ny, scalar nz) {
    glTexCoord2d(tx,ty);
    glNormal3d(nx,ny,nz);
    glVertex3d(x,y,z);
    return 0;
}