Esempio n. 1
0
void draw_scene() {

	glShadeModel(GL_SMOOTH);
	glInitNames();
	glPushName(SCENA);

	glPushMatrix();
		glPushName(HILL);
		glCallList(HILL);
	glPopMatrix();

	glPushMatrix();
		glLoadName(CHAIN);
		glPushMatrix();
			glTranslatef(0,-alfa*(pow(-19,2)+pow(0,2))+46.5,0);
			glRotatef(40*sin(angle),1,0,0);
			glTranslatef(0,-(-alfa*(pow(-19,2)+pow(0,2))+46.5),0);
			for(int i=0; i<10; i++) {
			glPushMatrix();
				glTranslatef(0,-alfa*(pow(-19,2)+pow(0,2))+ 46.5,0);
				glPushMatrix();
					glTranslatef(-8,-i*3,0);
					if(i%2==0)
						glRotatef(90,0,1,0);
					glCallList(CHAIN);
				glPopMatrix();
			glPopMatrix();
			}

			
			for(int i=0; i<10; i++) {
			glPushMatrix();
				glTranslatef(0,-alfa*(pow(-19,2)+pow(0,2))+ 46.5,0);
				glPushMatrix();
					glTranslatef(8,-i*3,0);
					if(i%2==0)
						glRotatef(90,0,1,0);
					glCallList(CHAIN);
				glPopMatrix();
			glPopMatrix();
			}

			glColor3f(0.4,0.4,0.4);

			glColor3f(0.8,0.3,0);
			// Seggiolino
			glPushMatrix();
				glLoadName(SEAT);
				glTranslatef(0,-alfa*(pow(-19,2)+pow(0,2))+16,0);
				glScalef(16,2,5);
				glutSolidCube(1);
			glPopMatrix();

			glColor3f(1,0,0);
			glPushMatrix();
				glLoadName(SEAT);
				glTranslatef(0,-alfa*(pow(-19,2)+pow(0,2))+17,0);
				glRotatef(-90,1,0,0);
				glutSolidCone(2.5,8,60,60);
			glPopMatrix();
		glPopMatrix();

			glColor3f(0.3,0.2,0);
			// Asta sx
			glPushMatrix();
				glLoadName(ASTA);
				glTranslatef(0,-alfa*(pow(-19,2)+pow(0,2)),0);
				glTranslatef(-17,25,0);
				glScalef(4,50,4);
				glutSolidCube(1);
			glPopMatrix();

			glColor3f(0.3,0.2,0);
			// Asta dx
			glPushMatrix();
				glLoadName(ASTA);
				glTranslatef(0,-alfa*(pow(-19,2)+pow(0,2)),0);
				glTranslatef(17,25,0);
				glScalef(4,50,4);
				glutSolidCube(1);
			glPopMatrix();

			glColor3f(0.5,0.5,0.5);
			// Asta centrale
			glPushMatrix();
				glTranslatef(0,-alfa*(pow(-19,2)+pow(0,2))+48,0);
				glBegin(GL_LINES);
					glVertex2f(-16,0);
					glVertex2f(16,0);
				glEnd();
			glPopMatrix();
	glPopMatrix();
}
Esempio n. 2
0
M(void, glLoadName, jint name) {
	glLoadName(name);
}
Esempio n. 3
0
/*-----------------------------------------------------------------------------
 *  Draw
 *  The Draw function is the main loop for the Graphics process. Draws each
 *  viewport and the lines within them
 *-----------------------------------------------------------------------------*/
void Draw( void )
{
    char buf[BUF_SIZ];
    GLdouble answer[MATRIX_SIZE];
    GLdouble attempt[MATRIX_SIZE];

    /* Clear the screen ... */
    glClear( GL_COLOR_BUFFER_BIT );

    if(gameComplete)
    {
        DrawText(-25.0, -25.0, DEFAULT_FONT, "GAME OVER! YOU WIN!");
    }
    else if(levelComplete)
    {
        DrawText(-25.0, -25.0, DEFAULT_FONT, "LEVEL COMPLETE!");
    }
    else
    {
        glPushMatrix( );
            /* Draw the Outlines for Transforms */
            glCallList('a');
            glCallList('s');

            /* Draw the Axes */
            glBegin( GL_LINES );
                glColor3f( 0.5, 0.5, 0.5 );
                glVertex3f( 100.0, 0.0, 0.0 );
                glVertex3f(-100.0, 0.0, 0.0 );
                glVertex3f( 0.0, 100.0, 0.0 );
                glVertex3f( 0.0,-100.0, 0.0 );
                glColor3f( 1.0, 1.0, 1.0 );
            glEnd( );
        glPopMatrix( );

        /* Draw the first set of Available Transforms */
        glPushMatrix( );
            /* Move to origin of first list */
            glTranslatef( 115.0, 90.0, 0.0 );

            /* List drawing */
            CreateTransforms( &tlAvailableTransforms, VERTICAL, AVAILABLE );
        glPopMatrix( );

        /* Draw the second set of Used Transforms */
        glPushMatrix( );
            /* Move to origin of first list */
            glTranslatef( -85.0, -120.0, 0.0 );

            /* List drawing */
            CreateTransforms( &tlSelectedTransforms, HORIZONTAL, SELECTED );
        glPopMatrix( );

        glPushMatrix( );
            /* Do all level transforms */
            RunTransformList( &tlLevel );

            /* Create model house */
            glLoadName( 1 );
            glCallList( 'l' );

            /* Get the modelview matrix */
            glGetDoublev( GL_MODELVIEW_MATRIX, answer );
        glPopMatrix( );

        /* Create the new house */
        glPushMatrix(  );
            /* Do all user selected transforms */
            RunTransformList( &tlSelectedTransforms );

            /* Create attempt house */
            glLoadName( HOUSE );
            glCallList( 'h' );

            /* Get the modelview matrix */
            glGetDoublev( GL_MODELVIEW_MATRIX, attempt );
        glPopMatrix( );

        /* Compare the model */
        if(CompareMatrices(answer, attempt))
        {
            levelComplete = TRUE;
            glutPostRedisplay( );
        }
    }

    /* Flush the buffer */
    glutSwapBuffers();

    return;
}
Esempio n. 4
0
void display(void)
{
	int startTime=glutGet(GLUT_ELAPSED_TIME);
	int counter = 1;
	
	glClearDepth(1.0f);
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_DEPTH_TEST);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glScalef(zoom, zoom, zoom);
	//floor plane
	glBegin(GL_POLYGON);
	glColor3f(0.3, 0.73, 0.1);
	glVertex3f(-75, -0.02, 75);
	glVertex3f(75, -0.02, 75);
	glVertex3f(75, -0.02, -75);
	glVertex3f(-75, -0.02, -75);
	glEnd();

	//draw patches
	for(int i=0;i<9;i++)
	{
		for(int j=0;j<9;j++)
		{
			glPushMatrix();
			glTranslatef((i-4.5)*10+5, 0, (j-4.5)*10+5);
			glLoadName(counter);
			counter++;
			drawPatch();
			glPopMatrix();
		}
	}

	
	drawMyHouse(texSet);

	/*
	glPushMatrix();
	drawMyHouse(texSet);

	glTranslatef(10, 0, 0);
	drawMyHouse(texSet);

	glTranslatef(10, 0, 0);
	drawMyHouse(texSet);

	glTranslatef(10, 0, 0);
	drawMyHouse(texSet);

	glTranslatef(10, 0, 0);
	drawMyHouse(texSet);

	glPopMatrix();
	*/

	
	int endTime=glutGet(GLUT_ELAPSED_TIME);
	cout<<"Frame Rate: "<<(float)1000/(endTime-startTime)<<"\n";
	glFlush();
	glutSwapBuffers();

}
Esempio n. 5
0
/* Render::pickModel: pick up a model at the screen position */
int Render::pickModel(PMDObject *objs, int num, int x, int y, int *allowDropPicked)
{
   int i;

   GLuint selectionBuffer[512];
   GLint viewport[4];

   GLint hits;
   GLuint *data;
   GLuint minDepth = 0, minDepthAllowDrop = 0;
   int minID, minIDAllowDrop;
   GLuint depth;
   int id;

   /* get current viewport */
   glGetIntegerv(GL_VIEWPORT, viewport);
   /* set selection buffer */
   glSelectBuffer(512, selectionBuffer);
   /* begin selection mode */
   glRenderMode(GL_SELECT);
   /* save projection matrix */
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   /* set projection matrix for picking */
   glLoadIdentity();
   /* apply picking matrix */
   gluPickMatrix(x, viewport[3] - y, 15.0, 15.0, viewport);
   /* apply normal projection matrix */
   applyProjectionMatrix();
   /* switch to model view mode */
   glMatrixMode(GL_MODELVIEW);
   /* initialize name buffer */
   glInitNames();
   glPushName(0);
   /* draw models with selection names */
   for (i = 0; i < num; i++) {
      if (objs[i].isEnable() == true) {
         glLoadName(i);
         objs[i].getPMDModel()->renderForPick();
      }
   }

   /* restore projection matrix */
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();
   /* switch to model view mode */
   glMatrixMode(GL_MODELVIEW);
   /* end selection mode and get number of hits */
   hits = glRenderMode(GL_RENDER);
   if (hits == 0) return -1;
   data = &(selectionBuffer[0]);
   minID = -1;
   minIDAllowDrop = -1;
   for (i = 0; i < hits; i++) {
      depth = *(data + 1);
      id = *(data + 3);
      if (minID == -1 || minDepth > depth) {
         minDepth = depth;
         minID = id;
      }
      if (allowDropPicked && objs[id].allowMotionFileDrop()) {
         if (minIDAllowDrop == -1 || minDepthAllowDrop > depth) {
            minDepthAllowDrop = depth;
            minIDAllowDrop = id;
         }
      }
      data += *data + 3;
   }
   if (allowDropPicked)
      *allowDropPicked = minIDAllowDrop;

   return minID;
}
Esempio n. 6
0
void Cube::Draw() const
{
  glPushMatrix();

  glLoadName(_id);

  QColor color(_color);

  //if (highlighted())
    //color = _color.lighter(120);

  qreal hSize = _size / 2.f;

  glTranslatef(_x, _y, _z);
  glTranslatef(_tx, _ty, _tz);
  glRotatef(_rx, 1.f, 0.f, 0.f);
  glRotatef(_ry, 0.f, 1.f, 0.f);
  glRotatef(_rz, 0.f, 0.f, 1.f);

  GLfloat diffuseColor[4] =
    {color.redF(), color.greenF(), color.blueF(), color.alphaF()};
  glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);

  glBegin(GL_QUADS);

  glNormal3f( 0.f,  0.f, -1.f);
  glVertex3f( hSize, -hSize, -hSize);
  glVertex3f( hSize,  hSize, -hSize);
  glVertex3f(-hSize,  hSize, -hSize);
  glVertex3f(-hSize, -hSize, -hSize);

  glNormal3f( 0.f,  0.f,  1.f);
  glVertex3f(-hSize, -hSize,  hSize);
  glVertex3f(-hSize,  hSize,  hSize);
  glVertex3f( hSize,  hSize,  hSize);
  glVertex3f( hSize, -hSize,  hSize);

  glNormal3f( 0.f,  1.f, 0.f);
  glVertex3f(-hSize,  hSize,  hSize);
  glVertex3f(-hSize,  hSize, -hSize);
  glVertex3f( hSize,  hSize, -hSize);
  glVertex3f( hSize,  hSize,  hSize);

  glNormal3f( 0.f, -1.f, 0.f);
  glVertex3f(-hSize, -hSize, -hSize);
  glVertex3f(-hSize, -hSize,  hSize);
  glVertex3f( hSize, -hSize,  hSize);
  glVertex3f( hSize, -hSize, -hSize);

  glNormal3f(-1.f,  0.f,  0.f);
  glVertex3f(-hSize, -hSize,  hSize);
  glVertex3f(-hSize, -hSize, -hSize);
  glVertex3f(-hSize,  hSize, -hSize);
  glVertex3f(-hSize,  hSize,  hSize);

  glNormal3f( 1.f,  0.f,  0.f);
  glVertex3f( hSize,  hSize,  hSize);
  glVertex3f( hSize,  hSize, -hSize);
  glVertex3f( hSize, -hSize, -hSize);
  glVertex3f( hSize, -hSize,  hSize);

  glEnd();

  glPopMatrix();
}
Esempio n. 7
0
File: g_render.c Progetto: aosm/X11
void __glXDisp_LoadName(GLbyte *pc)
{
	glLoadName( 
		*(GLuint   *)(pc + 0)
	);
}
Esempio n. 8
0
void Vehicle::display(
				Point translateToThirdPerson,//this point brings the car into View in first and third person mode
 				GLuint txtSiren,
				GLuint txtCar,
				bool firstPersonMode,
				bool overHeadView
				)
{
		int currName = getName();
		Point Centroid=getOrigin();
		float height = getSpaceDimensions().y;
		float width = getSpaceDimensions().x;
		float depth = getSpaceDimensions().z;
		vector<Point> displayPoints;
		vector<Point> textureCoords;
		glPushMatrix();

		// **********CHANGE FOR OVEHEAD
		if (overHeadView)
		{
			glTranslatef(0,-45,0);
			glTranslatef(getOrigin().x,getOrigin().y,getOrigin().z);
		}else
			glLoadIdentity();
		
		//Light/Siren on Vehicle
		if (siren==0)
		{
			siren= gluNewQuadric();
			gluQuadricNormals(siren, GLU_SMOOTH);
			gluQuadricTexture (siren,GLU_TRUE);			
		}

	if(firstPersonMode)
	{
		glPopMatrix();
		glTranslatef(0,-4,0);
		return;
	}
		
	glColor4f(1,1,1,0.9);

	if(!overHeadView)
	{
		glTranslatef(8,-24,-8);
	}
	else
		glTranslatef(-getOrigin().x,getOrigin().y,-getOrigin().z);

	if (collisionOccurs)
	{ //shake
		glTranslatef(0.5,0.5,-0.5);
		//draw pieces flying off
		glPushMatrix();
		glTranslatef(getOrigin().x,getOrigin().y+2*height,getOrigin().z);
		glEnable(GL_COLOR_MATERIAL);
		glColor4f(0,0,0,1);

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x-2*height,Centroid.y+2.5*height,Centroid.z);
		glVertex3f(Centroid.x-2.1*height,Centroid.y+2.5*height,Centroid.z+height);
		glVertex3f(Centroid.x-2*height,Centroid.y+2.8*height,Centroid.z+height);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x-2*height,Centroid.y+height,Centroid.z);
		glVertex3f(Centroid.x-2.1*height,Centroid.y+1.5*height,Centroid.z);
		glVertex3f(Centroid.x-2*height,Centroid.y+1.8*height,Centroid.z+height);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x+height,Centroid.y+height,Centroid.z);
		glVertex3f(Centroid.x+height,Centroid.y+1.5*height,Centroid.z);
		glVertex3f(Centroid.x+height,Centroid.y+1,Centroid.z+height);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x+height,Centroid.y+1.8*height,Centroid.z);
		glVertex3f(Centroid.x,Centroid.y+1.5*height,Centroid.z-0.5*height);
		glVertex3f(Centroid.x+height,Centroid.y+2*height,Centroid.z);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x,Centroid.y+1,Centroid.z);
		glVertex3f(Centroid.x+2*height,Centroid.y+2*height,Centroid.z);
		glVertex3f(Centroid.x,Centroid.y+1,Centroid.z);
		glEnd();

		glBegin(GL_TRIANGLES);
		glVertex3f(Centroid.x-2*height,Centroid.y+2*height,Centroid.z);
		glVertex3f(Centroid.x-2*height,Centroid.y+1.5*height,Centroid.z);
		glVertex3f(Centroid.x-height,Centroid.y+2*height,Centroid.z);
		glEnd();

		glDisable(GL_COLOR_MATERIAL);
		glColor4f(1,1,1,1);

		glPopMatrix();
	}
	

	glBindTexture(GL_TEXTURE_2D,txtCar);

	float damageModifier=(float)damage/(float)maxDamage *2.5;
	
	//Draw Vehicle
	displayPoints.clear();
	textureCoords.clear();
	glLoadName(getName());
	displayPoints.push_back(Point(Centroid.x - width+damageModifier,  Centroid.y - height,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height+damageModifier,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y + height,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z - depth));
	textureCoords =calculateTextureCoords(displayPoints);
	displayShape(displayPoints,textureCoords);

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x - width+damageModifier,  Centroid.y - height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height-+damageModifier,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y - height,  Centroid.z - depth));
	textureCoords =calculateTextureCoords(displayPoints);
	displayShape(displayPoints,textureCoords);

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height,  Centroid.z - depth-damageModifier));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y - height,  Centroid.z + depth-damageModifier));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y + height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x + width+damageModifier,  Centroid.y + height-damageModifier,  Centroid.z - depth));
	textureCoords =calculateTextureCoords(displayPoints);
	displayShape(displayPoints,textureCoords);

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y - height+damageModifier,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x - width+damageModifier,  Centroid.y - height+damageModifier,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z - depth+damageModifier));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z + depth+damageModifier));
	displayShape(displayPoints,calculateTextureCoords(displayPoints));

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x + width+damageModifier,  Centroid.y + height+damageModifier,  Centroid.z - depth));
	displayPoints.push_back(Point(Centroid.x + width+damageModifier,  Centroid.y + height+damageModifier,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z + depth));
	displayShape(displayPoints,calculateTextureCoords(displayPoints));

	displayPoints.clear();
	textureCoords.clear();
	displayPoints.push_back(Point(Centroid.x + width+damageModifier,  Centroid.y - height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x - width+damageModifier,  Centroid.y - height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x - width,  Centroid.y + height,  Centroid.z + depth));
	displayPoints.push_back(Point(Centroid.x + width,  Centroid.y + height,  Centroid.z + depth));
	displayShape(displayPoints,calculateTextureCoords(displayPoints));

	//draw siren
	float lightEmissive[]={1.0,1.0,1.0};
	glMaterialfv(GL_FRONT, GL_EMISSION,lightEmissive);
	glTranslatef(getOrigin().x,getOrigin().y+height,getOrigin().z);
	glBindTexture(GL_TEXTURE_2D,txtSiren);
	gluSphere(siren,height/4, 20,20);
	float lightEmissive2[]={0.0,0.0,0.0};
	glMaterialfv(GL_FRONT, GL_EMISSION,lightEmissive2);
	glPopMatrix();

	collisionOccurs=false;
}
Esempio n. 9
0
void ccGenericMesh::drawMeOnly(CC_DRAW_CONTEXT& context)
{
	ccGenericPointCloud* vertices = getAssociatedCloud();
	if (!vertices)
		return;

	handleColorRamp(context);

	//3D pass
	if (MACRO_Draw3D(context))
	{
		//any triangle?
		unsigned triNum = size();
		if (triNum == 0)
			return;

		//L.O.D.
		bool lodEnabled = (triNum > GET_MAX_LOD_FACES_NUMBER() && context.decimateMeshOnMove && MACRO_LODActivated(context));
		unsigned decimStep = (lodEnabled ? (unsigned)ceil((float)triNum*3 / (float)GET_MAX_LOD_FACES_NUMBER()) : 1);
		unsigned displayedTriNum = triNum / decimStep;

		//display parameters
		glDrawParams glParams;
		getDrawingParameters(glParams);
		glParams.showNorms &= bool(MACRO_LightIsEnabled(context));

		//vertices visibility
		const ccGenericPointCloud::VisibilityTableType* verticesVisibility = vertices->getTheVisibilityArray();
		bool visFiltering = (verticesVisibility && verticesVisibility->isAllocated());

		//wireframe ? (not compatible with LOD)
		bool showWired = isShownAsWire() && !lodEnabled;

		//per-triangle normals?
		bool showTriNormals = (hasTriNormals() && triNormsShown());
		//fix 'showNorms'
        glParams.showNorms = showTriNormals || (vertices->hasNormals() && m_normalsDisplayed);

		//materials & textures
		bool applyMaterials = (hasMaterials() && materialsShown());
		bool showTextures = (hasTextures() && materialsShown() && !lodEnabled);

		//GL name pushing
		bool pushName = MACRO_DrawEntityNames(context);
		//special case: triangle names pushing (for picking)
		bool pushTriangleNames = MACRO_DrawTriangleNames(context);
		pushName |= pushTriangleNames;

		if (pushName)
		{
			//not fast at all!
			if (MACRO_DrawFastNamesOnly(context))
				return;
			glPushName(getUniqueIDForDisplay());
			//minimal display for picking mode!
			glParams.showNorms = false;
			glParams.showColors = false;
			//glParams.showSF --> we keep it only if SF 'NaN' values are hidden
			showTriNormals = false;
			applyMaterials = false;
			showTextures = false;
		}

		//in the case we need to display scalar field colors
		ccScalarField* currentDisplayedScalarField = 0;
		bool greyForNanScalarValues = true;
		unsigned colorRampSteps = 0;
		ccColorScale::Shared colorScale(0);

		if (glParams.showSF)
		{
			assert(vertices->isA(CC_TYPES::POINT_CLOUD));
			ccPointCloud* cloud = static_cast<ccPointCloud*>(vertices);

			greyForNanScalarValues = (cloud->getCurrentDisplayedScalarField() && cloud->getCurrentDisplayedScalarField()->areNaNValuesShownInGrey());
			if (greyForNanScalarValues && pushName)
			{
				//in picking mode, no need to take SF into account if we don't hide any points!
				glParams.showSF = false;
			}
			else
			{
				currentDisplayedScalarField = cloud->getCurrentDisplayedScalarField();
				colorScale = currentDisplayedScalarField->getColorScale();
				colorRampSteps = currentDisplayedScalarField->getColorRampSteps();

				assert(colorScale);
				//get default color ramp if cloud has no scale associated?!
				if (!colorScale)
					colorScale = ccColorScalesManager::GetUniqueInstance()->getDefaultScale(ccColorScalesManager::BGYR);
			}
		}

		//materials or color?
		bool colorMaterial = false;
		if (glParams.showSF || glParams.showColors)
		{
			applyMaterials = false;
			colorMaterial = true;
			glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
			glEnable(GL_COLOR_MATERIAL);
		}

		//in the case we need to display vertex colors
		ColorsTableType* rgbColorsTable = 0;
		if (glParams.showColors)
		{
			if (isColorOverriden())
			{
				glColor3ubv(m_tempColor);
				glParams.showColors = false;
			}
			else
			{
				assert(vertices->isA(CC_TYPES::POINT_CLOUD));
				rgbColorsTable = static_cast<ccPointCloud*>(vertices)->rgbColors();
			}
		}
		else
		{
			glColor3fv(context.defaultMat.diffuseFront);
		}

		if (glParams.showNorms)
		{
			//DGM: Strangely, when Qt::renderPixmap is called, the OpenGL version can fall to 1.0!
			glEnable((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 ? GL_RESCALE_NORMAL : GL_NORMALIZE));
			glEnable(GL_LIGHTING);
			context.defaultMat.applyGL(true,colorMaterial);
		}

		//in the case we need normals (i.e. lighting)
		NormsIndexesTableType* normalsIndexesTable = 0;
		ccNormalVectors* compressedNormals = 0;
		if (glParams.showNorms)
		{
			assert(vertices->isA(CC_TYPES::POINT_CLOUD));
			normalsIndexesTable = static_cast<ccPointCloud*>(vertices)->normals();
			compressedNormals = ccNormalVectors::GetUniqueInstance();
		}

		//stipple mask
		if (stipplingEnabled())
			EnableGLStippleMask(true);

		if (!pushTriangleNames && !visFiltering && !(applyMaterials || showTextures) && (!glParams.showSF || greyForNanScalarValues))
		{
			//the GL type depends on the PointCoordinateType 'size' (float or double)
			GLenum GL_COORD_TYPE = sizeof(PointCoordinateType) == 4 ? GL_FLOAT : GL_DOUBLE;
			
			glEnableClientState(GL_VERTEX_ARRAY);
			glVertexPointer(3,GL_COORD_TYPE,0,GetVertexBuffer());

			if (glParams.showNorms)
			{
				glEnableClientState(GL_NORMAL_ARRAY);
				glNormalPointer(GL_COORD_TYPE,0,GetNormalsBuffer());
			}
			if (glParams.showSF || glParams.showColors)
			{
				glEnableClientState(GL_COLOR_ARRAY);
				glColorPointer(3,GL_UNSIGNED_BYTE,0,GetColorsBuffer());
			}

			//we can scan and process each chunk separately in an optimized way
			//we mimic the way ccMesh beahves by using virtual chunks!
			unsigned chunks = static_cast<unsigned>(ceil((double)displayedTriNum/(double)MAX_NUMBER_OF_ELEMENTS_PER_CHUNK));
			unsigned chunkStart = 0;
			const colorType* col = 0;
			for (unsigned k=0; k<chunks; ++k, chunkStart += MAX_NUMBER_OF_ELEMENTS_PER_CHUNK)
			{
				//virtual chunk size
				const unsigned chunkSize = k+1 < chunks ? MAX_NUMBER_OF_ELEMENTS_PER_CHUNK : (displayedTriNum % MAX_NUMBER_OF_ELEMENTS_PER_CHUNK);

				//vertices
				PointCoordinateType* _vertices = GetVertexBuffer();
				for (unsigned n=0; n<chunkSize; n+=decimStep)
				{
					const CCLib::TriangleSummitsIndexes* ti = getTriangleIndexes(chunkStart + n);
					memcpy(_vertices,vertices->getPoint(ti->i1)->u,sizeof(PointCoordinateType)*3);
					_vertices+=3;
					memcpy(_vertices,vertices->getPoint(ti->i2)->u,sizeof(PointCoordinateType)*3);
					_vertices+=3;
					memcpy(_vertices,vertices->getPoint(ti->i3)->u,sizeof(PointCoordinateType)*3);
					_vertices+=3;
				}

				//scalar field
				if (glParams.showSF)
				{
					colorType* _rgbColors = GetColorsBuffer();
					assert(colorScale);
					for (unsigned n=0; n<chunkSize; n+=decimStep)
					{
						const CCLib::TriangleSummitsIndexes* ti = getTriangleIndexes(chunkStart + n);
						col = currentDisplayedScalarField->getValueColor(ti->i1);
						memcpy(_rgbColors,col,sizeof(colorType)*3);
						_rgbColors += 3;
						col = currentDisplayedScalarField->getValueColor(ti->i2);
						memcpy(_rgbColors,col,sizeof(colorType)*3);
						_rgbColors += 3;
						col = currentDisplayedScalarField->getValueColor(ti->i3);
						memcpy(_rgbColors,col,sizeof(colorType)*3);
						_rgbColors += 3;
					}
				}
				//colors
				else if (glParams.showColors)
				{
					colorType* _rgbColors = GetColorsBuffer();

					for (unsigned n=0; n<chunkSize; n+=decimStep)
					{
						const CCLib::TriangleSummitsIndexes* ti = getTriangleIndexes(chunkStart + n);
						memcpy(_rgbColors,rgbColorsTable->getValue(ti->i1),sizeof(colorType)*3);
						_rgbColors += 3;
						memcpy(_rgbColors,rgbColorsTable->getValue(ti->i2),sizeof(colorType)*3);
						_rgbColors += 3;
						memcpy(_rgbColors,rgbColorsTable->getValue(ti->i3),sizeof(colorType)*3);
						_rgbColors += 3;
					}
				}

				//normals
				if (glParams.showNorms)
				{
					PointCoordinateType* _normals = GetNormalsBuffer();
					if (showTriNormals)
					{
						for (unsigned n=0; n<chunkSize; n+=decimStep)
						{
							CCVector3 Na, Nb, Nc;
							getTriangleNormals(chunkStart + n, Na, Nb, Nc);
							memcpy(_normals,Na.u,sizeof(PointCoordinateType)*3);
							_normals+=3;
							memcpy(_normals,Nb.u,sizeof(PointCoordinateType)*3);
							_normals+=3;
							memcpy(_normals,Nc.u,sizeof(PointCoordinateType)*3);
							_normals+=3;
						}
					}
					else
					{
						for (unsigned n=0; n<chunkSize; n+=decimStep)
						{
							const CCLib::TriangleSummitsIndexes* ti = getTriangleIndexes(chunkStart + n);
							memcpy(_normals,vertices->getPointNormal(ti->i1).u,sizeof(PointCoordinateType)*3);
							_normals+=3;
							memcpy(_normals,vertices->getPointNormal(ti->i2).u,sizeof(PointCoordinateType)*3);
							_normals+=3;
							memcpy(_normals,vertices->getPointNormal(ti->i3).u,sizeof(PointCoordinateType)*3);
							_normals+=3;
						}
					}
				}

				if (!showWired)
				{
					glDrawArrays(lodEnabled ? GL_POINTS : GL_TRIANGLES,0,(chunkSize/decimStep)*3);
				}
				else
				{
					glDrawElements(GL_LINES,(chunkSize/decimStep)*6,GL_UNSIGNED_INT,GetWireVertexIndexes());
				}
			}

			//disable arrays
			glDisableClientState(GL_VERTEX_ARRAY);
			if (glParams.showNorms)
				glDisableClientState(GL_NORMAL_ARRAY);
			if (glParams.showSF || glParams.showColors)
				glDisableClientState(GL_COLOR_ARRAY);
		}
		else
		{
			//current vertex color
			const colorType *col1=0,*col2=0,*col3=0;
			//current vertex normal
			const PointCoordinateType *N1=0,*N2=0,*N3=0;
			//current vertex texture coordinates
			float *Tx1=0,*Tx2=0,*Tx3=0;

			//loop on all triangles
			int lasMtlIndex = -1;

			if (showTextures)
			{
				//#define TEST_TEXTURED_BUNDLER_IMPORT
#ifdef TEST_TEXTURED_BUNDLER_IMPORT
				glPushAttrib(GL_COLOR_BUFFER_BIT);
				glEnable(GL_BLEND);
				glBlendFunc(context.sourceBlend, context.destBlend);
#endif

				glEnable(GL_TEXTURE_2D);
			}

			if (pushTriangleNames)
				glPushName(0);

			GLenum triangleDisplayType = lodEnabled ? GL_POINTS : showWired ? GL_LINE_LOOP : GL_TRIANGLES;
			glBegin(triangleDisplayType);

			//per-triangle normals
			const NormsIndexesTableType* triNormals = getTriNormsTable();
			//materials
			const ccMaterialSet* materials = getMaterialSet();

			for (unsigned n=0; n<triNum; ++n)
			{
				//current triangle vertices
				const CCLib::TriangleSummitsIndexes* tsi = getTriangleIndexes(n);

				//LOD: shall we display this triangle?
				if (n % decimStep)
					continue;

				if (visFiltering)
				{
					//we skip the triangle if at least one vertex is hidden
					if ((verticesVisibility->getValue(tsi->i1) != POINT_VISIBLE) ||
						(verticesVisibility->getValue(tsi->i2) != POINT_VISIBLE) ||
						(verticesVisibility->getValue(tsi->i3) != POINT_VISIBLE))
						continue;
				}

				if (glParams.showSF)
				{
					assert(colorScale);
					col1 = currentDisplayedScalarField->getValueColor(tsi->i1);
					if (!col1)
						continue;
					col2 = currentDisplayedScalarField->getValueColor(tsi->i2);
					if (!col2)
						continue;
					col3 = currentDisplayedScalarField->getValueColor(tsi->i3);
					if (!col3)
						continue;
				}
				else if (glParams.showColors)
				{
					col1 = rgbColorsTable->getValue(tsi->i1);
					col2 = rgbColorsTable->getValue(tsi->i2);
					col3 = rgbColorsTable->getValue(tsi->i3);
				}

				if (glParams.showNorms)
				{
					if (showTriNormals)
					{
						assert(triNormals);
						int n1,n2,n3;
						getTriangleNormalIndexes(n,n1,n2,n3);
						N1 = (n1>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n1)).u : 0);
						N2 = (n1==n2 ? N1 : n1>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n2)).u : 0);
						N3 = (n1==n3 ? N1 : n3>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n3)).u : 0);

					}
					else
					{
						N1 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i1)).u;
						N2 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i2)).u;
						N3 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i3)).u;
					}
				}

				if (applyMaterials || showTextures)
				{
					assert(materials);
					int newMatlIndex = this->getTriangleMtlIndex(n);

					//do we need to change material?
					if (lasMtlIndex != newMatlIndex)
					{
						assert(newMatlIndex<(int)materials->size());
						glEnd();
						if (showTextures)
						{
							GLuint texID = (newMatlIndex>=0 ? (*materials)[newMatlIndex].texID : 0);
							if (texID>0)
								assert(glIsTexture(texID));
							glBindTexture(GL_TEXTURE_2D, texID);
						}

						//if we don't have any current material, we apply default one
						(newMatlIndex>=0 ? (*materials)[newMatlIndex] : context.defaultMat).applyGL(glParams.showNorms,false);
						glBegin(triangleDisplayType);
						lasMtlIndex=newMatlIndex;
					}

					if (showTextures)
					{
						getTriangleTexCoordinates(n,Tx1,Tx2,Tx3);
					}
				}

				if (pushTriangleNames)
				{
					glEnd();
					glLoadName(n);
					glBegin(triangleDisplayType);
				}
				else if (showWired)
				{
					glEnd();
					glBegin(triangleDisplayType);
				}

				//vertex 1
				if (N1)
					ccGL::Normal3v(N1);
				if (col1)
					glColor3ubv(col1);
				if (Tx1)
					glTexCoord2fv(Tx1);
				ccGL::Vertex3v(vertices->getPoint(tsi->i1)->u);

				//vertex 2
				if (N2)
					ccGL::Normal3v(N2);
				if (col2)
					glColor3ubv(col2);
				if (Tx2)
					glTexCoord2fv(Tx2);
				ccGL::Vertex3v(vertices->getPoint(tsi->i2)->u);

				//vertex 3
				if (N3)
					ccGL::Normal3v(N3);
				if (col3)
					glColor3ubv(col3);
				if (Tx3)
					glTexCoord2fv(Tx3);
				ccGL::Vertex3v(vertices->getPoint(tsi->i3)->u);
			}

			glEnd();

			if (pushTriangleNames)
				glPopName();

			if (showTextures)
			{
#ifdef TEST_TEXTURED_BUNDLER_IMPORT
				glPopAttrib(); //GL_COLOR_BUFFER_BIT 
#endif
				glBindTexture(GL_TEXTURE_2D, 0);
				glDisable(GL_TEXTURE_2D);
			}
		}

		if (stipplingEnabled())
			EnableGLStippleMask(false);

		if (colorMaterial)
			glDisable(GL_COLOR_MATERIAL);

		if (glParams.showNorms)
		{
			glDisable(GL_LIGHTING);
			glDisable((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 ? GL_RESCALE_NORMAL : GL_NORMALIZE));
		}

		if (pushName)
			glPopName();
	}
}
Esempio n. 10
0
void CVX_Sim::DrawBonds(void)
{
	Vec3D<> P1, P2;
	CVXS_Voxel* pV1, *pV2;

	float PrevLineWidth;
	glGetFloatv(GL_LINE_WIDTH, &PrevLineWidth);
	glLineWidth(3.0);
	glDisable(GL_LIGHTING);

	int iT = NumBond();
	glBegin(GL_LINES);
	glLoadName (-1); //to disable picking
	for (int i = 0; i<iT; i++) //go through all the bonds...
	{
		pV1 = BondArray[i].GetpV1(); pV2 = BondArray[i].GetpV2();

		CColor ThisColor = GetCurBondColor(i);
		P1 = pV1->GetCurPos();
		P2 = pV2->GetCurPos();

		glColor4f(ThisColor.r, ThisColor.g, ThisColor.b, ThisColor.a);
		//TODO:sweet curved bonds!
		//if (CurViewVox == RVV_SMOOTH){
		//	CQuat A1 = pV1->GetCurAngle();
		//	CQuat A2 = pV1->GetCurAngle();
		//}
		//else {
			if (ThisColor.a != 0.0) {glVertex3f((float)P1.x, (float)P1.y, (float)P1.z); glVertex3f((float)P2.x, (float)P2.y, (float)P2.z);}
//		}
	}
	glEnd();


	Vec3D<> Center;
	iT = NumVox();
	glPointSize(5.0);
	Vec3D<> tmp(0,0,0);
	for (int i = 0; i<iT; i++) //go through all the voxels...
	{
		//mostly copied from Voxel drawing function!
		Center = VoxArray[i].GetCurPos();
		glColor4d(0.2, 0.2, 0.2, 1.0);
		glLoadName (StoXIndexMap[i]); //to enable picking

		glPushMatrix();
		glTranslated(Center.x, Center.y, Center.z);
		glLoadName (StoXIndexMap[i]); //to enable picking

		//generate rotation matrix here!!! (from quaternion)
		Vec3D<> Axis;
		vfloat AngleAmt;
		CQuat<>(VoxArray[i].GetCurAngle()).AngleAxis(AngleAmt, Axis);
		glRotated(AngleAmt*180/3.1415926, Axis.x, Axis.y, Axis.z);
	
		Vec3D<> Scale = VoxArray[i].GetCurScale(); //show deformed voxel size
		glScaled(Scale.x, Scale.y, Scale.z);

		//LocalVXC.Voxel.DrawVoxel(&tmp, LocalVXC.Lattice.Lattice_Dim*(1+0.5*CurTemp * pMaterials[CVoxelArray[i].MatIndex].CTE), LocalVXC.Lattice.Z_Dim_Adj);
		LocalVXC.Voxel.DrawVoxel(&tmp, 0.2); //LocalVXC.GetLatticeDim()); //[i].CurSize.x); //, LocalVXC.Lattice.Z_Dim_Adj);
		
		glPopMatrix();
	}


	glLineWidth(PrevLineWidth);
	glEnable(GL_LIGHTING);

}
Esempio n. 11
0
void PickScene::display() 
{

	// ---- BEGIN Background, camera and axis setup
	
	// Clear image and depth buffer everytime we update the scene
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	// Initialize Model-View matrix as identity (no transformation
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Apply transformations corresponding to the camera position relative to the origin
	CGFscene::activeCamera->applyView();

	// Draw (and update) light
	light0->draw();

	// Draw axis
	axis.draw();


	// ---- END Background, camera and axis setup


	// ---- BEGIN feature demos

	materialAppearance->apply();

	// scale down a bit	
	glScalef(0.2, 0.2, 0.2);

	// picking example, the important parts are the gl*Name functions
	// and the code in the associted PickInterface class

	// Example 1: simple naming
	glPushMatrix();

	glPushName(-1);		// Load a default name

	for (int i=0; i< NUM_OBJS;i++)
	{
		glPushMatrix();
		glTranslatef(i*5,0,0);
		glLoadName(i);		//replaces the value on top of the name stack
		obj->draw();
		glPopMatrix();
	}
	glPopMatrix();

	// example 2: structured naming
	for (int r=0; r < NUM_ROWS; r++)
	{
		glPushMatrix();
		glTranslatef(0, r*4, 0);
		glLoadName(r);
		for (int c=0; c < NUM_COLS; c++)
		{
			glPushMatrix();
			glTranslatef(0,0,(c+1)*5);
			glRotatef(90,0,1,0);
			glPushName(c);
			obj->draw();
			glPopName();
			glPopMatrix();
		}
		glPopMatrix();
	}

	// ---- END feature demos

	// glutSwapBuffers() will swap pointers so that the back buffer becomes the front buffer and vice-versa
	glutSwapBuffers();
}