C'est pas très optimisé , mais ca à le mérite d'être vu
Code : Tout sélectionner
;
; - SUPERSPRITE3D - PAR CPL.BATOR
;
Procedure.b InitSuperSprite3D()
If InitSprite()
#Flip_Vertically = $001
#Flip_Horizontally = $010
Structure MATRIX4x4
_11.f : _21.f : _31.f : _41.f
_12.f : _22.f : _32.f : _42.f
_13.f : _23.f : _33.f : _43.f
_14.f : _24.f : _34.f : _44.f
EndStructure
Structure VECTOR2
x.f : y.f
EndStructure
Structure VECTOR3 Extends VECTOR2
z.f
EndStructure
Structure CAMERA
Position.VECTOR3
LookAT.VECTOR3
Rotation.VECTOR3
Pitch.f
Yaw.f
Roll.f
EndStructure
Structure vertex
sx.f
sy.f
sz.f
rhw.f
Color.l
specular.l
tu.f
tv.f
EndStructure
Structure SuperSprite3D
No.l
Size_X.l
Size_Y.l
A3D.VECTOR3 : A2D.VECTOR2
B3D.VECTOR3 : B2D.VECTOR2
C3D.VECTOR3 : C2D.VECTOR2
D3D.VECTOR3 : D2D.VECTOR2
VA3D.VECTOR3
VB3D.VECTOR3
VC3D.VECTOR3
VD3D.VECTOR3
MatriceProjection.MATRIX4x4
MatriceRotation.MATRIX4x4
MatriceTranslation.MATRIX4x4
Camera.CAMERA
EndStructure
Structure PB_Sprite3D
Texture.l
Vertice.vertex[4]
Width.w
Height.w
EndStructure
Global NewList SS3D.l(),V.VECTOR3
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Macro MATRICE_Rotate_XYZ(MATRICE,Xa,Ya,Za)
MATRICE#\_11=Cos(Za#)*Cos(Ya#) :MATRICE#\_21=Sin(Za#)*Cos(Ya#) :MATRICE#\_31=-Sin(Ya#) :MATRICE#\_41=0
MATRICE#\_12=Cos(Za#)*Sin(Ya#)*Sin(Xa#)-Sin(Za#)*Cos(Xa#):MATRICE#\_22=Sin(Za#)*Sin(Ya#)*Sin(Xa#)+Cos(Xa#)*Cos(Za#):MATRICE#\_32=Sin(Xa#)*Cos(Ya#):MATRICE#\_42=0
MATRICE#\_13=Cos(Za#)*Sin(Ya#)*Cos(Xa#)+Sin(Za#)*Sin(Xa#):MATRICE#\_23=Sin(Za#)*Sin(Ya#)*Cos(Xa#)-Cos(Za#)*Sin(Xa#):MATRICE#\_33=Cos(Xa#)*Cos(Ya#):MATRICE#\_43=0
MATRICE#\_14=0 :MATRICE#\_24=0 :MATRICE#\_34=0 :MATRICE#\_44=1
EndMacro
Macro MATRICE_Translate_XYZ(MATRICE,xi,yi,zi)
MATRICE#\_11=1:MATRICE#\_21=0:MATRICE#\_31=0:MATRICE#\_41=xi#
MATRICE#\_12=0:MATRICE#\_22=1:MATRICE#\_32=0:MATRICE#\_42=yi#
MATRICE#\_13=0:MATRICE#\_23=0:MATRICE#\_33=1:MATRICE#\_43=zi#
MATRICE#\_14=0:MATRICE#\_24=0:MATRICE#\_34=0:MATRICE#\_44=1
V\x=MATRICE#\_41
V\y=MATRICE#\_42
V\z=MATRICE#\_43
EndMacro
Macro MATRICE_MULTIPLY(m1,m2,MatriceF)
MatriceF#\_11=m1#\_11*m2#\_11+m1#\_12*m2#\_21+m1#\_13*m2#\_31+m1#\_14*m2#\_41
MatriceF#\_12=m1#\_11*m2#\_12+m1#\_12*m2#\_22+m1#\_13*m2#\_32+m1#\_14*m2#\_42
MatriceF#\_13=m1#\_11*m2#\_13+m1#\_12*m2#\_23+m1#\_13*m2#\_33+m1#\_14*m2#\_43
MatriceF#\_14=m1#\_11*m2#\_14+m1#\_12*m2#\_24+m1#\_13*m2#\_34+m1#\_14*m2#\_44
MatriceF#\_21=m1#\_21*m2#\_11+m1#\_22*m2#\_21+m1#\_23*m2#\_31+m1#\_24*m2#\_41
MatriceF#\_22=m1#\_21*m2#\_12+m1#\_22*m2#\_22+m1#\_23*m2#\_32+m1#\_24*m2#\_42
MatriceF#\_23=m1#\_21*m2#\_13+m1#\_22*m2#\_23+m1#\_23*m2#\_33+m1#\_24*m2#\_43
MatriceF#\_24=m1#\_21*m2#\_14+m1#\_22*m2#\_24+m1#\_23*m2#\_34+m1#\_24*m2#\_44
MatriceF#\_31=m1#\_31*m2#\_11+m1#\_32*m2#\_21+m1#\_33*m2#\_31+m1#\_34*m2#\_41
MatriceF#\_32=m1#\_31*m2#\_12+m1#\_32*m2#\_22+m1#\_33*m2#\_32+m1#\_34*m2#\_42
MatriceF#\_33=m1#\_31*m2#\_13+m1#\_32*m2#\_23+m1#\_33*m2#\_33+m1#\_34*m2#\_43
MatriceF#\_34=m1#\_31*m2#\_14+m1#\_32*m2#\_24+m1#\_33*m2#\_34+m1#\_34*m2#\_44
MatriceF#\_41=m1#\_41*m2#\_11+m1#\_42*m2#\_21+m1#\_43*m2#\_31+m1#\_44*m2#\_41
MatriceF#\_42=m1#\_41*m2#\_12+m1#\_42*m2#\_22+m1#\_43*m2#\_32+m1#\_44*m2#\_42
MatriceF#\_43=m1#\_41*m2#\_13+m1#\_42*m2#\_23+m1#\_43*m2#\_33+m1#\_44*m2#\_43
MatriceF#\_44=m1#\_41*m2#\_14+m1#\_42*m2#\_24+m1#\_43*m2#\_34+m1#\_44*m2#\_44
EndMacro
Macro CopyMatrice(Source,Target)
CopyMemory(Source#,Target#,SizeOf(MATRIX4x4))
EndMacro
Macro SetPerspective(xoffset,yoffset)
Global Xoff.f=xoffset#
Global Yoff.f=yoffset#
EndMacro
Macro CreateSuperSprite3D(S,Sprite2DNumber,Width,Height)
S#.SuperSprite3D
;CreateSprite3D(Sprite2DNumber#,Sprite2DNumber#)
S#\No = Sprite2DNumber#
S#\Size_X = Width#
S#\Size_Y = Height#
S#\VA3D\x = -Width#/2 : S#\VB3D\x = Width#/2 : S#\VC3D\x = Width#/2 : S#\VD3D\x = -Width#/2
S#\VA3D\y = -Height#/2 : S#\VB3D\y = -Height#/2 : S#\VC3D\y = Height#/2 : S#\VD3D\y = Height#/2
S#\VA3D\z = 0 : S#\VB3D\z = 0 : S#\VC3D\z = 0 : S#\VD3D\z = 0
AddElement(SS3D()):SS3D()=@S#
EndMacro
Macro DisplaySuperSprite3D(S,Transparency=255)
MATRICE_Translate_XYZ(S#\MatriceTranslation,S#\Camera\Position\x,S#\Camera\Position\y,S#\Camera\Position\z)
MATRICE_Rotate_XYZ(S#\MatriceRotation,S#\Camera\Rotation\x,S#\Camera\Rotation\y,S#\Camera\Rotation\z)
MATRICE_MULTIPLY(S#\MatriceRotation,S#\MatriceTranslation,S#\MatriceProjection)
S#\A3D\x = S#\MatriceProjection\_11*S#\VA3D\x + S#\MatriceProjection\_21*S#\VA3D\y + S#\MatriceProjection\_31*S#\VA3D\z + S#\MatriceProjection\_41
S#\A3D\y = S#\MatriceProjection\_12*S#\VA3D\x + S#\MatriceProjection\_22*S#\VA3D\y + S#\MatriceProjection\_32*S#\VA3D\z + S#\MatriceProjection\_42
S#\A3D\z = S#\MatriceProjection\_13*S#\VA3D\x + S#\MatriceProjection\_23*S#\VA3D\y + S#\MatriceProjection\_33*S#\VA3D\z + S#\MatriceProjection\_43
S#\B3D\x = S#\MatriceProjection\_11*S#\VB3D\x + S#\MatriceProjection\_21*S#\VB3D\y + S#\MatriceProjection\_31*S#\VB3D\z + S#\MatriceProjection\_41
S#\B3D\y = S#\MatriceProjection\_12*S#\VB3D\x + S#\MatriceProjection\_22*S#\VB3D\y + S#\MatriceProjection\_32*S#\VB3D\z + S#\MatriceProjection\_42
S#\B3D\z = S#\MatriceProjection\_13*S#\VB3D\x + S#\MatriceProjection\_23*S#\VB3D\y + S#\MatriceProjection\_33*S#\VB3D\z + S#\MatriceProjection\_43
S#\C3D\x = S#\MatriceProjection\_11*S#\VC3D\x + S#\MatriceProjection\_21*S#\VC3D\y + S#\MatriceProjection\_31*S#\VC3D\z + S#\MatriceProjection\_41
S#\C3D\y = S#\MatriceProjection\_12*S#\VC3D\x + S#\MatriceProjection\_22*S#\VC3D\y + S#\MatriceProjection\_32*S#\VC3D\z + S#\MatriceProjection\_42
S#\C3D\z = S#\MatriceProjection\_13*S#\VC3D\x + S#\MatriceProjection\_23*S#\VC3D\y + S#\MatriceProjection\_33*S#\VC3D\z + S#\MatriceProjection\_43
S#\D3D\x = S#\MatriceProjection\_11*S#\VD3D\x + S#\MatriceProjection\_21*S#\VD3D\y + S#\MatriceProjection\_31*S#\VD3D\z + S#\MatriceProjection\_41
S#\D3D\y = S#\MatriceProjection\_12*S#\VD3D\x + S#\MatriceProjection\_22*S#\VD3D\y + S#\MatriceProjection\_32*S#\VD3D\z + S#\MatriceProjection\_42
S#\D3D\z = S#\MatriceProjection\_13*S#\VD3D\x + S#\MatriceProjection\_23*S#\VD3D\y + S#\MatriceProjection\_33*S#\VD3D\z + S#\MatriceProjection\_43
const = 577
If S#\A3D\z>0
S#\A2D\x=S#\A3D\x*const/S#\A3D\z+Xoff
S#\A2D\y=S#\A3D\y*const/S#\A3D\z+Yoff
EndIf
If S#\B3D\z>0
S#\B2D\x=S#\B3D\x*const/S#\B3D\z+Xoff
S#\B2D\y=S#\B3D\y*const/S#\B3D\z+Yoff
EndIf
If S#\C3D\z>0
S#\C2D\x=S#\C3D\x*const/S#\C3D\z+Xoff
S#\C2D\y=S#\C3D\y*const/S#\C3D\z+Yoff
EndIf
If S#\D3D\z>0
S#\D2D\x=S#\D3D\x*const/S#\D3D\z+Xoff
S#\D2D\y=S#\D3D\y*const/S#\D3D\z+Yoff
EndIf
If S#\Camera\Position\z>0
TransformSprite(S#\No,S#\A2D\x,S#\A2D\y,S#\A3D\z,S#\B2D\x,S#\B2D\y,S#\B3D\z,S#\C2D\x,S#\C2D\y,S#\C3D\z,S#\D2D\x,S#\D2D\y,S#\D3D\z)
DisplayTransparentSprite(S#\No,0,0,Transparency#)
EndIf
EndMacro
Macro RotateSuperSprite3D(S,xi,yi,zi)
S#\Camera\Rotation\x=xi#
S#\Camera\Rotation\y=yi#
S#\Camera\Rotation\z=zi#
EndMacro
Macro SetSuperSpritePosition(S,xi,yi,zi)
S#\Camera\Position\x=xi#
S#\Camera\Position\y=yi#
S#\Camera\Position\z=zi#
EndMacro
Procedure BlurSuperSprite3D(*Sprite.SuperSprite3D,Value=1)
Protected DB_.l,DBPF.l,PF.l,Color.l,r.f,V.f,B.f
Protected NbPixel.l
Protected Dim Blur.l(SpriteWidth(*Sprite\No),SpriteHeight(*Sprite\No))
StartDrawing(SpriteOutput(*Sprite\No))
DB_ = DrawingBuffer()
DBPF = DrawingBufferPixelFormat()
Select DBPF
Case #PB_PixelFormat_8Bits : PF=1
Case #PB_PixelFormat_15Bits : PF=2
Case #PB_PixelFormat_16Bits : PF=2
Case #PB_PixelFormat_24Bits_RGB : PF=3
Case #PB_PixelFormat_24Bits_BGR : PF=3
Case #PB_PixelFormat_32Bits_RGB : PF=4
Case #PB_PixelFormat_32Bits_BGR : PF=4
EndSelect
For y = 0 To SpriteHeight(*Sprite\No)-1
For x = 0 To SpriteWidth(*Sprite\No)-1
Blur(x,y) = PeekL(DB_+ ((x)*PF) + SpriteWidth(*Sprite\No)* ((y)*PF))
Next
Next
For y = 0 To SpriteHeight(*Sprite\No)-1
For x = 0 To SpriteWidth(*Sprite\No)-1
r = 0
V = 0
B = 0
NbPixel = 0
For Py = -Value To Value
For Px = -Value To Value
If Px + x >= 0 And Px + x < SpriteWidth(*Sprite\No)
If Py + y >= 0 And Py + y < SpriteHeight(*Sprite\No)
Color = Blur(x+Px,y+Py)
r = r + Red(Color)
V = V + Green(Color)
B = B + Blue(Color)
NbPixel + 1
EndIf
EndIf
Next
Next
Color = RGB( r/NbPixel,V/NbPixel,B/NbPixel)
PokeL(DB_+ ((x)*PF) + SpriteWidth(*Sprite\No)* ((y)*PF),Color)
Next
Next
StopDrawing()
EndProcedure
Procedure FlipSuperSprite3D(*Sprite.SuperSprite3D,Mode.b)
StartDrawing(SpriteOutput(*Sprite\No))
Protected *DB=DrawingBuffer(),PF.b
Protected l.l,swf.l=DrawingBufferPitch(),rows.l=SpriteHeight(*Sprite\No)
Protected *row1=*DB,*row2=*DB+swf*(rows-1)
Select DrawingBufferPixelFormat()
Case #PB_PixelFormat_8Bits:PF=1 ; 1 bytes per pixel, palletized
Case #PB_PixelFormat_15Bits:PF=2 ; 2 bytes per pixel
Case #PB_PixelFormat_16Bits:PF=2 ; 2 bytes per pixel
Case #PB_PixelFormat_24Bits_RGB:PF=3 ; 3 bytes per pixel (RRGGBB)
Case #PB_PixelFormat_24Bits_BGR:PF=3 ; 3 bytes per pixel (BBGGRR)
Case #PB_PixelFormat_32Bits_RGB:PF=4 ; 4 bytes per pixel (RRGGBB)
Case #PB_PixelFormat_32Bits_BGR:PF=4 ; 4 bytes per pixel (BBGGRR)
EndSelect
Protected *s1.long=*DB,*s2.long=*DB+swf-PF
Select Mode
Case #Flip_Horizontally
For l=1 To rows
While *s1<*s2
Swap *s1\l,*s2\l
*s1+PF:*s2-PF
Wend
*s1=*DB+l*swf:*s2=*s1+swf-PF
Next
Case #Flip_Vertically
Protected *rowbuffer=AllocateMemory(swf)
While *row1<*row2
CopyMemory(*row1,*rowbuffer,swf):CopyMemory(*row2,*row1,swf):CopyMemory(*rowbuffer,*row2,swf); <- swap
*row1+swf:*row2-swf
Wend
FreeMemory(*rowbuffer)
Case #Flip_Vertically|#Flip_Horizontally
*s2+(rows-1)*swf
While *s1<*s2
Swap *s1\l,*s2\l
*s1+PF:*s2-PF
Wend
EndSelect
StopDrawing()
EndProcedure
Procedure InvertColorSuperSprite3D(*Sprite.SuperSprite3D)
Protected DB_.l,DBPF.l,PF.l,Color.l,r.f,V.f,B.f
Protected Dim Spr.l(SpriteWidth(*Sprite\No),SpriteHeight(*Sprite\No))
StartDrawing(SpriteOutput(*Sprite\No))
DB_ = DrawingBuffer()
DBPF = DrawingBufferPixelFormat()
Select DBPF
Case #PB_PixelFormat_8Bits : PF=1
Case #PB_PixelFormat_15Bits : PF=2
Case #PB_PixelFormat_16Bits : PF=2
Case #PB_PixelFormat_24Bits_RGB : PF=3
Case #PB_PixelFormat_24Bits_BGR : PF=3
Case #PB_PixelFormat_32Bits_RGB : PF=4
Case #PB_PixelFormat_32Bits_BGR : PF=4
EndSelect
For y = 0 To SpriteHeight(*Sprite\No)-1
For x = 0 To SpriteWidth(*Sprite\No)-1
Spr(x,y) = PeekL(DB_+ ((x)*PF) + SpriteWidth(*Sprite\No)* ((y)*PF))
r= 255 - Red(Spr(x,y))
V= 255 - Green(Spr(x,y))
B= 255 - Blue(Spr(x,y))
PokeL(DB_+ ((x)*PF) + SpriteWidth(*Sprite\No)* ((y)*PF),RGB(r,V,B))
Next
Next
StopDrawing()
EndProcedure
Procedure SuperSprite3DChangeColor(*Sprite.SuperSprite3D,ColorToFind.l,ColorToChange.l)
StartDrawing(SpriteOutput(*Sprite\No))
DB_ = DrawingBuffer()
DBPF = DrawingBufferPixelFormat()
Select DBPF
Case #PB_PixelFormat_8Bits : PF=1
Case #PB_PixelFormat_15Bits : PF=2
Case #PB_PixelFormat_16Bits : PF=2
Case #PB_PixelFormat_24Bits_RGB : PF=3
Case #PB_PixelFormat_24Bits_BGR : PF=3
Case #PB_PixelFormat_32Bits_RGB : PF=4
Case #PB_PixelFormat_32Bits_BGR : PF=4
EndSelect
For y = 0 To SpriteHeight(*Sprite\No)-1
For x = 0 To SpriteWidth(*Sprite\No)-1
If PeekL(DB_+ ((x)*PF) + SpriteWidth(*Sprite\No)* ((y)*PF)) = ColorToFind
PokeL(DB_+ ((x)*PF) + SpriteWidth(*Sprite\No)* ((y)*PF),ColorToChange)
EndIf
Next
Next
StopDrawing()
EndProcedure
; Macro RGBA(Red,Green,Blue,Alpha)
; (RGB(Blue,Green,Red)|Alpha<<24)
; EndMacro
Procedure SetSuperSprite3DVertexColor(*Sprite.SuperSprite3D,A.l,B.l,C.l,D.l)
Protected *VertexSprite.PB_Sprite3D = IsSprite(*Sprite\No)
*VertexSprite\Vertice[0]\Color = A
*VertexSprite\Vertice[1]\Color = B
*VertexSprite\Vertice[2]\Color = D
*VertexSprite\Vertice[3]\Color = C
EndProcedure
Procedure SetSuperSprite3DUV(*Sprite.SuperSprite3D,T_u.f,T_v.f)
Protected *VertexSprite.PB_Sprite3D = IsSprite(*Sprite\No)
*VertexSprite\Vertice[0]\tu = 0
*VertexSprite\Vertice[0]\tv = 0
*VertexSprite\Vertice[1]\tu = T_u
*VertexSprite\Vertice[1]\tv = 0
*VertexSprite\Vertice[3]\tu = T_u
*VertexSprite\Vertice[3]\tv = T_v
*VertexSprite\Vertice[2]\tu = 0
*VertexSprite\Vertice[2]\tv = T_v
EndProcedure
If InitSuperSprite3D()
window = OpenWindow(#PB_Any,0,0,1024,768,"SuperSprite3D")
OpenWindowedScreen(WindowID(window),0,0,1024,768)
UseJPEGImageDecoder() : InitNetwork()
temp = ReceiveHTTPFile("http://us.123rf.com/450wm/roverto/roverto1401/roverto140100141/25404355-vector-vieille-carte-avec-la-texture-fissur--style-baroque-avec-des-d-tails-floraux-organis-par-couc.jpg","temp.jpg")
pb_sprite = LoadSprite(#PB_Any,"temp.jpg")
SetPerspective(512,384)
CreateSuperSprite3D(MonSuperSprite,pb_sprite,273,350)
SetSuperSpritePosition(MonSuperSprite,0,0,384)
SetSuperSprite3DVertexColor(@MonSuperSprite,$FF,$FFFF,$FFF00F,$FFFFFF)
deltatime.f = 0
While #True
clock = ElapsedMilliseconds()
Repeat
event = WindowEvent()
If event = #PB_Event_CloseWindow
End
EndIf
Until event = 0
angle.f + 45 * deltatime
ClearScreen($FFFFFF)
RotateSuperSprite3D(MonSuperSprite,0,Radian(angle),0)
DisplaySuperSprite3D(MonSuperSprite)
RotateSuperSprite3D(MonSuperSprite,0,Radian(angle+180),0)
DisplaySuperSprite3D(MonSuperSprite)
FlipBuffers()
deltatime = (ElapsedMilliseconds()-clock)/1000
Wend
EndIf
edit: ne marche pas avec opengl.