Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [C] Un errore misterioso...

    ciao! in un mio programma ho scritto la seguente funzione:

    codice:
    void mouseMove(int actualX, int actualY)
    {
       int spostamentoX = lastMousePos[0] - actualX;
       int spostamentoY = lastMousePos[1] - actualY;
       lastMousePos[0] = actualX;
       lastMousePos[1] = actualY;
    
       if (stato == MOVIMENTO)
       {
          moveLeftOrRight(spostamentoX);
          moveUpOrDown(spostamentoY);
       }
    }
    ma in fase di compilazione mi da' un errore: mi dice che nella riga
    codice:
    if (stato == MOVIMENTO)
    manca la ')' prima del ';'
    Ho provato a ricontrollare tutte le parentesi e sembrano tutte ben accoppiate...

    vi posto tutto il codice sorgente se volete aiutarmi a capire dov'è l'errore... grazie!!!

    codice:
    #include <windows.h>
    #include <gl/glut.h>
    #include <math.h>
    
    #define NESSUN_MOVIMENTO 0;
    #define MOVIMENTO 1;
    
    void drawRubikCube(GLfloat edge);
    
    static int stato=NESSUN_MOVIMENTO;
    static int lastMousePos[2];
    
    GLfloat arrowXrot=0.0;
    GLfloat arrowYrot=0.0;
    GLfloat arrowZrot=0.0;
    int semaforo[3];
    
    void init(void)
    {
     int i;
    
     /* Abilita il Culling e il Depth testing */
     glEnable(GL_DEPTH_TEST);
     glEnable(GL_CULL_FACE);
    
     /* Imposta lo smooth shading */
     glShadeModel(GL_SMOOTH);
     
     /* colore di sfondo nero */
     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    
     for(i=0; i<3; i++)
    	 semaforo[i]=0;
    }
    
    void oscilla()
    {
     GLfloat offset=0.1;
     GLfloat maxAngleSize=15.0;
     static GLfloat angle=90.0;
     static GLfloat angleOld;
     GLfloat zRot=sin(angle)*3;
     GLfloat xRot=cos(angle)*3;
    
     angleOld=angle+offset;
    
     glRotatef(zRot, 0.0, 0.0, 1.0);
     glRotatef(xRot, 0.0, 1.0, 0.0);
    
    /* imposta un leggero movimento oscillatorio di default */
    if(angleOld-angle > 0 && angle > -maxAngleSize)
    	{
    	 angle-=offset;
    	 angleOld-=offset;
    	}
    else if(angle <= maxAngleSize)
    	{
     	 if(angle < -maxAngleSize)
    		angle+=offset;
     
    	 else
    		{
    		angle+=offset;
    		angleOld+=offset;
    		}
    	}
    else
    	 angleOld+=offset;
    }
    
    void timer(int valore)
    {
     switch(valore)
    	{case 0:
    		
    		glutPostRedisplay();
    		glutTimerFunc(100, timer, 0); 
    		
    		break;	 
    	}
    }
    
    void mouseFunc(int button, int state, int x, int y)
    {
     switch (button)
       {
       case GLUT_LEFT_BUTTON:
          if (state == GLUT_DOWN)
          {
             stato = MOVIMENTO;
          }
          else
          {
             stato = NESSUN_MOVIMENTO;
          }
          break;
       }
    }
    
    void moveLeftOrRight(int x)
    {
     glMatrixMode(GL_MODELVIEW);
     glTranslatef(x, 0.0, 0.0);
    }
    
    void moveUpOrDown(int y)
    {
     glMatrixMode(GL_MODELVIEW);
     glTranslatef(0.0, y, 0.0);
    }
    
    void mouseMove(int actualX, int actualY)
    {
       int spostamentoX = lastMousePos[0] - actualX;
       int spostamentoY = lastMousePos[1] - actualY;
       lastMousePos[0] = actualX;
       lastMousePos[1] = actualY;
    
       if (stato == MOVIMENTO)
       {
          moveLeftOrRight(spostamentoX);
          moveUpOrDown(spostamentoY);
       }
    }
    
    void specialKeyboard(int key, int x, int y)
    {
     if(key == GLUT_KEY_UP)
    	{
    	 /*semaforo[0]=1;
    	 semaforo[1]=0;
    	 semaforo[2]=0;*/
    
    	 arrowXrot-=5;
    	 if(arrowXrot< -360.0)
    		 arrowXrot=0.0;
    	}
    
     if(key == GLUT_KEY_DOWN)
    	{
    	 /*semaforo[0]=1;
    	 semaforo[1]=0;
    	 semaforo[2]=0;*/
    
    	 arrowXrot+=5;
    	 if(arrowXrot > 360.0)
    		 arrowXrot=0.0;
    	}
    
     if(key == GLUT_KEY_LEFT)
    	{
    	 /*semaforo[0]=0;
    	 semaforo[1]=1;
    	 semaforo[2]=0;*/
    
    	 arrowYrot-=5;
    	 if(arrowYrot < -360.0)
    		arrowYrot=0.0;
    	}
          
     if(key == GLUT_KEY_RIGHT)
    	{
    	 /*semaforo[0]=0;
    	 semaforo[1]=1;
    	 semaforo[2]=0;*/
    	 
    	 arrowYrot+=5;
    	 if(arrowYrot > 360.0)
    		 arrowYrot=0.0;
    	}
    
     if(key == GLUT_KEY_PAGE_DOWN)
    	{
    	 /*semaforo[0]=0;
    	 semaforo[1]=0;
    	 semaforo[2]=1;*/
    
    	 arrowZrot-=5;
    	 if(arrowZrot < -360.0)
    		 arrowZrot=0.0;
    	}
    
     if(key == GLUT_KEY_END)
    	{
    	 /*semaforo[0]=0;
    	 semaforo[1]=0;
    	 semaforo[2]=1;*/
    
    	 arrowZrot+=5;
    	 if(arrowZrot > 360.0)
    		 arrowZrot=0.0;
    	}
                            
     /* Aggiorna l'immagine */
     glutPostRedisplay();
    }
    
    void drawGround(void)
        {   
        glBegin(GL_QUADS);
            glColor3ub(0, 0, 0);
            glVertex3f(600.0f, -50.0f, -400.0f);
            glVertex3f(-600.0f, -50.0f, -400.0f);
            glColor3ub(200, 200, 200);
            glVertex3f(-600.0f, -50.0f, -20.0f);
            glVertex3f(600.0f, -50.0f, -20.0f);
        glEnd();
        }
    
    void drawColumn(int direzione, GLfloat spostamento, GLfloat lato)
    {
     switch(direzione)
    	{
    	 case 1: 
    		 glTranslatef(spostamento, 0.0, 0.0);
    		 break;
    
    	 case -1: 
    		 glTranslatef(-spostamento, 0.0, 0.0);
    		 break;
    
    	 case 3: 
    		 glTranslatef(0.0, 0.0, spostamento);
    		 break;
    
    	 case -3: 
    		 glTranslatef(0.0, 0.0, -spostamento);
    		 break;
    	}
    
     glutWireCube(lato);
    
    	glPushMatrix();
    
    		glTranslatef(0.0, spostamento, 0.0);
    		glutWireCube(lato);
    
    	glPopMatrix();
    
    	glPushMatrix();
    
    		glTranslatef(0.0, -spostamento, 0.0);
    		glutWireCube(lato);
    
    	glPopMatrix();
    }
    
    void drawRubikCube(GLfloat edge)
    {
     /* salva la posizione corrente e spostati in alto per disegnare il cubo */
     glPushMatrix();
    
        glTranslatef(0.0, edge, 0.0);
    
    	glColor3ub(255, 0, 0);
    	glutWireCube(edge);
    	glColor3ub(0, 255, 0);
    
     /* ripristina la posizione iniziale */
     glPopMatrix();
    
     /* salva la posizione corrente e spostati in basso per disegnare il cubo */
     glPushMatrix();
    
        glTranslatef(0.0, -edge, 0.0);
    
    	glutWireCube(edge); 
    
     /* ripristina la posizione iniziale */
     glPopMatrix();
    
     drawColumn(1, edge, edge);
     drawColumn(3, edge, edge);
     drawColumn(-1, edge, edge);
     drawColumn(-1, edge, edge);
     drawColumn(-3, edge, edge);
     drawColumn(-3, edge, edge);
     drawColumn(1, edge, edge);
     drawColumn(1, edge, edge);
    }
    
    void display(void)
    {
     /* inizializza il color buffer e il depth buffer */
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
     /* d'ora in poi si modifica la matrice modelview*/
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
    
     drawGround();
     
     glTranslatef(0.0, 0.0, -50.0);
     glRotatef(45.0, 1.0, 0.0, 0.0);
     glRotatef(45.0, 0.0, 1.0, 0.0);
    
     /* SE VENGONO PREMUTE LE FRECCE IL CUBO RUOTA */
     /*if(semaforo[0])
    	{*/
    	 glRotatef(arrowYrot, 0.0, 1.0, 0.0);
    	 glRotatef(arrowZrot, 0.0, 0.0, 1.0);
    	 glRotatef(arrowXrot, 1.0, 0.0, 0.0);
    /*	}
    
     if(semaforo[1])
    	{
    	 glRotatef(arrowXrot, 1.0, 0.0, 0.0);
    	 glRotatef(arrowZrot, 0.0, 0.0, 1.0);
    	 glRotatef(arrowYrot, 0.0, 1.0, 0.0);
    	}
    
     if(semaforo[2])
    	{
    	 glRotatef(arrowXrot, 1.0, 0.0, 0.0);
    	 glRotatef(arrowYrot, 0.0, 1.0, 0.0);
    	 glRotatef(arrowZrot, 0.0, 0.0, 1.0);
    	}*/
    
     //oscilla();
     drawRubikCube(10.0);
    
     glutSwapBuffers();
    }
    
    void reshape(GLsizei w, GLsizei h)
    {
     GLfloat ratio;
    
     if(h==0)
    	 h=1;
    
     glViewport(0, 0, w, h);
    
     ratio=(GLfloat) w/ (GLfloat) h;
    
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
    
     gluPerspective(90.0, ratio, 20.0, 500.0);
     //glOrtho(-100.0, 100.0, -75.0, 75.0, 20.0, 300.0);
    
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
    }
    
    main()
    {
     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    
     glutInitWindowSize(800, 600);
     glutInitWindowPosition(0, 0);
     glutCreateWindow("Prova");
    
     glutTimerFunc(250, timer, 0);
     glutDisplayFunc(display);
     glutReshapeFunc(reshape);
     //glutKeyboardFunc(keyboard);
     glutSpecialFunc(specialKeyboard);
     glutMouseFunc(mouseFunc);
     glutMotionFunc(mouseMove);
    
     init();
    
     glutMainLoop();
    }

  2. #2
    sostituisci #define movimento 1;
    con #define movimento 1
    e #define NESSUN_MOVIMENTO 0;
    con #define NESSUN_MOVIMENTO 0

  3. #3

  4. #4
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,328
    [EDIT]
    Ok... ho risposto tardi...
    [/EDIT]
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.