Esempio n. 1
0
void display(void)
{
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity ();
    glTranslatef(0,0,-2.5);
    /*
    	glBegin(GL_TRIANGLES);
    	glVertex3f(0,2,0);
    	glVertex3f(3,0,0);
    	glVertex3f(-3,0,0);
    	glEnd();
    */
    /* SIMPLE FLAT POLYGON
    	glBegin(GL_POLYGON);
    	glVertex3f(1.0f, 1.0f , 0.0f);
    	glVertex3f(1.0f, -1.0f, 0.0f);
    	glVertex3f(-1.0f, -1.0f, 0.0f);
    	glVertex3f(-1.0f, 1.0f, 0.0f);
    	glEnd();
    */
    /*
    	glBegin(GL_TRIANGLES);
    	glColor3f(1.0f,0.0f,0.0f);
    	glVertex3f( 0.0f, 1.0f, 0.0f);
    	glColor3f(0.0f,1.0f,0.0f);
    	glVertex3f(-1.0f,-1.0f, 0.0f);
    	glColor3f(0.0f,0.0f,1.0f);
    	glVertex3f( 1.0f,-1.0f, 0.0f);
    	glEnd();
    */
    glPushMatrix();
    glRotatef(ypoz,0,1,0);
    glRotatef(zpoz,0,0,1);
    drawmodel_box();
    glPopMatrix();
    glutSwapBuffers();
}
Esempio n. 2
0
void display()
{
	glClearColor(0.0, 0.0, 0.0, 0.0);
    	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);


/*	glPushMatrix();
	glTranslatef(xavg,yavg,0);
	glutSolidCube(200);
	glPopMatrix();
/*

	glBegin(GL_QUADS);
		glVertex3f(xr,xb,0);	
		glVertex3f(xb,yb,0);	
		glVertex3f(xl,yl,0);
		glVertex3f(xt,yt,0);
	glEnd();
*/
///////////////////////////////////////////////////////////nishanthprakash20///////////////////////////////////////////////////
	captured=cvQueryFrame(video1);
	disp=cvCreateImage(cvGetSize(captured),IPL_DEPTH_8U,3);	
	eroded=cvCreateImage(cvGetSize(captured),IPL_DEPTH_8U,3);	
	dilated=cvCreateImage(cvGetSize(captured),IPL_DEPTH_8U,3);

//	data=cvGet2D(captured,240,320);
//	printf("%f,%f,%f\n",data.val[0],data.val[1],data.val[2]);
	

	thresh1=150;
	thresh2=100;
	thresh3=100;


	for(i=0;i<disp->height;i++)
	for(j=0;j<disp->width;j++)
		{
			data=cvGet2D(captured,i,j);
			
			if(data.val[1]>thresh1&&data.val[2]<thresh2&&data.val[0]<thresh3)
			{	
				cvSet2D(disp,i,j,data);
			}
		}

	cvErode(disp,eroded,NULL,1);
	cvDilate(eroded,dilated,NULL,4);
	for(i=0;i<disp->height;i++)
	for(j=0;j<disp->width;j++)
		{
			data=cvGet2D(dilated,i,j);
			
			if(data.val[1]>thresh1&&data.val[2]<thresh2&&data.val[0]<thresh3)
			{	goto donetop;
				
			}
		}
	donetop:
	xt=j;
	yt=i;
	
	for(i=479;i>0;i--)
	for(j=0;j<disp->width;j++)
		{
			data=cvGet2D(dilated,i,j);
			
			if(data.val[1]>thresh1&&data.val[2]<thresh2&&data.val[0]<thresh3)
			{	goto doneleft;
				
			}
		}
	doneleft:
	xb=j;
	yb=i;
	
	inclination=((float)atan((yt-yb)/(xt-xb))-(float)atan(10.0/21))*180/3.14;
	if(inclination<0)	inclination+=60;
	printf("%f\n",inclination);
	
	cvNamedWindow("Cap");
	cvShowImage("Cap",dilated);
	cvWaitKey(3);

//*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    	glColor3f(1.0, 1.0, 1.0);
	glPushMatrix();
	glTranslatef(0,0,-5);
	glRotatef(inclination,0,0,1);

	glScalef(100,100,100);
	glColor3f(0.0f,0.0f,0.0f);
	drawmodel_box();
		glColor3f(1.0f,1.0f,1.0f);
		drawmodel_box2();
		glColor3f(1.0f,1.0f,1.0f);
		drawmodel_box3();
		glColor3f(1.0f,1.0f,1.0f);
		drawmodel_box4();
		glColor3f(0.2f,0.2f,1.0f);
		drawmodel_box5();									//remove this
	//glScalef(0.01,0.01,0.01);
//glTranslatef(0,0,5);
	glPopMatrix();
	
  	glutSwapBuffers();
}
Esempio n. 3
0
void display(void)
{
	float ypoz1;
	ypoz1=ypoz*3.14/180;
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//	gluLookAt(10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	glLoadIdentity ();
	GLfloat lightColor0[] = {0.6f, 0.6f, 0.6f, 1.0f};
	GLfloat lightPos0[] = {txpos-2.0, 2.0f, tzpos-2.0, 1.0f}; //positioning the light
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
	if(camera==0)
	{

		gluLookAt(9.0,16.0,9.0,8.0,0.0,8.0, 0.0, 0.0 ,1.0);
	}
	if(camera==1)
	{
		//		gluLookAt(-3.0, 6.0,3.0, -4.0, 0.0, -5.0, 0.0, 1.0 ,0.0);
		gluLookAt(txpos-2.0*sin(ypoz1),typos+1.0  ,tzpos-2.0*cos(ypoz1),txpos/*+2.0*sin(ypoz1)*/,typos,tzpos/*+10.0*cos(ypoz1)*/ , 0.0, 1.0 ,0.0);
	}
	if(camera==2)
	{

		gluLookAt(txpos,typos+2,tzpos,txpos+10.0*sin(ypoz1),typos-2.0,tzpos+10.0*cos(ypoz1) , 0.0, 1.0 ,0.0);
	}
	if(camera==3)
	{

		gluLookAt(9.0,zoom,9.0,hel_x,0,hel_z, 0.0, 0.0 ,1.0);
		//gluLookAt(txpos,typos+2,tzpos-12,txpos+2.0*sin(ypoz1),typos-1.0,tzpos+-12+10.0*cos(ypoz1) , 0.0, 1.0 ,0.0);
	}
	if(camera==4)
	{
		float h_y;
		if(matrix[sel_i][sel_j].type==0)
		{
			h_y=0.5;
		}
		else
			h_y=h-1.0;

		gluLookAt(matrix[sel_i][sel_j].x1+1,h_y,matrix[sel_i][sel_j].z1+1,txpos,typos-1.0,tzpos , 0.0, 1.0 ,0.0);
	}
	GLfloat ambientLight[]={0.3f,0.3f,0.3f,1.0f};
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientLight);
	//glTranslatef(txpos,typos,tzpos+-12.0);
//	printf("before\n");
	for(int g=0;g<n_tiles;g++)
	  {
	  for(int h2=0;h2<n_tiles;h2++)
	  {
	  if(matrix[g][h2].type==2)
	  {
		  matrix[g][h2].height=(h-1.0);
//		  printf("look here %f %f\n",matrix[g][h2].height,h);
	  }
	  else if(matrix[g][h2].type==4)
	  {
		  matrix[g][h2].height=2.0*h-1.5;
//		  printf("look here %f %f\n",matrix[g][h2].height,h);
	  }
	  }
	  }
	if(((matrix[tz][tx].type==4 && matrix[tz][tx].draw==1 )|| matrix[tz][tx].type==2) && jump==0 )
	{
		typos=matrix[tz][tx].height;
	}
	else if(dead==0 && matrix[tz][tx].type==4 && matrix[tz][tx].draw==0)
	{
		dead=1;
		fall();
	}
	glPushMatrix();	
	//	glScalef(0.5,0.5,0.5);
	glTranslatef(txpos,typos+0.5,tzpos);
	glScalef(0.5,0.5,0.5);
	// I added these to be able to rotate the whole scene so you can see the box and textures
	glRotatef(ypoz,0,1,0);
	glRotatef(zpoz,0,0,1);	
	//	glTranslatef(txpos,typos,tzpos+-2.0);	
	if(!pmodel1)
	{
		pmodel1 = glmReadOBJ("man3.obj");
		//	pmodel2 = glmReadOBJ("terrain.obj");
	}
	//		pmodel3 = glmReadOBJ("ter.obj");
	drawmodel_box(pmodel1);
	glPopMatrix();
/*	glPushMatrix();
	glRotatef(90.0,1,0,0);
	DrawLine(-10.0,-2.0,-10.0,18.0,12.0,1.0,0.0,0.0);
	glPopMatrix();*/
	glPushMatrix();

	glTranslatef(0.0,-1.0,0.0);
	/*	glScalef(6.0,1.1,8.0);
	// I added these to be able to rotate the whole scene so you can see the box and textures
	glRotatef(0.0,0,1,0);
	glRotatef(0.0,0,0,1);
	//	glRotatef(30,1,0,0);
	drawmodel_box(pmodel2);
	//	drawmodel_box(pmodel3);
	glPopMatrix();*/
	if(flag1==0)
	{
		h=h+0.01;
	}
	else
		h=h-0.01;
	if(h>2.7)
		flag1=1;
	if(h<0.05)
		flag1=0;



	for(int ij=0;ij<n_tiles;ij++)
	{
		for(int ji=0;ji<n_tiles;ji++)
		{
			glPushMatrix();
			matrix[ij][ji].x1=2.0*ji-1;
			matrix[ij][ji].x2=2.0*ji+1;
			matrix[ij][ji].z1=2.0*ij-1;
			matrix[ij][ji].z2=2.0*ij+1;
			glTranslatef(2.0*ji,0,2.0*ij);
			DrawCube(ij,ji);
			glPopMatrix();
		}


	}
	glPopMatrix();
	/*
	   glMatrixMode(GL_MODELVIEW);

	   glLoadIdentity();
	   if(camera==1)
	   {
	   gluLookAt(-3.0, 6.0,3.0, -4.0, 0.0, -5.0, 0.0, 1.0 ,0.0);
	   }
	   if(camera==2)
	   {
	   float ypoz1;
	   ypoz1=ypoz*3.14/180;
	   gluLookAt(txpos,typos ,tzpos-12,txpos+2.0*sin(ypoz1),typos-1.0,tzpos-12+10.0*cos(ypoz1) , 0.0, 1.0 ,0.0);
	   }
	//glScalef(2.0,1.0,40.0);
	//	glPushMatrix();
	glRotatef(-_angle, 0.0f, 1.0f, 0.0f);

	glTranslatef(-4*1.5, -2.0, -5.0f);
	glRotatef(0,1,0,0);

	for(float j=0.0;j>(-8*1.5);j-=1.5)

	{

	k++;

	for(i=0.0;i<(4*3.0);i+=3.0)

	{

	if(k%2==0)

	{

	glPushMatrix();

	glTranslatef(i,0.0,j);

	glCallList(_displayListId_blackArea);

	glPopMatrix();



	}


	else

	{

	glPushMatrix();

	glTranslatef(i+1.5,0.0,j);

	glCallList(_displayListId_blackArea);

	glPopMatrix();



	}

	}

	}

	for(float j=0.0;j>(-8*1.5);j-=1.5)

	{

	k++;

	for(i=0.0;i<(4*3.0);i+=3.0)

	{

		if(k%2!=0)

		{

			glPushMatrix();

			glTranslatef(i,0.0,j);

			glCallList(_displayListId_whiteArea);

			glPopMatrix();



		}

		else

		{

			glPushMatrix();

			glTranslatef(i+1.5,0.0,j);

			glCallList(_displayListId_whiteArea);

			glPopMatrix();



		}

	}

}*/
//	glPopMatrix();

//glutSwapBuffers();








//Sleep(5);
glutSwapBuffers();


}