Comment faire un sprite pivotant

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Micoute
Messages : 2584
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Comment faire un sprite pivotant

Message par Micoute »

Bonjour à tous, je souhaite faire un sprite rotatif, mais je n'arrive pas à afficher la face arrière qui est normalement le miroir de la face avant.

je vous remercie d'avance de vos solution

Code : Tout sélectionner

InitSprite()

OpenWindow(0, 0, 0, 800, 600, "Ecran", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

SpriteQuality(1)

Font = FontID(LoadFont(#PB_Any, "Arial", 192))
CreateSprite(1, 256, 256, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(1))
  DrawingFont(Font) : DrawingMode(1)
  Box(0,0,256,256,$FF0000)
  DrawText(20, 0, "M", $0000FF, 0)
StopDrawing()

Repeat

  ClearScreen(0)

  a.f = ElapsedMilliseconds()/1000
     
  ZoomSprite(1, 200*Sin(a), 200)
  DisplayTransparentSprite(1, 400-100*Sin(a), 200)

  FlipBuffers()

Until WindowEvent() = #PB_Event_CloseWindow 
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Comment faire un sprite pivotant

Message par falsam »

Bonjour Micoute.

La face cachée d'un sprite: C'est drole parce mon sujet d'exploration depuis quelques jours était comment afficher les faces cachées d'un objet 3D et j'avais découvert (partiellement) le sens du mot Culling.

C'est moins impressionnant en 2D mais cette notion existe aussi en 2D et se résume à implanter cette procédure.

Code : Tout sélectionner

;Disable Backface Culling
Procedure BackFaceCullingDisable()
  Global pd3d.IDirect3DDevice9

  EnableASM
  !extrn _PB_Screen_Direct3DDevice
  !MOV dword EAX, [_PB_Screen_Direct3DDevice]
  !MOV dword [v_pd3d],EAX
  DisableASM
  
  pd3d\SetRenderState(22,1)
  pd3d\SetRenderState(7,0)
EndProcedure
Que ce soit à l'endroit ou à l'envers, un M reste un M :)

Code : Tout sélectionner

;Disable Backface Culling
Procedure BackFaceCullingDisable()
  Global pd3d.IDirect3DDevice9

  EnableASM
  !extrn _PB_Screen_Direct3DDevice
  !MOV dword EAX, [_PB_Screen_Direct3DDevice]
  !MOV dword [v_pd3d],EAX
  DisableASM
  
  pd3d\SetRenderState(22,1)
  pd3d\SetRenderState(7,0)
EndProcedure

InitSprite()

OpenWindow(0, 0, 0, 800, 600, "Ecran", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

SpriteQuality(1)

Font = FontID(LoadFont(#PB_Any, "Arial", 192))
CreateSprite(1, 256, 256, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(1))
  DrawingFont(Font) : DrawingMode(1)
  Box(0,0,256,256,$FF0000)
  DrawText(20, 0, "E", $0000FF, 0)
StopDrawing()

BackFaceCullingDisable()

Repeat

  ClearScreen(0)

  ;a.f = ElapsedMilliseconds()/1000  
  ;ZoomSprite(1, 200*Sin(a), 200)
  ;DisplayTransparentSprite(1, 400-100*Sin(a), 200)
  
  x+Rh
  TransformSprite(1, x,0, SpriteWidth(1)-x,0, SpriteWidth(1)-x,SpriteHeight(1), x, SpriteHeight(1))     
  
  If x>SpriteWidth(1) ;
    Rh=-1
  ElseIf X=0
    Rh=1
  EndIf
  
  DisplayTransparentSprite(1, 150, 100) 
  FlipBuffers()

Until WindowEvent() = #PB_Event_CloseWindow 
J'ai tiré cette procédure de ce que j'ai posté sur ce lien.
:arrow: http://www.purebasic.fr/french/viewtopi ... 24#p169124
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Micoute
Messages : 2584
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: Comment faire un sprite pivotant

Message par Micoute »

Merci beaucoup falsam, c'est exactement ce que je voulais faire, c'est en redécouvrant ce vieux programme qui fonctionnait avec des sprites 3d, que j'ai eut l'idée de le remettre à jour, du coup c'est réussi.

Merci encore.
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Répondre