Results 1 to 3 of 3

Thread: what's wrong in this function ? (keyboard)

  1. #1
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    what's wrong in this function ? (keyboard)

    float c = 0.0 ;

    void keyboard (unsigned char key, int x, int y)
    {



    switch (key)
    {
    case 'd' : //fait tourner selon l'axe des Y
    case 'D' :

    nbr_degre += 2.0;
    j = 0.0 ;
    k = 1.0 ;
    l = 0.0 ;
    glutPostRedisplay () ;
    break ;

    case 's' :
    case 'S' :

    nbr_degre += 2.0; //fait tourner selon l'axe des Y
    j = 0.0 ;
    k = -1.0 ;
    l = 0.0 ;
    glutPostRedisplay () ;
    break ;

    case 'e' : //fait tourner selon l'axe des X
    case 'E' :

    nbr_degre += 2.0;
    j = -1.0 ;
    k = 0.0 ;
    l = 0.0 ;
    glutPostRedisplay () ;
    break ;

    case 'x' : //fait tourner selon l'axe des X
    case 'X' :

    nbr_degre += 2.0;
    j = 1.0 ;
    k = 0.0 ;
    l = 0.0 ;
    glutPostRedisplay () ;
    break ;

    case 'i':
    case 'I':

    c += 0.5 ;
    switch (c)
    {
    case 10.0 :
    profondeur = 1 ;
    glutPostRedisplay () ;
    break ;

    case 20.0 :
    profondeur = 2 ;
    glutPostRedisplay () ;
    break ;

    case 30.0 :
    profondeur = 3 ;
    glutPostRedisplay () ;
    break ;

    case 40.0 :
    profondeur = 4 ;
    glutPostRedisplay () ;
    break ;
    }




    case 'o':
    case 'O':

    c -= 0.5 ;
    glutPostRedisplay () ;
    break ;


    }
    }

    [This message has been edited by airseb (edited 08-03-2002).]

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: what's wrong in this function ? (keyboard)

    Your problem is that you donīt get it compiled, do you?

    You cannot use floats in a switch-statement. The switch-statement only allows integertypes (int, short, enum, byte, char).

    You could do it this way:

    c += 0.5 ;

    int c2 = (int) (c);

    switch (c2)
    {
    case 10:
    profondeur = 1 ;
    glutPostRedisplay () ;
    break ;

    case 20:
    profondeur = 2 ;
    glutPostRedisplay () ;
    break ;

    case 30:
    profondeur = 3 ;
    glutPostRedisplay () ;
    break ;

    case 40:
    profondeur = 4 ;
    glutPostRedisplay () ;
    break ;
    }


    Jan.
    GLIM - Immediate Mode Emulation for GL3

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    Re: what's wrong in this function ? (keyboard)

    thanks for your answer

Similar Threads

  1. keyboard function to display polygon object
    By fauzo86 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-08-2017, 11:28 AM
  2. Problem with keyboard function
    By avpai1992 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-12-2015, 01:13 AM
  3. move camera with keyboard function
    By marito in forum OpenGL ES
    Replies: 2
    Last Post: 03-19-2013, 10:28 AM
  4. move camera with keyboard function
    By imported_marito in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-13-2013, 10:48 AM
  5. Replies: 2
    Last Post: 10-22-2003, 09:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean