Seite 1 von 1

Sprite richtig am Horizont spiegeln(Wasser-effekt)

Verfasst: 18.11.2007 16:43
von Rings
Bild

Code: Alles auswählen

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
  End
EndIf
If InitSprite3D() = 0
  MessageRequester("Error", "Direct3D system can't be initialized correctly", 0)
  End
EndIf

Procedure SpriteMirrorHorizontal(SpriteID)
;Mirrors a sprite horizontal
StartDrawing(SpriteOutput(SpriteID))
 IW = SpriteWidth(SpriteID) 
 IH = SpriteHeight(SpriteID)
 Buffer      = DrawingBuffer()             ; Get the start address of the screen buffer
 Pitch       = DrawingBufferPitch()        ; Get the length (in byte) took by one horizontal line
  
 *pxData1.LONG = Buffer
 *pxData2.LONG = *pxData1 + (IH-1)*Pitch

 mem=AllocateMemory(Pitch)
 For lines=0 To IH/2-1
  CopyMemory(*pxData1,mem,pitch)
  CopyMemory(*pxData2,*pxData1,pitch)
  CopyMemory(mem,*pxData2,pitch)
  *pxData1 + pitch
  *pxData2 - pitch
 Next
 StopDrawing() 
 If mem: FreeMemory(mem):EndIf
  
EndProcedure
If OpenScreen(800,600, 32, "Sprite")

  LoadSprite(0, "Data\Geebee2.bmp", #PB_Sprite_Texture)
  TransparentSpriteColor(0, RGB(255, 0, 255)) ; Our pink is transparent :)
    StartDrawing(SpriteOutput(0))
     Box(0,0,30,30,RGB(250,250,50))
    StopDrawing()
  CopySprite(0,1,  #PB_Sprite_Texture)
  SpriteMirrorHorizontal(1)
  TransparentSpriteColor(1, RGB(255, 0, 255)) ; Our pink is transparent :)
  CreateSprite3D(0, 0)
  CreateSprite3D(1, 1)
  ZoomSprite3D(1,SpriteWidth(1),SpriteHeight(1)*1.5)
  f1.f=1;0.5
  Repeat
    FlipBuffers()
   
    ClearScreen(RGB(200,200,255))
    StartDrawing(ScreenOutput())
     Box (0,130+SpriteHeight(0),800,600-130-SpriteHeight(0),RGB(50,50,250))
    StopDrawing()
    ; Draw our sprite
    If Start3D()
      DisplaySprite3D(0, 200, 130);original
      b=b+f1
      If b>5
       f1=f1*-1
      EndIf 
      If b<-5
       f1=f1*-1
      EndIf 

      ZoomSprite3D(1,SpriteWidth(1),SpriteHeight(1)*1.5 - b)
      DisplaySprite3D(1, 200, 130+SpriteHeight(0),64)
      Stop3D()
    EndIf
    ExamineKeyboard()
    x+1
  Until x > 2500 Or KeyboardPushed(#PB_Key_Escape)
Else
  MessageRequester("Error", "Can't open a screen !", 0)
EndIf
End  

Re: Sprite richtig am Horizont spiegeln(Wasser-effekt)

Verfasst: 11.11.2018 21:06
von RSBasic
*alten Thread herauskram*
Das ist der einzige Code, den ich gefunden habe, der (nach der Anpassung auf die neuste PB-Version) funktioniert. Kann jemand diesen Code für mich so umbauen, damit man Sprites auch vertikal spiegeln kann?

Re: Sprite richtig am Horizont spiegeln(Wasser-effekt)

Verfasst: 11.11.2018 22:38
von ccode_new
Ich verweise nur einmal hier drauf:

viewtopic.php?f=8&t=31076

__________________________________________________
Domain angepasst
11.11.2018
RSBasic


Hier für einmal für Shader-Liebhaber:

Code: Alles auswählen

#version 120
//Horizontal Spiegeln (Windows-Version)
uniform sampler2D color_texture;
uniform vec2 resolution;
void main() {
	vec2 pos = gl_FragCoord.xy/resolution;
	pos.y = -pos.y;
	pos.x = resolution.x-pos.x;
	vec4 color = texture2D(color_texture, -pos);
	gl_FragColor = color;
}

Code: Alles auswählen

#version 120
//Vertikal Spiegeln (Windows-Version)
uniform sampler2D color_texture;
uniform vec2 resolution;
void main() {
	vec2 pos = gl_FragCoord.xy/resolution;
	vec4 color = texture2D(color_texture, -pos);
	gl_FragColor = color;
}

Re: Sprite richtig am Horizont spiegeln(Wasser-effekt)

Verfasst: 11.11.2018 23:15
von RSBasic
ccode_new hat geschrieben:Ich verweise nur einmal hier drauf:
viewtopic.php?f=8&t=31076
Danke für den Code. Nachdem ich diese Prozedur umgebaut habe, so dass Sprites stattdessen gespiegelt werden, funktioniert es und ist bei 400 Sprites (ohne Debugger) nur minimal langsamer, als der Code von Rings. :allright: