Page 1 sur 1

Comment faire un sprite pivotant

Publié : ven. 19/déc./2014 10:42
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 

Re: Comment faire un sprite pivotant

Publié : ven. 19/déc./2014 11:21
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

Re: Comment faire un sprite pivotant

Publié : ven. 19/déc./2014 14:32
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.