(la différence entre catmull-rom et les courbes de Béziers, c'est qu'avec catmull-rom on passe obligatoirement part les points données)
voici le résultat aujourd'hui !

si quelqu'un a une idée pour améliorer la fonction ou la lisibilité de se code qu'il n’hésitez pas !
Code : Tout sélectionner
Structure game
screenPixelWidth.l
screenPixelHeight.l
EndStructure
Global game.game
game\screenPixelWidth=800
game\screenPixelheight=600
If InitSprite() And InitSprite3D() And InitSound() And InitNetwork()
If InitKeyboard() And InitMouse()
winMain = OpenWindow(#PB_Any,0,0,game\screenPixelWidth,game\screenPixelHeight,"Press [Esc] to close",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(winMain), 0, 0,game\screenPixelWidth,game\screenPixelHeight, 1, 0, 0)
UsePNGImageDecoder()
UseJPEGImageDecoder()
SetFrameRate(60)
EndIf
Else
MessageRequester("","Unable to initsprite") :
EndIf
Define p.point,p0.Point,p1.Point,p2.point,p3.point
;les 4 points part le quel je dois passer
p0\x=Random(100)+50:p0\y=Random(500)+50
p1\x=Random(100)+250:p1\y=Random(500)+50
p2\x=Random(100)+350:p2\y=Random(500)+50
p3\x=Random(100)+450:p3\y=Random(500)+50
; t doit varier de 0 a 1 (0 étant le point de départ et 1 le point d'arrivé)
;CATMULL ROM FUNCTIONALITY
Procedure CatmullRomSpline(t.f,*result.POINT,*p0.Point,*p1.Point,*p2.point,*p3.point)
t2.f = t * t
t3.f = t2 * t
*result\x= 0.5 * ( ( 2.0 * *p1\x ) + ( -*p0\x + *p2\x ) * t + ( 2.0 * *p0\x - 5.0 * *p1\x + 4 * *p2\x - *p3\x ) * t2 + ( -*p0\x + 3.0 * *p1\x - 3.0 * *p2\x + *p3\x ) * t3 )
*result\y= 0.5 * ( ( 2.0 * *p1\y ) + ( -*p0\y + *p2\y ) * t + ( 2.0 * *p0\y - 5.0 * *p1\y + 4 * *p2\y - *p3\y ) * t2 + ( -*p0\y + 3.0 * *p1\y - 3.0 * *p2\y + *p3\y ) * t3 )
EndProcedure
;première version
Procedure old_beziersSpline(t.f,*result.POINT,*p0.Point,*p1.Point,*p2.point,*p3.point)
*result\x = *p0\x*Pow((1-t),3) + 3* *p1\x*Pow((1-t),2)*t + 3* *p2\x*(1-t)*Pow(t,2) + *p3\x*Pow(t,3)
*result\y = *p0\y*Pow((1-t),3) + 3* *p1\y*Pow((1-t),2)*t + 3* *p2\y*(1-t)*Pow(t,2) + *p3\y*Pow(t,3)
EndProcedure
;une version optimizé ! :o)
Procedure beziersSpline(t.f,*result.POINT,*p0.Point,*p1.Point,*p2.point,*p3.point)
a.f=(1-t)
b.f=a*a
c.f=a*a*a
d.f=t*t
e.f=d*t
*result\x = *p0\x*c + 3* *p1\x*b*t + 3* *p2\x*a*d + *p3\x*e
*result\y = *p0\y*c + 3* *p1\y*b*t + 3* *p2\y*a*d + *p3\y*e
EndProcedure
Repeat
Delay(1)
EventID = WindowEvent()
ExamineKeyboard()
ClearScreen(0)
StartDrawing(ScreenOutput())
div=50 ;nombre de division entre les 2 points
For z=0 To div
;-CatmullRom
;premier segment
CatmullRomSpline(z/div,p,p0,p0,p1,p2)
Circle(p\x,p\y,2,#Blue)
;second segment
CatmullRomSpline(z/div,p,p0,p1,p2,p3)
Circle(p\x,p\y,2,#Blue)
;troisième segment
CatmullRomSpline(z/div,p,p1,p2,p3,p3)
Circle(p\x,p\y,2,#Blue)
;-Bezier
beziersSpline(z/div,p,p0,p1,p2,p3)
Circle(p\x,p\y,2,#Green)
Next
;Je trace les points de passage !
Circle(p0\x,p0\y,10,#Red):DrawText(p0\x+15,p0\y,"(0)")
Circle(p1\x,p1\y,10,#Red):DrawText(p1\x+15,p1\y,"(1)")
Circle(p2\x,p2\y,10,#Red):DrawText(p2\x+15,p2\y,"(2)")
Circle(p3\x,p3\y,10,#Red):DrawText(p3\x+15,p3\y,"(3)")
StopDrawing()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape) Or EventID = #PB_Event_CloseWindow