Seite 1 von 1
Sprite und Sprite3D Kollision bzw Sprite3D udn Sprite3D K.!!
Verfasst: 23.12.2004 21:06
von Lukas-P
Hallo,
wie stell ich eine pixel Kollision von einem Sprite3D und einem normalen Sprite fest?
[EDIT]
ODER wie stellle ich fest ob sich zwei Sprite ds "Kollisionieren"(Komisches Wort)???
Am besten eine Pixel Kollision

Verfasst: 23.12.2004 23:46
von Laurin
Ich glaube, das geht nicht.
1) Ich habe hier noch nie gehört, dass einer so eine Kollision angewendet hat.
2) Sprite3D ist ein 3D-Objekt (auf einer 2D-Ebene), das normale Sprite aber ein 2D-Objekt. Das geht schon wegen den Dimensionen halt nicht.
(Alle Aussagen ohne Gewähr, weil teilweise fehlendes Wissen. Müsste aber von der Logik her alles stimmen, oder?)
Greetz Laurin
(Auweia, so ein vages Posting habe ich noch nie gemacht.)
Verfasst: 24.12.2004 13:07
von Lukas-P
Kann ich denn irgendwie ein normales Sprite rotieren?
Verfasst: 24.12.2004 13:10
von Kaeru Gaman
Verfasst: 24.12.2004 13:16
von Lukas-P
thx ich hoffe mal das die Procedure:
Code: Alles auswählen
Procedure PutRotatedSprite(Sprite,XPos,YPos,Angle.f)
*Sprite.PB_Sprite=IsSprite(Sprite)
If *Sprite=0:ProcedureReturn 0:EndIf
Angle.f=Angle*0.017453; *(ACos(-1)*2)/360
Cos=Cos(Angle.f)*2048
Sin=Sin(Angle.f)*2048
NSin=-Sin
SpriteWidth=*Sprite\Width-1
SpriteHeight=*Sprite\Height-1
StartX=*Sprite\ClipX
StartY=*Sprite\ClipY
EndX=SpriteWidth+StartX
EndY=SpriteHeight+StartY
SpriteWidth2=(SpriteWidth)/2+StartX
SpriteHeight2=(SpriteHeight)/2+StartY
ScreenWidth=_ScreenWidth()-1
ScreenHeight=_ScreenHeight()-1
*SpriteDDS.IDirectDrawSurface7=*Sprite\Sprite
*DestDDS.IDirectDrawSurface7=GetCurrentBuffer()
SpriteDDSD2.DDSURFACEDESC2
DestDDSD2.DDSURFACEDESC2
SpriteDDSD2\dwSize=SizeOf(DDSURFACEDESC2)
DestDDSD2\dwSize=SizeOf(DDSURFACEDESC2)
*SpriteDDS\Lock(0,SpriteDDSD2,#DDLOCK_WAIT,0);schließt den Sprite-
*DestDDS\Lock(0,DestDDSD2,#DDLOCK_WAIT,0);und Rendering-Buffer, damit man direkt auf den Speicher zugreifen kann.
SrcPitch=SpriteDDSD2\lPitch
DestPitch=DestDDSD2\lPitch
SrcAddr=SpriteDDSD2\lpSurface
DestAddr=DestDDSD2\lpSurface
PixelFormat=GetPixelFormat()
x=Sqr(Pow((*Sprite\Width+1)/2,2)+Pow((*Sprite\Height+1)/2,2))
If XPos-x>=0 And YPos-x>=0 And XPos+x<=ScreenWidth And YPos+x<=ScreenHeight ;Kann das Bild komplett dargestellt werden ?
;======================================================================
If PixelFormat=#PB_PixelFormat_8Bits
For y=StartY To EndY
*SrcPtr.Long=SrcAddr+y*SrcPitch+StartX ;Berechnet die Startadresse
Yv1=((y-SpriteHeight2)*NSin)>>11+XPos
Yv2=((y-SpriteHeight2)*Cos)>>11+YPos
For x=StartX To EndX
Color=*SrcPtr\l&$FF
PokeW(DestAddr+((((x-SpriteWidth2)*Sin)>>11+Yv2))*DestPitch+(((x-SpriteWidth2)*Cos)>>11+Yv1),Color+Color<<8) ;Zeichnet den Pixel
*SrcPtr+1
Next
Next
EndIf
If PixelFormat=#PB_PixelFormat_15Bits Or PixelFormat=#PB_PixelFormat_16Bits
For y=StartY To EndY
*SrcPtr.Long=SrcAddr+y*SrcPitch+StartX*2 ;Berechnet die Startadresse
Yv1=((y-SpriteHeight2)*NSin)>>11+XPos
Yv2=((y-SpriteHeight2)*Cos)>>11+YPos
For x=StartX To EndX
Color=*SrcPtr\l&$FFFF
PokeL(DestAddr+(((x-SpriteWidth2)*Sin)>>11+Yv2)*DestPitch+(((x-SpriteWidth2)*Cos)>>11+Yv1)*2,Color+Color<<16) ;Zeichnet den Pixel
*SrcPtr+2
Next
Next
EndIf
If PixelFormat=#PB_PixelFormat_24Bits_RGB Or PixelFormat=#PB_PixelFormat_24Bits_BGR
For y=StartY To EndY
*SrcPtr.Long=SrcAddr+y*SrcPitch+StartX*3 ;Berechnet die Startadresse
Yv1=((y-SpriteHeight2)*NSin)>>11+XPos
Yv2=((y-SpriteHeight2)*Cos)>>11+YPos
For x=StartX To EndX
Color=*SrcPtr\l
Addr=DestAddr+(((x-SpriteWidth2)*Sin)>>11+Yv2) *DestPitch+(((x-SpriteWidth2)*Cos)>>11+Yv1)*3 ;Zeichnet den Pixel
PokeW(Addr,Color)
PokeL(Addr+2,Color>>16|Color<<8)
*SrcPtr+3
Next
Next
EndIf
If PixelFormat=#PB_PixelFormat_32Bits_RGB Or PixelFormat=#PB_PixelFormat_32Bits_BGR
For y=StartY To EndY
*SrcPtr.Long=SrcAddr+y*SrcPitch+StartX*4 ;Berechnet die Startadresse
Yv1=((y-SpriteHeight2)*NSin)>>11+XPos
Yv2=((y-SpriteHeight2)*Cos)>>11+YPos
For x=StartX To EndX
Color=*SrcPtr\l
Addr=DestAddr+(((x-SpriteWidth2)*Sin)>>11+Yv2) *DestPitch+(((x-SpriteWidth2)*Cos)>>11+Yv1)*4 ;Zeichnet den Pixel
PokeL(Addr,Color)
PokeL(Addr+4,Color)
*SrcPtr+4
Next
Next
EndIf
;======================================================================
Else
;======================================================================
If PixelFormat=#PB_PixelFormat_8Bits
For y=StartY To EndY
*SrcPtr.Long=SrcAddr+y*SrcPitch+StartX ;Berechnet die Startadresse
Yv1=((y-SpriteHeight2)*NSin)>>11+XPos
Yv2=((y-SpriteHeight2)*Cos)>>11+YPos
For x=StartX To EndX
Xp=((x-SpriteWidth2)*Cos)>>11+Yv1 ;Berechnet die Position des Pixels
Yp=((x-SpriteWidth2)*Sin)>>11+Yv2
If Xp>=0 And Xp<ScreenWidth And Yp>=0 And Yp<=ScreenHeight
Color=*SrcPtr\l&$FF
PokeW(DestAddr+Yp*DestPitch+Xp,Color+Color<<8) ;Zeichnet den Pixel
EndIf
*SrcPtr+1
Next
Next
EndIf
If PixelFormat=#PB_PixelFormat_15Bits Or PixelFormat=#PB_PixelFormat_16Bits
For y=StartY To EndY
*SrcPtr.Long=SrcAddr+y*SrcPitch+StartX*2 ;Berechnet die Startadresse
Yv1=((y-SpriteHeight2)*NSin)>>11+XPos
Yv2=((y-SpriteHeight2)*Cos)>>11+YPos
For x=StartX To EndX
Xp=((x-SpriteWidth2)*Cos)>>11+Yv1 ;Berechnet die Position des Pixels
Yp=((x-SpriteWidth2)*Sin)>>11+Yv2
If Xp>=0 And Xp<ScreenWidth And Yp>=0 And Yp<=ScreenHeight
Color=*SrcPtr\l&$FFFF
PokeL(DestAddr+Yp*DestPitch+Xp*2,Color+Color<<16) ;Zeichnet den Pixel
EndIf
*SrcPtr+2
Next
Next
EndIf
If PixelFormat=#PB_PixelFormat_24Bits_RGB Or PixelFormat=#PB_PixelFormat_24Bits_BGR
For y=StartY To EndY
*SrcPtr.Long=SrcAddr+y*SrcPitch+StartX*3 ;Berechnet die Startadresse
Yv1=((y-SpriteHeight2)*NSin)>>11+XPos
Yv2=((y-SpriteHeight2)*Cos)>>11+YPos
For x=StartX To EndX
Xp=((x-SpriteWidth2)*Cos)>>11+Yv1 ;Berechnet die Position des Pixels
Yp=((x-SpriteWidth2)*Sin)>>11+Yv2
If Xp>=0 And Xp<ScreenWidth And Yp>=0 And Yp<=ScreenHeight
Color=*SrcPtr\l
Addr=DestAddr+Yp*DestPitch+Xp*3 ;Zeichnet den Pixel
PokeW(Addr,Color)
PokeL(Addr+2,Color>>16|Color<<8)
EndIf
*SrcPtr+3
Next
Next
EndIf
If PixelFormat=#PB_PixelFormat_32Bits_RGB Or PixelFormat=#PB_PixelFormat_32Bits_BGR
For y=StartY To EndY
*SrcPtr.Long=SrcAddr+y*SrcPitch+StartX*4 ;Berechnet die Startadresse
Yv1=((y-SpriteHeight2)*NSin)>>11+XPos
Yv2=((y-SpriteHeight2)*Cos)>>11+YPos
For x=StartX To EndX
Xp=((x-SpriteWidth2)*Cos)>>11+Yv1 ;Berechnet die Position des Pixels
Yp=((x-SpriteWidth2)*Sin)>>11+Yv2
If Xp>=0 And Xp<ScreenWidth And Yp>=0 And Yp<=ScreenHeight
Color=*SrcPtr\l
Addr=DestAddr+Yp*DestPitch+Xp*4 ;Zeichnet den Pixel
PokeL(Addr,Color)
PokeL(Addr+4,Color)
EndIf
*SrcPtr+4
Next
Next
EndIf
;======================================================================
EndIf
*SpriteDDS\UnLock(0) ;Öffnet den Sprite-Buffer und den Rendering-Buffer wieder.
*DestDDS\UnLock(0)
ProcedureReturn -1
EndProcedure
Funktioniert
Verfasst: 24.12.2004 13:19
von Kaeru Gaman
hey luke, musst du denn die ganze proc zitieren, für den einen satz
'ich hoffe dass sie funktioniert' ???

Verfasst: 24.12.2004 14:02
von Lukas-P
Ich glaub ich hab ne Kreiskollision noch hinbekommen:
Code: Alles auswählen
Procedure.w sprite3dcollision(sprite1x,sprite1y,sprite2x,sprite2y,sprite2D1,sprite2D2)
Sprite3D_1_Radius.f = Sqr(Pow(SpriteWidth(sprite2D1), 2) + Pow(SpriteHeight(sprite2D1), 2))
Sprite3D_2_Radius.f = Sqr(Pow(SpriteWidth(sprite2D2), 2) + Pow(SpriteHeight(sprite2D2), 2))
If Sqr(Pow(sprite2x - sprite1x, 2) + Pow(sprite2y - sprite1y, 2)) <= Sprite3D_1_Radius + Sprite3D_2_Radius
ProcedureReturn 1
EndIf
EndProcedure