IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SDL Discussion :

Rotation Image / Positionnement / SDL_gfx


Sujet :

SDL

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut Rotation Image / Positionnement / SDL_gfx
    Bonjour,
    Je cherche à faire développer un tower defense. Pour cela, j'aurais besoin de developper une fonctionalité qui permet aux tourelles de tourner.
    J'ai donc ecrit ce code mais le positionnement ne marche pas et il y a une bande noire dont je n'arrive pas à me débarasser.

    Voici le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    void RotationSdl(SdlJeu *sj, SDL_Surface * ecran, int xtank, int ytank, int xtourelle, int ytourelle, int type)
    {
    	SDL_Surface * rotation = NULL;
    	double angle=45;
    	SDL_Rect pos;
    	pos.x=xtourelle;
    	pos.y=ytourelle;
    	{
    		if(type==2)
    		{
    			/*angle=tan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank));*/
    			rotation=rotozoomSurface(sj->image->imgtourelle[6], angle, 1.0, 1);
                            SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
    			SDL_SetAlpha(rotation, SDL_RLEACCEL, 0);
    			AffichageImageSdlJeu (rotation, ecran, xtourelle, ytourelle);
            		pos.x =  xtourelle - rotation->w / 2; //Test du positionnement de l'image en fonction de la taille
            		pos.y =  ytourelle - rotation->h / 2;
    			angle++;
    		}
     
    		if(type==3)
    		{
    			/*angle=tan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank));*/
    			rotation=rotozoomSurface(sj->image->imgtourelle[8], angle, 1.0, 1);
                            SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
    			SDL_SetAlpha(rotation, SDL_RLEACCEL, 0);
    			AffichageImageSdlJeu (rotation, ecran, xtourelle,  ytourelle);
    			pos.x =  xtourelle - rotation->w * 2; //ReTest du positionnement
            		pos.y =  ytourelle - rotation->h * 2;
    			angle++;
    		}
    	SDL_FreeSurface(rotation);
    	}
    }
    Et voici ce que cela me donne :

    http://imageshack.us/photo/my-images...eenshotxvi.png

    Merci de bien vouloir m'aider

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    Sinon personne aurait un bon tuto sur sdl_gfx ?
    Merci

  3. #3
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 575
    Points
    218 575
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Je me demande quels sont les fichiers utilisés à la base. Je veux dire par là, que je pense que vous aurez moins de soucis, si vous utilisez un sprite qui ne contient que la terre (le sol) et un sprite qui ne contient que la tourelle (et ce uniquement celui ci que l'on tourne).
    Si tel est déjà le cas, alors il y a un problème avec la gestion de l'alpha. Peut être faudra t-il refaire la commande pour indiquer la couleur de transparence à la SDL.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    Bonjour,
    déjà merci pour votre réponse, ensuite j'utilise bien un sprite pour le terrain, un autre pour la base de la tourelle et un troisième pour le canon.
    Donc, dans ma fonctionnalité je veux juste faire tourner l'image du canon.

    Dans mon code (que j'ai un peu retouché), j'essaye déjà de m'occuper de la transparence du noir avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
    voici le code complet

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    void RotationSdl(SdlJeu *sj, SDL_Surface * ecran, int xtank, int ytank, int xtourelle, int ytourelle, int type)
    {
    	SDL_Surface * rotation = NULL;
    	double angle;
    	SDL_Rect pos;
    	pos.x=xtourelle;
    	pos.y=ytourelle;
     
    	if(ytourelle<ytank && xtourelle>xtank)
    	{
    		angle=90+(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
    	}
    	else if (ytourelle>ytank && xtourelle>xtank)
    	{
    		angle=90-(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
    	}
    	else if (ytourelle>ytank && xtourelle<xtank)
    	{
    		angle=270+(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
    	}
    	else if (ytourelle<ytank && xtourelle<xtank)
    	{
    		angle=270-(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
    	}
    	if(type==2)
    	{
    		rotation=rotozoomSurface(sj->image->imgtourelle[6], angle, 1.0, 1);
    	}
    	if(type==3)
    	{
    		rotation=rotozoomSurface(sj->image->imgtourelle[8], angle, 1.0, 1);
    	}
     
    	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
    	SDL_SetAlpha(rotation, SDL_RLEACCEL, 0);
    	AffichageImageSdlJeu (rotation, ecran, xtourelle,  ytourelle);
    	pos.x =  xtourelle - rotation->w / 2; /*ReTest du positionnement*/
            pos.y =  ytourelle - rotation->h / 2;
    	SDL_FreeSurface(rotation);
    }
    Merci beaucoup pour l'aide !

  5. #5
    Membre émérite Avatar de Djakisback
    Profil pro
    Inscrit en
    Février 2005
    Messages
    2 021
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 2 021
    Points : 2 278
    Points
    2 278
    Par défaut
    Salut,
    peut-être une réponse ici : http://www.developpez.net/forums/d70...tozoomsurface/
    Vive les roues en pierre

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    Oui, je comprends pourquoi ça marche pas maintenant mais comment je définis la transparance pixel par pixel alors ?

  7. #7
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 575
    Points
    218 575
    Billets dans le blog
    120
    Par défaut
    Je pense qu'il faut virer le SetAlpha ( http://www.gamedev.net/topic/501621-...-transparency/ )
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    Ok, je l'ai enlevé donc il n'y a plus de noir mais la transparence avec l'image du canon ne se fait plus

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    void RotationSdl(SdlJeu *sj, SDL_Surface * ecran, int xtank, int ytank, int xtourelle, int ytourelle, int type)
    {
    	SDL_Surface * rotation = NULL;
    	double angle;
    	SDL_Rect pos;
    	pos.x=xtourelle;
    	pos.y=ytourelle;
     
    	if(ytourelle<=ytank && xtourelle>=xtank)
    	{
    		angle=90+(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
    	}
    	else if (ytourelle>ytank && xtourelle>xtank)
    	{
    		angle=90-(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
    	}
    	else if (ytourelle>=ytank && xtourelle<=xtank)
    	{
    		angle=270+(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
    	}
    	else if (ytourelle<ytank && xtourelle<xtank)
    	{
    		angle=270-(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
    	}
    	if(type==2)
    	{
    		rotation=rotozoomSurface(sj->image->imgtourelle[6], angle, 1.0, 1);
    	}
    	if(type==3)
    	{
    		rotation=rotozoomSurface(sj->image->imgtourelle[8], angle, 1.0, 1);
    	}
    	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
    	pos.x =  pos.x - rotation->w/20 ; 
            pos.y =  pos.y - rotation->h/20 ;
    	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL|SDL_SRCALPHA), SDL_MapRGB(rotation->format, 255, 0, 255));
    	SDL_BlitSurface(rotation, NULL, ecran, &pos);
            SDL_FreeSurface(rotation); //On efface rotation car on va la redéfinir dans la prochaine boucle. Si on ne le fait pas, cela crée une fuite de mémoire. 
    }
    voici l'image que j'ai :

    http://www.noelshack.com/2012-22-133...reenshot-1.png

    Merci de l'aide

  9. #9
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 575
    Points
    218 575
    Billets dans le blog
    120
    Par défaut
    Au final, pourquoi n'utilisez vous pas des fichiers en PNG ayant un canal alpha ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    En fait j'ai déjà essayé mais je ne sais pas comment ça s'utilise donc j'ai des problemes de segmentation.
    Y a pas un moyen facile de faire avec des bmp vu qu'il ne manque plus que la transparence du canon à faire ?

  11. #11
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 575
    Points
    218 575
    Billets dans le blog
    120
    Par défaut
    On peut faire un BMP en 32bits, qui aura donc une couche d'alpha, mais le PNG restait une meilleure solution.
    Vous chargez vos images avec SDL_image ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  12. #12
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    Je charge mes images comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    	SDL_Rect pos;
    	pos.x = (int) x;
    	pos.y = (int) y;
    	SDL_SetColorKey (img, SDL_SRCCOLORKEY, SDL_MapRGB (img->format,255 ,0,255));
    	SDL_BlitSurface(img, NULL, ecran, &pos);

  13. #13
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 575
    Points
    218 575
    Billets dans le blog
    120
    Par défaut
    Non ça c'est pour l'affichage. En SDL le chargement se fait avec SDL_LoadBMP() et avec SDL_image en utilisant IMG_Load()
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  14. #14
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    ah oui pardon, j'utilise SDL_LoadBMP()

  15. #15
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 575
    Points
    218 575
    Billets dans le blog
    120
    Par défaut
    Je vous conseille d'utiliser SDL_image afin de charger des PNG, qui auront un canal de transparence.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  16. #16
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    Juste pour les canons ou pour toutes les images ?

  17. #17
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 575
    Points
    218 575
    Billets dans le blog
    120
    Par défaut
    Autant toutes les faire
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  18. #18
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    Voilà c'est fait mais en gardant le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    if(type==2)
    	{
    		rotation=rotozoomSurface(sj->image->imgtourelle[6], angle, 1.0, 1);
    	}
    	if(type==3)
    	{
    		rotation=rotozoomSurface(sj->image->imgtourelle[8], angle, 1.0, 1);
    	}
    	SDL_SetAlpha(rotation, SDL_RLEACCEL, 1);
    	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
     
    	pos.x =  pos.x - rotation->w/20 ; 
            pos.y =  pos.y - rotation->h/20 ;
     
    	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL|SDL_SRCALPHA), SDL_MapRGB(rotation->format, 255, 0, 255));
    	SDL_BlitSurface(rotation, NULL, ecran, &pos);
            SDL_FreeSurface(rotation);
    la bande noire est toujours là !

  19. #19
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 575
    Points
    218 575
    Billets dans le blog
    120
    Par défaut
    Enlevez les lignes de SDL_SetColorKey()
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  20. #20
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    95
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 95
    Points : 52
    Points
    52
    Par défaut
    Voilà c'est fait et maintenant il n'y pas de transparance avec le noir et le rose !

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. rotation image/volume autre que la fonction de base
    Par S4sha dans le forum Général Python
    Réponses: 0
    Dernier message: 18/02/2010, 12h56
  2. rotation image et taille fixe
    Par slim_java dans le forum 2D
    Réponses: 3
    Dernier message: 04/08/2009, 03h15
  3. Rotation image from powerpoint
    Par cuterate dans le forum Word
    Réponses: 2
    Dernier message: 27/08/2008, 14h27
  4. GdiPlus : Rotation image / Décomposition des Gifs animés
    Par Arkham46 dans le forum Contribuez
    Réponses: 5
    Dernier message: 30/03/2008, 21h07
  5. Algorithme pour rotation image en C
    Par guigui01 dans le forum Traitement d'images
    Réponses: 6
    Dernier message: 22/04/2006, 14h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo