Esempio n. 1
0
bool GeradMoveLeft(float &x, float &y)
{
	 x -= Gerad.GetSpeed();
			if(Timer->elapsed(walkTimer, STOPTIME))
			{
			    Gerad.Setxy(x, y);
				walkTimer = Timer->time();
			}
			for(int i = 0;i < currentLocation->ObjectNum;i++)
			{
				if(currentLocation->objects[i].IsWithin(x, y))
				{
					x += Gerad.GetSpeed();
					Gerad.SetStopStatus();
					Gerad.Setxy(x, y);
					return true;
				}
			}
			if(x <= 0)
			if(currentLocation->left != NULL)
			{
				    currentLocation = currentLocation->left;
				    x = 462;
				    background.load(currentLocation->getName());
				    background.loadGLTextures();
			}
			else {x = 0; Gerad.SetStopStatus();}
		    if(Timer->elapsed(walkTimer, STOPTIME))
			{
			    Gerad.Setxy(x, y);
				walkTimer = Timer->time();
			}
			return true;
}
void image_print3(){
	
	int r,c;	
	for(r=0;r<pic3.width;r++)
	{
	  for(c=0;c<pic3.height;c++)
	  {
		  glBegin(GL_POINTS);

		  float rr=(float)(pic3.pixel(r,c,0));
		  float gg=(float)(pic3.pixel(r,c,1));
		  float bb=(float)(pic3.pixel(r,c,2));

		  glColor3f(rr/255,gg/255.0,bb/255.0);

		  glVertex2d(r,c);

		  glEnd();
	  }
	}	

	glTranslatef(0,-250,0);

	for(r=0;r<pic3.width;r++)
	{
	  for(c=0;c<pic3.height;c++)
	  {
		  glBegin(GL_POINTS);

		  double magn=(F_real2[r][c]*F_real2[r][c]);

		  magn+=(F_img2[r][c]*F_img2[r][c]);
		  magn=sqrt(magn);

		  float rr=(float)magn;
		  rr/=255.0;

		  glColor3f(rr,rr,rr);
		  glVertex2d(r,c);

		  glEnd();
	  }
	}
	
	glTranslatef(0,250,0);


}
void fourier_transform4(){

	int i,j,n,m,k,l;

	// take input . . .  f(i,j)
	n=pic4.height;
	m=pic4.width;
	for(i=0;i<pic4.height;i++)
	{
	  for(j=0;j<pic4.width;j++)
	  {
		  float rr=(float)(pic4.pixel(i,j,0));
		  f_real[i][j]=rr;
		  f_img[i][j]=0;
		  if((i+j)%2){
			f_real[i][j]=-rr;
			f_img[i][j]=-0;
		  }
	  }	
	}

	// calculating . . .  P(i,j);
	for(j=0;j<m;j++){
		int k;
		for (k = 0; k < n; k++) {  /* For each output element */
			double sumreal = 0;
			double sumimag = 0;
			int t;
			for (t = 0; t < n; t++) {  /* For each input element */
				double angle = 2 * M_PI * t * k / (double)n;
				sumreal +=  f_real[t][j] * cos(angle) + f_img[t][j] * sin(angle);
				sumimag += -f_real[t][j] * sin(angle) + f_img[t][j] * cos(angle);
			}
			P_real[k][j] = sumreal;
			P_img[k][j] = sumimag;
		}
	}

	// taking Input . . .  F(i,j);
	for(i=0;i<n;i++){
		int k;
		for (k = 0; k < m; k++) {  /* For each output element */
			double sumreal = 0;
			double sumimag = 0;
			int t;
			for (t = 0; t < m; t++) {  /* For each input element */
				double angle = 2 * M_PI * t * k / (double)n;
				sumreal +=  P_real[i][t] * cos(angle) + P_img[i][t] * sin(angle);
				sumimag += -P_real[i][t] * sin(angle) + P_img[i][t] * cos(angle);
			}
			F_real3[i][k] = sumreal/(double)m;
			F_img3[i][k] = sumimag/(double)m;
		}
	}

	puts("FINISH");
	

	return ;
}
Esempio n. 4
0
bool ProcessFrame()
{ 
	if(InMenu)
	{
		return true;
	}
	float x, y;
	Gerad.Getxy(x, y);
	if(Gerad.GetWalk())
	{
		if(InInterior)
		{
			if(CheckForExit(x, y))
			{
				int x, y;
				exitLocation->interiors[currentInterior].getxy(x, y);
				y += 20;
				Gerad.Setxy(x, y);
				currentLocation = exitLocation;
				Gerad.SetFront();
				background.load(currentLocation->getName());
				background.loadGLTextures();
				InInterior = false;
				return true;
			}
		}
        interiorLoop(x, y);
	    if(Gerad.GetRight())
		{
	        return GeradMoveRight(x, y);
        }
		else if(Gerad.GetBack())
        {
	        return GeradMoveBack(x, y);
		}
	    else if(Gerad.GetFront())
		{
	        return GeradMoveFront(x, y);
        }
        else if(Gerad.GetLeft())
        {
    	   return GeradMoveLeft(x, y);
        }
	}

  return true;
}
Esempio n. 5
0
bool GeradMoveBack(float &x, float &y)
{
	y -= Gerad.GetSpeed();
			if(Timer->elapsed(walkTimer, STOPTIME))
			{
			    Gerad.Setxy(x, y);
				walkTimer = Timer->time();
			}
			for(int i = 0;i < currentLocation->ObjectNum;i++)
			{
				if(currentLocation->objects[i].IsWithin(x, y))
				{
					y += Gerad.GetSpeed();
					Gerad.SetStopStatus();
					Gerad.Setxy(x, y);
					return true;
				}
			}
			if(y <= 0)
			{
				if(currentLocation->top != NULL)
				{
				    currentLocation = currentLocation->top;
					if(topInterior)InInterior = true;
				    y = 462;
				    background.load(currentLocation->getName());
				    background.loadGLTextures();
				}
				else
				{
					y = 0;
					Gerad.SetStopStatus();
				}
			}
		    if(Timer->elapsed(walkTimer, STOPTIME))
			{
			    Gerad.Setxy(x, y);
				walkTimer = Timer->time();
			}
			return true;
}
Esempio n. 6
0
void interiorLoop(float x, float y)
{
	for(int i = 0; i < currentLocation->InteriorNum; i++)
    {
			if(checkInterior(i))
			{
				InInterior = true;
				currentInterior = i;
				currentLocation->interiors[i].getstartxy(x, y);
				y += 20;
				Gerad.Setxy(x, y);
				currentLocation->interiors[i].setdirection();
				currentLocation->interiors[i].exit = currentLocation;
				exitLocation = currentLocation;
				currentLocation = currentLocation->interiors[i].getLocation();
				background.load(exitLocation->interiors[i].getLocation()->getName());
				background.loadGLTextures();
				return;
			}
	}
}
Esempio n. 7
0
BMPError BMPLoad(std::string fname,BMPClass& bmp)
{
	FILE * f=fopen(fname.c_str(),"rb");		//open for reading in binary mode
	if(!f) return BMPNOOPEN;
	char header[54];
	fread(header,54,1,f);			//read the 54bit main header

	if(header[0]!='B' || header[1]!='M') 
	{
		fclose(f);
		return BMPNOTABITMAP;		//all bitmaps should start "BM"
	}

	if(sizeof(int)==4)	//Annoyingly I can't just assume this
	{
		bmp.width=*(int*)(header+18);
		bmp.height=*(int*)(header+22);
	}
	else
	{
		bmp.width=header[18]+256*header[19]+256*256*header[20]+256*256*256*header[21];
		bmp.height=header[22]+256*header[23]+256*256*header[24]+256*256*256*header[25];
	}
	bmp.allocateMem();

	int bits=int(header[28]);		//colourdepth

	int x,y,c;
	BYTE cols[256*4];
	switch(bits)
	{
	case(24):
		fread(bmp.bytes,bmp.width*bmp.height*3,1,f);	//24bit is easy
		for(x=0;x<bmp.width*bmp.height*3;x+=3)			//except the format is BGR, grr
		{
			BYTE temp=bmp.bytes[x];
			bmp.bytes[x]=bmp.bytes[x+2];
			bmp.bytes[x+2]=temp;
		}
		break;

	case(8):
		fread(cols,256*4,1,f);							//read colortable
		for(y=0;y<bmp.height;++y)						//(Notice 4bytes/col for some reason)
			for(x=0;x<bmp.width;++x)
			{
				BYTE byte;			
				fread(&byte,1,1,f);						//just read byte					
				for(int c=0;c<3;++c)
					bmp.pixel(x,y,c)=cols[byte*4+2-c];	//and look up in the table
			}
		break;

	case(4):
		fread(cols,16*4,1,f);
		for(y=0;y<256;++y)
			for(x=0;x<256;x+=2)
			{
				BYTE byte;
				fread(&byte,1,1,f);						//as above, but need to exract two
				for(c=0;c<3;++c)						//pixels from each byte
					bmp.pixel(x,y,c)=cols[byte/16*4+2-c];
				for(c=0;c<3;++c)
					bmp.pixel(x+1,y,c)=cols[byte%16*4+2-c];
			}
		break;

	//NOT CURRENTLY WORKING PROPERLY
	//case(1):
	//	fread(cols,8,1,f);		//colourtable
	//	for(y=0;y<256;++y)
	//		for(x=0;x<256;x+=8)
	//		{
	//			BYTE byte;
	//			fread(&byte,1,1,f);
	//			//The idea here is that every byte is eight pixels
	//			//so I'm shifting the byte to the relevant position, then masking out
	//			//all but the lowest bit in order to get the index into the colourtable.
	//			for(int x2=0;x2<8;++x2)
	//			{
	//				for(int c=0;c<3;++c)
	//					bmp.pixel(x+x2,y,c)=cols[((byte>>(7-x2))&1)*4+2-c];
	//			}
	//		}
	//	break;
	default:
		fclose(f);
		return BMPUNKNOWNFORMAT;
	}

	fclose(f);
	if(ferror(f)) return BMPFILEERROR;

	return BMPNOERROR;
}
Esempio n. 8
0
BMPError BMPLoad(std::string fname,BMPClass& bmp)
{
	if(sizeof(int)!=4) return BMPBADINT;
		
	FILE* f=fopen(fname.c_str(),"rb");		//open for reading in binary mode
	if(!f) return BMPNOOPEN;
	char header[54];
	fread(header,54,1,f);			//read the 54bit main header

	if(header[0]!='B' || header[1]!='M') 
	{
		fclose(f);
		return BMPNOTABITMAP;		//all bitmaps should start "BM"
	}

	//it seems gimp sometimes makes its headers small, so we have to do this. hence all the fseeks
	int offset=*(unsigned int*)(header+10);
	
	bmp.width=*(int*)(header+18);
	bmp.height=*(int*)(header+22);
	//now the bitmap knows how big it is it can allocate its memory
	bmp.allocateMem();

	int bits=int(header[28]);		//colourdepth

	int x,y,c;
	BYTE cols[256*4];				//colourtable
	switch(bits)
	{
	case(24):
		fseek(f,offset,SEEK_SET);
		fread(bmp.bytes,bmp.width*bmp.height*3,1,f);	//24bit is easy
		for(x=0;x<bmp.width*bmp.height*3;x+=3)			//except the format is BGR, grr
		{
			BYTE temp=bmp.bytes[x];
			bmp.bytes[x]=bmp.bytes[x+2];
			bmp.bytes[x+2]=temp;
		}
		break;

	case(8):
		fread(cols,256*4,1,f);							//read colortable
		fseek(f,offset,SEEK_SET);
		for(y=0;y<bmp.height;++y)						//(Notice 4bytes/col for some reason)
			for(x=0;x<bmp.width;++x)
			{
				BYTE byte;			
				fread(&byte,1,1,f);						//just read byte					
				for(int c=0;c<3;++c)
					bmp.pixel(x,y,c)=cols[byte*4+2-c];	//and look up in the table
			}
		break;

	case(4):
		fread(cols,16*4,1,f);
		fseek(f,offset,SEEK_SET);
		for(y=0;y<256;++y)
			for(x=0;x<256;x+=2)
			{
				BYTE byte;
				fread(&byte,1,1,f);						//as above, but need to exract two
				for(c=0;c<3;++c)						//pixels from each byte
					bmp.pixel(x,y,c)=cols[byte/16*4+2-c];
				for(c=0;c<3;++c)
					bmp.pixel(x+1,y,c)=cols[byte%16*4+2-c];
			}
		break;

	case(1):
		fread(cols,8,1,f);
		fseek(f,offset,SEEK_SET);
		for(y=0;y<bmp.height;++y)
			for(x=0;x<bmp.width;x+=8)
			{
				BYTE byte;
				fread(&byte,1,1,f);
				//Every byte is eight pixels
				//so I'm shifting the byte to the relevant position, then masking out
				//all but the lowest bit in order to get the index into the colourtable.
				for(int x2=0;x2<8;++x2)
					for(int c=0;c<3;++c)
						bmp.pixel(x+x2,y,c)=cols[((byte>>(7-x2))&1)*4+2-c];
			}
		break;

	default:
		fclose(f);
		return BMPUNKNOWNFORMAT;
	}

	if(ferror(f))
	{
		fclose(f);
		return BMPFILEERROR;
	}
	
	fclose(f);

	return BMPNOERROR;
}
Esempio n. 9
0
void mainmenu(){ /// have to change the color (sajid)

	//puts("MainMenu");
	
	glBegin( GL_POINTS );
	glColor3f(1,0,0);

	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){		
			glVertex2d( i,j);
		}
	}
	
	glEnd();

	

	glColor3f(0,0,0);

	glPushMatrix();
    glLoadIdentity();
	glTranslatef(20,100,0);

	//texture maping of left field
	int r,c,r1;
	double p1,c1;
	
	for(r=0;r<menu5.width;r++)
	{
	  for(c=0;c<menu5.height;c++)
	  {
		  glBegin(GL_POINTS);
		  
		  float rr=(float)(menu5.pixel(r,c,0));
		  float gg=(float)(menu5.pixel(r,c,1));
		  float bb=(float)(menu5.pixel(r,c,2));		  
		  
		  glColor3f(rr/255,gg/255.0,bb/255.0);

		  if(!print_flag && j<30) printf("%3.0f,%3.0f,%3.0f,  ",rr,gg,bb);
		  
		  glVertex2d(r,c);		  
		  
		  glEnd();
	  }

	  if(!print_flag)puts("");
	
	}

	if(!print_flag) printf("%d %d\n",r,c);
	
	print_flag=1;

	

	glPopMatrix();
	
	glPushMatrix();
    glLoadIdentity();
	glTranslatef(250,100,0);

	for(r=0,r1=0;r<=menu5.width;r++,r1+=1)
	{
	  for(c=0,c1=0;c<=menu5.height;c++,c1+=1.55)
	  {
		  glBegin(GL_POINTS);
		  float rr=(float)(menu5.pixel(r,c,0));
		  float gg=(float)(menu5.pixel(r,c,1));
		  float bb=(float)(menu5.pixel(r,c,2));
		  glColor3f(rr/255,gg/255.0,bb/255.0);
		  for(p1=0;p1<=2;p1+=.25){
			  glVertex2d(r1+p1,c1+p1);
		  }
		  glEnd();
	  }

	}

	glPopMatrix();

}
Esempio n. 10
0
bool LoadImages()
{
  background.load(currentLocation->getName());
  background.loadGLTextures();

  int r=254, g=0, b=254, frameCount=12, frame=0;    // r,g,b is background color to be filtered, frameCount and frame number
  mario1sprite=new CBaseSprite(frameCount, background.getViewportWidth(), background.getViewportHeight());
  mario1sprite->loadFrame(frame,   "Gerad - Walk (Right)1.bmp",r, g, b);
  mario1sprite->loadFrame(frame+1,   "Gerad - Walk (Right)2.bmp",r, g, b);
  mario1sprite->loadFrame(frame+2, "Gerad - Walk (Right)3.bmp", r, g, b);
  mario1sprite->loadFrame(frame+3, "Gerad - Walk (Left)1.bmp", r, g, b);
  mario1sprite->loadFrame(frame+4, "Gerad - Walk (Left)2.bmp", r, g, b);
  mario1sprite->loadFrame(frame+5, "Gerad - Walk (Left)3.bmp", r, g, b);
  mario1sprite->loadFrame(frame+6, "Gerad - Walk (Front)1.bmp", r, g, b);
  mario1sprite->loadFrame(frame+7, "Gerad - Walk (Front)2.bmp", r, g, b);
  mario1sprite->loadFrame(frame+8, "Gerad - Walk (Front)3.bmp", r, g, b);
  mario1sprite->loadFrame(frame+9, "Gerad - Walk (Back)1.bmp", r, g, b);
  mario1sprite->loadFrame(frame+10, "Gerad - Walk (Back)2.bmp", r, g, b);
  mario1sprite->loadFrame(frame+11, "Gerad - Walk (Back)3.bmp", r, g, b);
  mario1sprite->loadGLTextures();
  InventorySprite = new CBaseSprite(1, background.getViewportWidth(), background.getViewportHeight());
  InventorySprite->loadFrame(frame, "bckgnd1.bmp", r, g, b);
  InventorySprite->loadGLTextures();
  NPC1Sprite = new CBaseSprite(1, background.getViewportWidth(), background.getViewportHeight());
  NPC1Sprite->loadFrame(frame, "Scholar1 (Front).bmp", r, g, b);
  NPC1Sprite->loadGLTextures();
  NPC2Sprite = new CBaseSprite(1, background.getViewportWidth(), background.getViewportHeight());
  NPC2Sprite->loadFrame(frame, "Old Woman (Front).bmp", r, g, b);
  NPC2Sprite->loadGLTextures();
  TextboxSprite = new CBaseSprite(1, background.getViewportWidth(), background.getViewportHeight());
  TextboxSprite->loadFrame(frame, "textbox.bmp", r, g, b);
  TextboxSprite->loadGLTextures();
  return true;
}
Esempio n. 11
0
void display()
{
   ComposeFrame();
   background.drawGLbackground();
   if (!InMenu)
   {
	   if(text1)
	   {
		   Textbox.draw(0);
		   textPrintf(110/512.0, 420/512.0, font2, "Please save the princess.", color);
	   }
	   else if(text2)
	   {
		   Textbox.draw(0);
		   textPrintf(90/512.0, 420/512.0, font2, "I always knew that old wizard was no good.", color);
	   }
	   drawPeople();
       if(Gerad.GetWalk())
       {
           if(Gerad.GetRight())
           {
               DisplayDirection(0, 1, 2);
           }
           else if(Gerad.GetLeft())
           {
    	       DisplayDirection(3, 4, 5);
           }
           else if(Gerad.GetBack())
           {
	           DisplayDirection(9, 10, 11);
           }
           else if(Gerad.GetFront())
           {
	           DisplayDirection(6, 7, 8);
           }
       }
       else
       {
	       if(Gerad.GetRight())
           {
               DisplayDirection(0, 0, 0);
           }
           else if(Gerad.GetLeft())
           {
	           DisplayDirection(3, 3, 3);
           }
           else if(Gerad.GetBack())
           {
	           DisplayDirection(9, 9, 9);
           }
           else if(Gerad.GetFront())
           {
	           DisplayDirection(6, 6, 6);
           }
	   }
   }
   else
   {
	   inventory.draw();
   }

   glutSwapBuffers();
}