Aller au menu - Aller au contenu

[Plan du site] Vous êtes ici --- > Le Site du Zéro > Les forums > Programmation > Langage C > [SDL_JOYAXISMOTION] Problème d'axes inactifs > Lecture du sujet

[SDL_JOYAXISMOTION] Problème d'axes inactifs

20 axes reconnus mais inactifs...

Vous devez être inscrit pour pouvoir poster des messages

Page : 1 
Auteur Message
1 visiteur sur ce sujet (1 anonyme)
Page : 1 
Hors ligne Gaetano-FR # Posté le 16/05/2008 à 10:03:31
Avatar
Groupe : Membres
Bonjour à tous,

J'apprends actuellement à gérer le joystick grâce au cours sur les Evènements du SDZ, mais mon code ci-desoous ne permet pas de faire bouger Zozor grâce aux Joystick (seulement grâce aux flèches). :(

Y aurait-il une solution à mon problème SVP ???
(J'ai 19 boutons et 20 axes reconnus).

Voici mon code:
Code : C
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>


int main(int argc, char *argv[])
{
    SDL_Surface *ecran = NULL, *zozor = NULL;
    SDL_Rect positionZozor;
    SDL_Event event;
    int continuer = 1, i = 0;

    SDL_Joystick *joystick = NULL;


    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);

    SDL_JoystickEventState(SDL_ENABLE);
    joystick = SDL_JoystickOpen(0);


    printf("Il y a %d joysticks connectés\n", SDL_NumJoysticks());

    for (i = 0 ; i < SDL_NumJoysticks() ; i++ )
{
    printf("Joystick n°%d : %s\n", i, SDL_JoystickName(i));
}

printf("----> %d boutons\n", SDL_JoystickNumButtons(joystick));
printf("----> %d axes\n", SDL_JoystickNumAxes(joystick));
printf("----> %d trackballs\n", SDL_JoystickNumBalls(joystick));
printf("----> %d chapeaux\n", SDL_JoystickNumHats(joystick));


    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);

    /* Chargement de Zozor */
    zozor = SDL_LoadBMP("zozor.bmp");
    SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));

    /* On centre Zozor à l'écran */
    positionZozor.x = ecran->w / 2 - zozor->w / 2;
    positionZozor.y = ecran->h / 2 - zozor->h / 2;


SDL_EnableKeyRepeat(10, 10); // Répétition de touches


    while (continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
{
    case SDL_QUIT:
        continuer = 0;
        break;
    case SDL_JOYBUTTONDOWN:
        if (event.jbutton.button == 16) /* Arrêt du programme si on appuie sur le bouton n°16 */
            continuer = 0;

        break;
}
        switch(event.type)
        {
            case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                    case SDLK_UP: // Flèche haut
                        positionZozor.y--;
                        break;
                    case SDLK_DOWN: // Flèche bas
                        positionZozor.y++;
                        break;
                    case SDLK_RIGHT: // Flèche droite
                        positionZozor.x++;
                        break;
                    case SDLK_LEFT: // Flèche gauche
                        positionZozor.x--;
                        break;
        switch(event.type)
        {
                    case SDL_JOYAXISMOTION:
    if (event.jaxis.axis == 0 && event.jaxis.value < -3200) /* Vers la gauche */
        positionZozor.x--;

    else if (event.jaxis.axis == 0 && event.jaxis.value > 3200) /* Vers la droite */
        positionZozor.x++;

    else if (event.jaxis.axis == 1 && event.jaxis.value < -3200) /* Vers le haut */
        positionZozor.y--;

    else if (event.jaxis.axis == 1 && event.jaxis.value > 3200) /* Vers le bas */
        positionZozor.y++;

    break;
                }
                    default: continuer = 1;
                }
                break;
        }

        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); /* On efface l'écran */
        SDL_BlitSurface(zozor, NULL, ecran, &positionZozor); /* On place zozor à sa nouvelle position */
        SDL_Flip(ecran); /* On met à jour l'affichage */
    }

    SDL_JoystickClose(joystick);
    SDL_FreeSurface(zozor);
    SDL_Quit();

    return EXIT_SUCCESS;
}


Voilà, merci d'avance...
Hors ligne Fvirtman # Posté le 16/05/2008 à 10:24:14
Avatar
Groupe : Membres
pourquoi mets tu plusieurs fois switch(event.type) ?? et un seul case dans ces switchs ?

Dis moi la vérité : tu fais ça au hasard ?

--- "Toute tâche répétitive est automatisable..." ---
Tuto C/C++ basés sur des exemples :
http://perso.numericable.fr/~fvirtman/info/tuto/index.html
Mes programmes a peu pres finis :
http://perso.numericable.fr/~fvirtman/progs/index.html
 
Hors ligne Gaetano-FR # Posté le 16/05/2008 à 10:41:48
Avatar
Groupe : Membres
J'ai enlevé des switch(event.type) en trop (je croyais qu'il fallait en définir pour chaque Evenements SDL)...
Mon code ne plante pas à la compilation mais le joystick est toujours inactif.

Ce code-ci est-il plus correct ?

Code : C
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>


int main(int argc, char *argv[])
{
    SDL_Surface *ecran = NULL, *zozor = NULL;
    SDL_Rect positionZozor;
    SDL_Event event;
    int continuer = 1, i = 0;

    SDL_Joystick *joystick = NULL;


    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);

    SDL_JoystickEventState(SDL_ENABLE);
    joystick = SDL_JoystickOpen(0);


    printf("Il y a %d joysticks connectés\n", SDL_NumJoysticks());

    for (i = 0 ; i < SDL_NumJoysticks() ; i++ )
{
    printf("Joystick n°%d : %s\n", i, SDL_JoystickName(i));
}

printf("----> %d boutons\n", SDL_JoystickNumButtons(joystick));
printf("----> %d axes\n", SDL_JoystickNumAxes(joystick));
printf("----> %d trackballs\n", SDL_JoystickNumBalls(joystick));
printf("----> %d chapeaux\n", SDL_JoystickNumHats(joystick));


    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);

    /* Chargement de Zozor */
    zozor = SDL_LoadBMP("zozor.bmp");
    SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));

    /* On centre Zozor à l'écran */
    positionZozor.x = ecran->w / 2 - zozor->w / 2;
    positionZozor.y = ecran->h / 2 - zozor->h / 2;


SDL_EnableKeyRepeat(10, 10); // Répétition de touches


    while (continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
{
    case SDL_QUIT:
        continuer = 0;
        break;
    case SDL_JOYBUTTONDOWN:
        if (event.jbutton.button == 16) /* Arrêt du programme si on appuie sur le bouton n°16 */
            continuer = 0;
        break;
            case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                    case SDLK_UP: // Flèche haut
                        positionZozor.y--;
                        break;
                    case SDLK_DOWN: // Flèche bas
                        positionZozor.y++;
                        break;
                    case SDLK_RIGHT: // Flèche droite
                        positionZozor.x++;
                        break;
                    case SDLK_LEFT: // Flèche gauche
                        positionZozor.x--;
                        break;

                    case SDL_JOYAXISMOTION:
    if (event.jaxis.axis == 0 && event.jaxis.value < -3200) /* Vers la gauche */
        positionZozor.x--;

    else if (event.jaxis.axis == 0 && event.jaxis.value > 3200) /* Vers la droite */
        positionZozor.x++;

    else if (event.jaxis.axis == 1 && event.jaxis.value < -3200) /* Vers le haut */
        positionZozor.y--;

    else if (event.jaxis.axis == 1 && event.jaxis.value > 3200) /* Vers le bas */
        positionZozor.y++;

    break;

                    default: continuer = 1;
                }
                break;
}

        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); /* On efface l'écran */
        SDL_BlitSurface(zozor, NULL, ecran, &positionZozor); /* On place zozor à sa nouvelle position */
        SDL_Flip(ecran); /* On met à jour l'affichage */
    }

    SDL_JoystickClose(joystick);
    SDL_FreeSurface(zozor);
    SDL_Quit();

    return EXIT_SUCCESS;
}


Merci d'avance.

Hors ligne Fvirtman # Posté le 16/05/2008 à 10:49:32
Avatar
Groupe : Membres
Non.
Regarde ce que tu fais :
Tu as un case SDL_KEYDOWN:
et a l'interieur tu fais les case pour les touches, et tu fais aussi un case SDL_JOYAXISMOTION:, dans le switch event.key.keysym.sym....

Tu ne le fais donc pas au bon endroit.
Déja, indente ton code ! Tu y verras plus clair.

--- "Toute tâche répétitive est automatisable..." ---
Tuto C/C++ basés sur des exemples :
http://perso.numericable.fr/~fvirtman/info/tuto/index.html
Mes programmes a peu pres finis :
http://perso.numericable.fr/~fvirtman/progs/index.html
 
Hors ligne Gaetano-FR # Posté le 16/05/2008 à 11:06:31
Avatar
Groupe : Membres
Merci de me conseiller Fvirtman...

Voici mon code de façon plus claire (cette fois les flèches marchent mais le joystick ne répond que s'il est en mouvement -et donc par accouds-).

Y a t-il une fonction similaire à enable key repeat pour le joystick ?

Code : C
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>


int main(int argc, char *argv[])
{
    SDL_Surface *ecran = NULL, *zozor = NULL;
    SDL_Rect positionZozor;
    SDL_Event event;
    int continuer = 1, i = 0;

    SDL_Joystick *joystick = NULL;


    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);

    SDL_JoystickEventState(SDL_ENABLE);
    joystick = SDL_JoystickOpen(0);


    printf("Il y a %d joysticks connectés\n", SDL_NumJoysticks());

    for (i = 0 ; i < SDL_NumJoysticks() ; i++ )
{
    printf("Joystick n°%d : %s\n", i, SDL_JoystickName(i));
}

printf("----> %d boutons\n", SDL_JoystickNumButtons(joystick));
printf("----> %d axes\n", SDL_JoystickNumAxes(joystick));
printf("----> %d trackballs\n", SDL_JoystickNumBalls(joystick));
printf("----> %d chapeaux\n", SDL_JoystickNumHats(joystick));


    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);

    /* Chargement de Zozor */
    zozor = SDL_LoadBMP("zozor.bmp");
    SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));

    /* On centre Zozor à l'écran */
    positionZozor.x = ecran->w / 2 - zozor->w / 2;
    positionZozor.y = ecran->h / 2 - zozor->h / 2;


SDL_EnableKeyRepeat(10, 10); // Répétition de touches


    while (continuer)
{
        SDL_WaitEvent(&event);
        switch(event.type)
        {
        case SDL_QUIT:
        continuer = 0;
        break;

        case SDL_JOYBUTTONDOWN:
        if (event.jbutton.button == 16) /* Arrêt du programme si on appuie sur le bouton n°16 */
            continuer = 0;
        break;

        case SDL_JOYAXISMOTION:

            if (event.jaxis.axis == 0 && event.jaxis.value < -3200) /* Vers la gauche */
            positionZozor.x--;

            else if (event.jaxis.axis == 0 && event.jaxis.value > 3200) /* Vers la droite */
            positionZozor.x++;

            else if (event.jaxis.axis == 1 && event.jaxis.value < -3200) /* Vers le haut */
            positionZozor.y--;

            else if (event.jaxis.axis == 1 && event.jaxis.value > 3200) /* Vers le bas */
            positionZozor.y++;

            break;

            case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                    case SDLK_UP: // Flèche haut
                        positionZozor.y--;
                        break;
                    case SDLK_DOWN: // Flèche bas
                        positionZozor.y++;
                        break;
                    case SDLK_RIGHT: // Flèche droite
                        positionZozor.x++;
                        break;
                    case SDLK_LEFT: // Flèche gauche
                        positionZozor.x--;
                        break;
                        default: continuer = 1;
                        break;
                }



}

        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); /* On efface l'écran */
        SDL_BlitSurface(zozor, NULL, ecran, &positionZozor); /* On place zozor à sa nouvelle position */
        SDL_Flip(ecran); /* On met à jour l'affichage */
    }

    SDL_JoystickClose(joystick);
    SDL_FreeSurface(zozor);
    SDL_Quit();

    return EXIT_SUCCESS;
}


Merci d'avance.

Hors ligne Fvirtman # Posté le 16/05/2008 à 11:15:28
Avatar
Groupe : Membres
personnellement, je deteste SDL_EnableKeyRepeat

J'ai un exemple sur l'utilisation du stick sur mon site :
cf ma signature, §2.1.4.

--- "Toute tâche répétitive est automatisable..." ---
Tuto C/C++ basés sur des exemples :
http://perso.numericable.fr/~fvirtman/info/tuto/index.html
Mes programmes a peu pres finis :
http://perso.numericable.fr/~fvirtman/progs/index.html
 
Hors ligne Gaetano-FR # Posté le 16/05/2008 à 12:06:16
Avatar
Groupe : Membres
Merci pour le lien de ton site...

Je suis en train de l'étudier...
Seulement, dans mon nouveau code (ci-dessous) la compilation plante au moment de positionner zozor au centre (j'ai presque tout mis dans la fonction UpdateEvents() croyant qu'il y avait un problème de pointeur...)

Je ne cromprends pas l'erreur de mon code:

Code : C
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

void UpdateEvents()
{
    int continuer = 1;
	SDL_Event event;

    SDL_Rect *positionZozor;

    SDL_Surface *ecran = NULL;
    SDL_Surface *zozor = NULL;

    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);


    /* Chargement de Zozor */
    zozor = SDL_LoadBMP("zozor.bmp");
    SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));


    /* On centre Zozor à l'écran */
    positionZozor.x = ecran->w / 2 - zozor->w / 2;
    positionZozor.y = ecran->h / 2 - zozor->h / 2;



SDL_EnableKeyRepeat(10, 10); // Répétition de touches

	while(SDL_PollEvent(&event))
	{
		switch (event.type)
		{

            if (key[SDLK_RETURN])
			break;

        case SDL_QUIT:
        continuer = 0;
        break;

		case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                    case SDLK_UP: // Flèche haut
                        positionZozor.y--;
                        break;
                    case SDLK_DOWN: // Flèche bas
                        positionZozor.y++;
                        break;
                    case SDLK_RIGHT: // Flèche droite
                        positionZozor.x++;
                        break;
                    case SDLK_LEFT: // Flèche gauche
                        positionZozor.x--;
                        break;
                        default: continuer = 1;
                        break;
                }
		case SDL_MOUSEMOTION:
			xsouris=event.motion.x;
			ysouris=event.motion.y;
			xrelsouris=event.motion.xrel;
			yrelsouris=event.motion.yrel;
			break;
		case SDL_MOUSEBUTTONDOWN:
			boutons[event.button.button-1]=1;
			break;
		case SDL_MOUSEBUTTONUP:
			boutons[event.button.button-1]=0;
			break;

        case SDL_JOYBUTTONDOWN:
        if (event.jbutton.button == 16) /* Arrêt du programme si on appuie sur le bouton n°16 */
            continuer = 0;
        break;

        case SDL_JOYAXISMOTION:

            if (event.jaxis.axis == 0 && event.jaxis.value < -3200) /* Vers la gauche */
            positionZozor.x--;

            else if (event.jaxis.axis == 0 && event.jaxis.value > 3200) /* Vers la droite */
            positionZozor.x++;

            else if (event.jaxis.axis == 1 && event.jaxis.value < -3200) /* Vers le haut */
            positionZozor.y--;

            else if (event.jaxis.axis == 1 && event.jaxis.value > 3200) /* Vers le bas */
            positionZozor.y++;

            break;

		}
	}
}

int main(int argc, char *argv[])
{

    int i;

    SDL_Joystick *joystick = NULL;

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);

    SDL_JoystickEventState(SDL_ENABLE);
    joystick = SDL_JoystickOpen(0);


    printf("Il y a %d joysticks connectés\n", SDL_NumJoysticks());

    for (i = 0 ; i < SDL_NumJoysticks() ; i++ )
{
    printf("Joystick n°%d : %s\n", i, SDL_JoystickName(i));
}

printf("----> %d boutons\n", SDL_JoystickNumButtons(joystick));
printf("----> %d axes\n", SDL_JoystickNumAxes(joystick));
printf("----> %d trackballs\n", SDL_JoystickNumBalls(joystick));
printf("----> %d chapeaux\n", SDL_JoystickNumHats(joystick));


    while (1)
    {

    UpdateEvents();

    }

//        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); /* On efface l'écran */
//        SDL_BlitSurface(zozor, NULL, ecran, &positionZozor); /* On place zozor à sa nouvelle position */

        SDL_Flip(ecran); /* On met à jour l'affichage */
    }

    SDL_JoystickClose(joystick);
    SDL_FreeSurface(zozor);
    SDL_Quit();

    return EXIT_SUCCESS;
}


Pourriez-vous m'aider SVP ?
Hors ligne moi281184 # Posté le 16/05/2008 à 12:58:07
Groupe : Membres
En fait tu as commis une grosse erreur :

Code : C
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
int continuer = 1;
	SDL_Event event;

    SDL_Rect *positionZozor;

    SDL_Surface *ecran = NULL;
    SDL_Surface *zozor = NULL;

    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);


    /* Chargement de Zozor */
    zozor = SDL_LoadBMP("zozor.bmp");
    SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));


    /* On centre Zozor à l'écran */
    positionZozor.x = ecran->w / 2 - zozor->w / 2;
    positionZozor.y = ecran->h / 2 - zozor->h / 2;


Tu as mis tout ça dans ta boucle principale...

D'une part tu n'arriveras jamais à déplacer ton 'zozor' puisse qu'à chaque tour de boucle tu le replaces au centre, d'autre part j'imagine qu'à l'exécution il ne va pas aimer les accès systèmes en boucle (l'ouverture de fichier notamment).

Sort donc cette portion de code de ta fonction, mets les par exemple dans le main(), puis passe les en paramètre à ta fonction (ou au pire passe par des variables globales).

Ensuite tu dis que c'est la compilation qui plante ? est-ce la compilation où l'exécution ? Si c'est l'exécution ça n'a rien d'étonnant vu ton problème vu ci-dessus, par contre si c'est à la compilation qu'il y a un problème, quel est le message d'erreur ?

EDIT : autre problème :
Code : C
1
SDL_FreeSurface(zozor);

Tu as mis ça à la fin de ton main, mais zozor n'est déclaré que dans ta fonction UpdateEvents, aucune chance que celà compile.
Édité le 16/05/2008 à 13:02:33 par moi281184

Image utilisateur
Image utilisateur
Image utilisateur
 
Hors ligne Gaetano-FR # Posté le 16/05/2008 à 13:24:27
Avatar
Groupe : Membres
Bon, j'ai tout repris à zéro et juste repris la fonction de Fvirtman uniquement (le reste est dans le main).
Mais la compilation plante aux lignes 70 et 71 où je centre zozor à l'écran, avec le message d'erreur que j'ai mentionné en commentaire:

Voici mon code:

Code : C
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

char key[400];
int xsouris=0,xrelsouris=0,yrelsouris=0,ysouris=0;
char boutons[3]={0,0,0};

void UpdateEvents()
{
	SDL_Event event;
	while(SDL_PollEvent(&event))
	{
		switch (event.type)
		{
		case SDL_KEYDOWN:
			key[event.key.keysym.sym]=1;
			break;
		case SDL_KEYUP:
			key[event.key.keysym.sym]=0;
			break;
		case SDL_MOUSEMOTION:
			xsouris=event.motion.x;
			ysouris=event.motion.y;
			xrelsouris=event.motion.xrel;
			yrelsouris=event.motion.yrel;
			break;
		case SDL_MOUSEBUTTONDOWN:
			boutons[event.button.button-1]=1;
			break;
		case SDL_MOUSEBUTTONUP:
			boutons[event.button.button-1]=0;
			break;
		}
	}
}


int main(int argc, char *argv[])
{

    int i;

    SDL_Joystick *joystick = NULL;

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);

    SDL_JoystickEventState(SDL_ENABLE);
    joystick = SDL_JoystickOpen(0);


    SDL_Rect *positionZozor;

    SDL_Surface *ecran = NULL;
    SDL_Surface *zozor = NULL;


    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);


    /* Chargement de Zozor */
    zozor = SDL_LoadBMP("zozor.bmp");
    SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));


    /* On centre Zozor à l'écran */
    positionZozor.x = ecran->w / 2 - zozor->w / 2;  /* erreur: request for number 'x' in something not a structure or union */
    positionZozor.y = ecran->h / 2 - zozor->h / 2;  /* pareil:                    'y'      */


    SDL_EnableKeyRepeat(10, 10); // Répétition de touches


    printf("Il y a %d joysticks connectés\n", SDL_NumJoysticks());

    for (i = 0 ; i < SDL_NumJoysticks() ; i++ )
{
    printf("Joystick n°%d : %s\n", i, SDL_JoystickName(i));
}

printf("----> %d boutons\n", SDL_JoystickNumButtons(joystick));
printf("----> %d axes\n", SDL_JoystickNumAxes(joystick));
printf("----> %d trackballs\n", SDL_JoystickNumBalls(joystick));
printf("----> %d chapeaux\n", SDL_JoystickNumHats(joystick));



    while (1)
    {
    UpdateEvents();
    SDL_Flip(ecran); /* On met à jour l'affichage */
    }

    SDL_JoystickClose(joystick);
    SDL_FreeSurface(zozor);
    SDL_Quit();

    return EXIT_SUCCESS;
}


Voilà, j'espère que vous pourrez m'aider...Merci d'avance
Hors ligne moi281184 # Posté le 16/05/2008 à 13:37:40
Groupe : Membres
Code : C
1
SDL_Rect *positionZozor;


C'est un pointeur, pas une structure.

Fait donc comme ça :
Code : C
1
2
positionZozor->x = ecran->w / 2 - zozor->w / 2;
    positionZozor->y = ecran->h / 2 - zozor->h / 2;

Image utilisateur
Image utilisateur
Image utilisateur
 
Hors ligne Gaetano-FR # Posté le 16/05/2008 à 16:28:37
Avatar
Groupe : Membres
merci moi281184, mon code ne plante plus à la compilation mais la fenêtre s'ouvre et se referme aussitôt... :(

Mais de toute façon, ce précédent code ne gére pas les évènements joystick...

En incluant la gestion du joystick, j'arrive au code ci-dessous (là aussi, la fenêtre s'ouvre et se referme aussitôt):

Code : C
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

char key[400];
int xsouris=0,xrelsouris=0,yrelsouris=0,ysouris=0;
char boutons[3]={0,0,0};

SDL_Rect *positionZozor = NULL;

void UpdateEvents()
{
    int continuer = 1;
	SDL_Event event;
	while(SDL_PollEvent(&event))
	{while(continuer)
	{
		switch (event.type)
		{
        case SDL_QUIT:
        continuer = 0;
        break;

		case SDL_KEYDOWN:
			key[event.key.keysym.sym]=1;
			break;
		case SDL_KEYUP:
			key[event.key.keysym.sym]=0;
			break;
		case SDL_MOUSEMOTION:
			xsouris=event.motion.x;
			ysouris=event.motion.y;
			xrelsouris=event.motion.xrel;
			yrelsouris=event.motion.yrel;
			break;
		case SDL_MOUSEBUTTONDOWN:
			boutons[event.button.button-1]=1;
			break;
		case SDL_MOUSEBUTTONUP:
			boutons[event.button.button-1]=0;
			break;

        case SDL_JOYBUTTONDOWN:
        if (event.jbutton.button == 16) /* Arrêt du programme si on appuie sur le bouton n°16 */
            continuer = 0;
        break;

        case SDL_JOYAXISMOTION:

                SDL_Delay(10);

            if (event.jaxis.axis == 0 && event.jaxis.value < -3200) /* Vers la gauche */
            positionZozor->x--;

            else if (event.jaxis.axis == 0 && event.jaxis.value > 3200) /* Vers la droite */
            positionZozor->x++;

            else if (event.jaxis.axis == 1 && event.jaxis.value < -3200) /* Vers le haut */
            positionZozor->y--;

            else if (event.jaxis.axis == 1 && event.jaxis.value > 3200) /* Vers le bas */
            positionZozor->y++;

            break;

            default: continuer = 1;
                        break;
		}
		}
	}
}


int main(int argc, char *argv[])
{

    int i;

    SDL_Joystick *joystick = NULL;

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);

    SDL_JoystickEventState(SDL_ENABLE);
    joystick = SDL_JoystickOpen(0);




    SDL_Surface *ecran = NULL;
    SDL_Surface *zozor = NULL;


    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);


    /* Chargement de Zozor */
    zozor = SDL_LoadBMP("zozor.bmp");
    SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));


    /* On centre Zozor à l'écran */
    positionZozor->x = ecran->w / 2 - zozor->w / 2;  /* erreur: request for number 'x' in something not a structure or union */
    positionZozor->y = ecran->h / 2 - zozor->h / 2;  /* pareil:                    'y'      */


    SDL_EnableKeyRepeat(10, 10); // Répétition de touches


    printf("Il y a %d joysticks connectés\n", SDL_NumJoysticks());

    for (i = 0 ; i < SDL_NumJoysticks() ; i++ )
{
    printf("Joystick n°%d : %s\n", i, SDL_JoystickName(i));
}

printf("----> %d boutons\n", SDL_JoystickNumButtons(joystick));
printf("----> %d axes\n", SDL_JoystickNumAxes(joystick));
printf("----> %d trackballs\n", SDL_JoystickNumBalls(joystick));
printf("----> %d chapeaux\n", SDL_JoystickNumHats(joystick));


    while (1)
    {
    UpdateEvents();
//    SDL_BlitSurface(zozor, NULL, ecran, &positionZozor); /* On place zozor à sa nouvelle position */
    SDL_Flip(ecran); /* On met à jour l'affichage */
    }

    SDL_JoystickClose(joystick);
    SDL_FreeSurface(zozor);
    SDL_Quit();

    return EXIT_SUCCESS;
}


D'où vient ce même problème ??

Retour au forum "Langage C" ou à la liste des forums

Vous devez être inscrit pour pouvoir poster des messages

Changer de design | En savoir plus | Plan du site | Politique d'accessibilité | Règles | RSS tutoriels | RSS news
Édité par Simple IT SARL : Nous contacter | Notre blog | Revue de presse | Publicité

Y'a plus rien à lire, faut remonter maintenant !

Hébergement web - Correction de tutoriels - Créer un site
Vous souhaitez apparaître ici ? Contactez-nous.