예제 #1
0
void sidebarMouse(int btn, int state, int x, int y)
{
  int lineUp   = 6;
  int lineDown = 7;

  if (btn != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return;

  if (x < 180 && x>= 5) {
    if (y >= DEF_TEXT_Y_OFFSET*++lineUp+5 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(DEF_OBJ_SEL);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_BASIC);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_ADV);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_CONE);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_ADV_CONE);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_SQUARE);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_ADV_SQUARE);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_FIRE);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_FIRE2);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_ICE);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_ICE2);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_EARTH);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_EARTH2);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_POISON);
    else if (y >= DEF_TEXT_Y_OFFSET*++lineUp+9 && y < DEF_TEXT_Y_OFFSET*++lineDown+9) changeObjectSelected(OBJ_POISON2);
  }

  redisplayAll();
}
예제 #2
0
/*
 *  main()
 *  ----
 *  Start up GLUT and tell it what to do
 */
int main(int argc,char* argv[])
{
  initializeGlobals();
  /* screencast specific variables */
  windowName = "OpenGL screenscasts 17: Animation part 2";
  screencastID = 17;
  toggleAxes = 0;
  toggleAnimation = 0;

  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutInitWindowSize(windowWidth,windowHeight);
  glutInitWindowPosition(450,350);
  glutCreateWindow(windowName);

  glutDisplayFunc(display);
  glutReshapeFunc(displayReshape);
  glutKeyboardFunc(windowKey);
  glutSpecialFunc(windowSpecial);

  initializeTextures();
  initializeObjs();
  timer(toggleAnimation);

  redisplayAll();
  glutMainLoop();
  return 0;
}
예제 #3
0
/*
 *  main()
 *  ----
 *  Start up GLUT and tell it what to do
 */
int main(int argc,char* argv[])
{
  initializeGlobals();
  /* screencast specific variables */
  windowName = "OpenGL screenscasts 14: Textures part 1";
  screencastID = 14;
  dim = 4;
  fov = 50;
  th = -25;
  ph = 15;
  ecX = -0.4;
  ecZ = -2.0;
  distance = 2;

  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutInitWindowSize(windowWidth,windowHeight);
  glutCreateWindow(windowName);

  glutDisplayFunc(display);
  glutReshapeFunc(displayReshape);
  glutKeyboardFunc(windowKey);
  glutSpecialFunc(windowSpecial);

  initializeTextures();

  redisplayAll();
  glutMainLoop();
  return 0;
}
/*
 *  windowSpecial()
 *  ------
 *  GLUT calls this routine when an arrow key is pressed
 */
void windowSpecial(int key,int x,int y)
{
  int modifiers = glutGetModifiers();
  /*  If holding shift, then rotate/elevate */
  if (modifiers == GLUT_ACTIVE_SHIFT) {
    /*  Right/Left - rotate */
    if (key == GLUT_KEY_RIGHT) th += 5;
    else if (key == GLUT_KEY_LEFT) th -= 5;
    /*  Up/Down - elevation */
    else if (key == GLUT_KEY_UP) ph += 5;
    else if (key == GLUT_KEY_DOWN) ph -= 5;
  }
  /*  Otherwise, just shift the screen */
  else {
    /*  Shift */
    if (key == GLUT_KEY_RIGHT) ecX += .5;
    else if (key == GLUT_KEY_LEFT) ecX -= .5;
    else if (key == GLUT_KEY_DOWN) ecZ += .5;
    else if (key == GLUT_KEY_UP) ecZ -= .5;
  }

  /*  Keep angles to +/-360 degrees */
  th %= 360;
  ph %= 360;

  redisplayAll();
}
예제 #5
0
파일: Camera.c 프로젝트: AM1244/Blog
//-------------------------------------------------------------------------
//  Reset Object Transformations in the scene
//-------------------------------------------------------------------------
void reset()
{
    translate_x = translate_y = translate_z = 0.0f;
    rot_x = rot_y = rot_z = 0.0f;
    scale_x = scale_y = scale_z = 1.0f;
    previousX = previousY = previousZ = 0;
    redisplayAll();
}
예제 #6
0
void SpecialKey(int key, int x, int y)
{
	switch (key) {
		case GLUT_KEY_UP: estado.teclas.up =GL_TRUE;
			break;
		case GLUT_KEY_DOWN: estado.teclas.down =GL_TRUE;
			break;
		case GLUT_KEY_LEFT: estado.teclas.left =GL_TRUE;
			break;
		case GLUT_KEY_RIGHT: estado.teclas.right =GL_TRUE;
			break;
		case GLUT_KEY_F1: estado.vista[JANELA_TOP]=!estado.vista[JANELA_TOP];
			break;
		case GLUT_KEY_F2: estado.vista[JANELA_NAVIGATE]=!estado.vista[JANELA_NAVIGATE];
			break;
		case GLUT_KEY_PAGE_UP: 
                  if(estado.camera.fov>20)
                  {
                    estado.camera.fov--;
                    glutSetWindow(estado.navigateSubwindow);
                    reshapeNavigateSubwindow(glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT));
                    redisplayAll();
                  }
			break;
		case GLUT_KEY_PAGE_DOWN: 
                  if(estado.camera.fov<130)
                  {
                    estado.camera.fov++;
                    glutSetWindow(estado.navigateSubwindow);
                    reshapeNavigateSubwindow(glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT));
                    redisplayAll();
                  }
			break;
	}

}
예제 #7
0
void glutTime(int toggle)
{
  if (gameStarted) {
    if (gamePaused != DEF_GAME_PAUSED) {
      moveTowerTops();
      moveBalls();
      checkCollisions();
      moveMinions();
      checkCollisions();
      checkTowerRange();
    }
    glutTimerFunc(50,glutTime,0);
  }
  redisplayAll();
}
/*
 *  windowKey()
 *  ------
 *  GLUT calls this routine when a non-special key is pressed
 */
void windowKey(unsigned char key,int x,int y)
{
  /*  Exit on ESC */
  if (key == 27) exit(0);
  else if (key == 'x' || key == 'X') toggleAxes = 1-toggleAxes;
  else if (key == 'v' || key == 'V') toggleParams = 1-toggleParams;
  else if (key == 'o' || key == 'O') toggleOverlay = 1-toggleOverlay;
  /*  Spacebar */
  else if (key == 32) toggleAnimation = 1-toggleAnimation;
  /*  Change field of view angle */
  else if (key == '-' && key>1) fov--;
  else if (key == '+' && key<179) fov++;
  /*  Change dimensions */
  else if (key == 'I') dim += 0.2;
  else if (key == 'i' && dim>1) dim -= 0.2;
  /*  BEGIN LIGHTING FUNCTIONALITY */
  /*  Toggle lighting */
  else if (key == 'l' || key == 'L') toggleLight = 1-toggleLight;
  /*  Move light (rotation) */
  else if (key == '<') lightPh -= 5;
  else if (key == '>') lightPh += 5;
  /*  Light elevation */
  else if (key == '[') lightY -= 0.5;
  else if (key == ']') lightY += 0.5;
  /*  Light distance */
  else if (key == '{') distance -= 1;
  else if (key == '}') distance += 1;
  /*  Ambient level */
  else if (key == 'a' && ambient>0) ambient -= 5;
  else if (key == 'A' && ambient<100) ambient += 5;
  /*  Diffuse level */
  else if (key == 'd' && diffuse>0) diffuse -= 5;
  else if (key == 'D' && diffuse<100) diffuse += 5;
  /*  Specular level */
  else if (key == 's' && specular>0) specular -= 5;
  else if (key == 'S' && specular<100) specular += 5;
  /*  Emission level */
  else if (key == 'e' && emission>0) emission -= 5;
  else if (key == 'E' && emission<100) emission += 5;
  /*  Shininess level */
  else if (key == 'n' && shininess>-1) shininess -= 1;
  else if (key == 'N' && shininess<7) shininess += 1;

  /*  Translate shininess power to value (-1 => 0) */
  shinyvec[0] = shininess<0 ? 0 : pow(2.0,shininess);

  redisplayAll();
}
예제 #9
0
/*
 *  timer
 *  ------
 *  game animation logic turned on or off here
 */
void timer(int toggle)
{
  if (gameStarted) {
    if (gamePaused != DEF_GAME_PAUSED) {
      moveLight();
      moveTowerTops();
      moveShots();
      checkCollisions();
      moveMinions();
      checkCollisions();
      checkTowerRange();
    }
    glutTimerFunc(50,timer,0);
  }
  redisplayAll();
}
예제 #10
0
void updateAngle(void){ //update function
	for(int j=0;j<14;j++){
		GLfloat currentAngle = 0.0, orbitAngle = 0.0;
		currentAngle = planet[j]->getCurrentAngle();
		orbitAngle = currentAngle + planetOrbitAngle[j];
		if (orbitAngle >= 360.0) 
			orbitAngle = 0.0;
		planet[j]->setAngle(orbitAngle);
		planet[j]->update();
	}
	warbird->update();
	missileSite[0]->checkForShip(warbird->getX(),warbird->getY(),warbird->getZ(),0);
	missileSite[1]->checkForShip(warbird->getX(),warbird->getY(),warbird->getZ(),1);
	missileSite[0]->update();
	missileSite[1]->update();
	redisplayAll();
 }
예제 #11
0
파일: Camera.c 프로젝트: AM1244/Blog
//-------------------------------------------------------------------------
// function used when the user is dragging the mouse
//-------------------------------------------------------------------------
void motion (int x, int y) 
{
    //  Translate
    if (rightButton) 
    {
        translate_x += (x - previousX) * 0.005;
        translate_y -= (y - previousY) * 0.005;
    }

    //  Scale
    if (middleButton) 
    {
        scale_x -= (y - previousZ) * 0.005;
        scale_y -= (y - previousZ) * 0.005;
        scale_z -= (y - previousZ) * 0.005;
    }

    //  Rotate
    if (leftButton) 
    {
        if ((y - previousY) >= 0)
            rot_x += (y - previousY);
        else 
            rot_x += (y - previousY);
        if ((x - previousX) >= 0)
            rot_y += (x - previousX);
        else
            rot_y += (x - previousX);
    }	

    // reset the previousX, previousY, and previousZ to the current position of the mouse
    previousX = (float)x;
    previousY = (float)y;
    previousZ = (float)y;

    redisplayAll ();
}
예제 #12
0
void Timer(int value)
{
    GLfloat nx=0,nz=0;
    GLboolean andar=GL_FALSE;

	GLuint curr = glutGet(GLUT_ELAPSED_TIME);

	if(modelo.homer[JANELA_NAVIGATE].GetSequence()==20 && curr-modelo.animStart>1050){
		modelo.homer[JANELA_NAVIGATE].SetSequence(0);
		modelo.homer[JANELA_TOP].SetSequence(0);
		modelo.animStart = 0;
	}
  // calcula velocidade baseado no tempo passado
	float velocidade= modelo.objecto.vel*(curr - modelo.prev )*0.001;

	glutTimerFunc(estado.timer, Timer, 0);
	modelo.prev = curr;

    
  if(estado.teclas.up){
	  nx = modelo.objecto.pos.x + velocidade * cos(modelo.objecto.dir);
	  nz = modelo.objecto.pos.z + velocidade * -sin(modelo.objecto.dir);
		if(!detectaColisao(nx,nz)){
			modelo.objecto.pos.x=nx;
			modelo.objecto.pos.z=nz;
		}else{
			modelo.animStart = curr;
		}
    andar=GL_TRUE;
	}
	if(estado.teclas.down){
    nx = modelo.objecto.pos.x - velocidade * cos(modelo.objecto.dir);
	nz = modelo.objecto.pos.z - velocidade * -sin(modelo.objecto.dir);
		if(!detectaColisao(nx,nz)){
			modelo.objecto.pos.x=nx;
			modelo.objecto.pos.z=nz;
		}else{
			modelo.animStart = curr;
		}
    andar=GL_TRUE;
	}
	if(estado.teclas.left){
		modelo.objecto.dir += 0.1;
		estado.camera.dir_long += 0.1;
    }
	if(estado.teclas.right){
		modelo.objecto.dir -= 0.1;
		estado.camera.dir_long -= 0.1;
	}

	setNavigateSubwindowCamera(&estado.camera,modelo.objecto);

// Sequencias - 0(parado) 3(andar) 20(choque)
//  modelo.homer[JANELA_NAVIGATE].GetSequence()  le Sequencia usada pelo homer
//  modelo.homer[JANELA_NAVIGATE].SetSequence()  muda Sequencia usada pelo homer
	if(modelo.homer[JANELA_NAVIGATE].GetSequence() !=20){
		if(andar && modelo.homer[JANELA_NAVIGATE].GetSequence()!=3){
			modelo.homer[JANELA_NAVIGATE].SetSequence(3);
			modelo.homer[JANELA_TOP].SetSequence(3);
		}else if(!andar && modelo.homer[JANELA_NAVIGATE].GetSequence()!=0){
			modelo.homer[JANELA_NAVIGATE].SetSequence(0);
			modelo.homer[JANELA_TOP].SetSequence(0);
		}
	}
  redisplayAll();
	
}
예제 #13
0
void Timer(int value)
{
	GLfloat nx=0,nz=0;
	float velocidade;

	GLuint curr = glutGet(GLUT_ELAPSED_TIME);
	// calcula velocidade baseado no tempo passado

	if(!gordon.correr)
		velocidade= gordon.objecto.vel*(curr - gordon.prev )*0.001;
	else
		velocidade= gordon.objecto.vel*(curr - gordon.prev )*0.001*2;

	glutTimerFunc(estado.timer, Timer, 0);
	gordon.prev = curr;

	if(!gordon.saltar){

		if(estado.teclas.z && gordon.andar)
			gordon.correr=GL_TRUE;
		else
			gordon.correr=GL_FALSE;

		if(!estado.teclas.up && !estado.teclas.down){
			gordon.andar=GL_FALSE;
			if(gordon.stdModel[JANELA_NAVIGATE].GetSequence()!=0)
				gordon.stdModel[JANELA_NAVIGATE].SetSequence(0);
		}

		if(estado.teclas.up){
			//Roda Objecto
			if(!gordon.andarFrente){
				gordon.objecto.dir+=M_PI;
				gordon.andarFrente=GL_TRUE;
			}
			// calcula nova posição nx,nz
			nx=gordon.objecto.pos.x+velocidade;
			//nz=modelo.objecto.pos.z-velocidade*sin(modelo.objecto.dir);

			//if(!detectaColisao(nx,nz)){

			gordon.objecto.pos.x=nx;
			gordon.andar=GL_TRUE;
			//}
		}

		if(estado.teclas.down){
			//roda o objecto

			if(gordon.andarFrente){
				gordon.objecto.dir-=M_PI;
				gordon.andarFrente=GL_FALSE;
			}
			// calcula nova posição nx,nz
			nx=gordon.objecto.pos.x-velocidade;

			//if(!detectaColisao(nx,nz)){

			gordon.objecto.pos.x=nx;
			gordon.andar=GL_TRUE;
			//}
		}

		if( gordon.andar && !gordon.correr && gordon.stdModel[JANELA_NAVIGATE].GetSequence()!=4)
			gordon.stdModel[JANELA_NAVIGATE].SetSequence(4);

		if(gordon.correr && gordon.stdModel[JANELA_NAVIGATE].GetSequence()!=3)
			gordon.stdModel[JANELA_NAVIGATE].SetSequence(3);

		if(estado.teclas.x){
			gordon.andar=GL_FALSE;
			gordon.saltar=GL_TRUE;
			gordon.stdModel[JANELA_NAVIGATE].SetSequence(8);
			gordon.saltarStartTime=curr;
		}
	}
	else{

		if(gordon.saltarStartTime + TEMPO_SALTO > curr){
			//	gordon.saltar = GL_FALSE;
			//gordon.stdModel[JANELA_NAVIGATE].SetSequence(0);
			gordon.objecto.pos.y=abs(2*sin(M_PI*curr/TEMPO_SALTO));
			
			/*	else{*/
			if(estado.teclas.up){
				//Roda Objecto
				if(!gordon.andarFrente){
					gordon.objecto.dir+=M_PI;
					gordon.andarFrente=GL_TRUE;
				}
				// calcula nova posição nx,nz
				nx=gordon.objecto.pos.x+velocidade;
				//nz=modelo.objecto.pos.z-velocidade*sin(modelo.objecto.dir);

				//if(!detectaColisao(nx,nz)){

				gordon.objecto.pos.x=nx;
				//gordon.andar=GL_TRUE;
				//}
			}

			if(estado.teclas.down){
				//roda o objecto

				if(gordon.andarFrente){
					gordon.objecto.dir-=M_PI;
					gordon.andarFrente=GL_FALSE;
				}
				// calcula nova posição nx,nz
				nx=gordon.objecto.pos.x-velocidade;

				//if(!detectaColisao(nx,nz)){

				gordon.objecto.pos.x=nx;
				//gordon.andar=GL_TRUE;
				//}
			}

		}
		else{
			
			gordon.saltar = GL_FALSE;
			gordon.stdModel[JANELA_NAVIGATE].SetSequence(0);
		}
	}

	redisplayAll();
}