Je me suis amusé avec les "Ribbon Effects", et c'est assez classe. (elle est bien, cette 4.60 )
Par contre, je ne comprends pas tout:
- Le 4ème paramètre "NbChains", il sert à quoi ?
- De même qu'il y a un paramètres "initialWidth", ne devrait-il pas y avoir un paramètre "finalWidth", afin que le ruban paraisse de plus en plus petit vers la fin ?
- Je n'ai pas réussi à le rendre "correctement" transparent; au lieu d'être de plus en plus transparent en allant vers la fin, il est de plus en plus noir...
Tenez, jetez un oeil, vous comprendrez mieux:
Code : Tout sélectionner
; Window size
#SCREENWIDTH = 800
#SCREENHEIGHT = 500
Structure ball_struct
numEntity.i
numNode.i
numRibbon.i
timer.f
EndStructure
Global NewList ball.ball_struct()
;- initialization
InitSprite()
InitEngine3D()
InitKeyboard()
;- Window
OpenWindow(0, 0, 0, #SCREENWIDTH, #SCREENHEIGHT, "Ribbon FX test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, #SCREENWIDTH,#SCREENHEIGHT, 0, 0, 0,#PB_Screen_SmartSynchronization)
;-Texture
Add3DArchive(".",#PB_3DArchive_FileSystem)
CreateImage(0,128, 128)
StartDrawing(ImageOutput(0))
Box(0, 0, 128, 128, $FFFFFF)
StopDrawing()
SaveImage(0,"temp.bmp")
FreeImage(0)
LoadTexture(0,"temp.bmp")
DeleteFile("temp.bmp")
; Colors
Global Dim color.i(7)
color(0) = $FF0000
color(1) = $00FF00
color(2) = $0000FF
color(3) = $FFFF00
color(4) = $FF00FF
color(5) = $00FFFF
color(6) = $0077FF
;-Materials
CreateMaterial(999,TextureID(0)) ; walls
CreateMaterial(998,TextureID(0)) ; ribbons
MaterialDepthWrite(998, #False)
MaterialFilteringMode(998,#PB_Material_None)
For i=0 To 6
CreateMaterial(i,TextureID(0)) ; balls
MaterialAmbientColor(i,color(i))
Next i
;- Entities
; walls
planeMesh = CreatePlane(#PB_Any,2,2,10,10,1,1)
ground = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
EntityPhysicBody(ground, #PB_Entity_StaticBody,1,1,0)
ceiling = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(ceiling,180,0,0)
EntityLocate(ceiling,0,20,0)
EntityPhysicBody(ceiling, #PB_Entity_StaticBody)
backWall = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(backwall,90,0,0)
EntityLocate(backwall,0,10,-10)
EntityPhysicBody(backwall, #PB_Entity_StaticBody,1,1,0)
frontWall = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(frontWall,270,0,0)
EntityLocate(frontWall,0,10,10)
EntityPhysicBody(frontWall, #PB_Entity_StaticBody,1,1,0)
HideEntity(frontWall,#True)
leftWall = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(leftWall,0,0,270)
EntityLocate(leftWall,-10,10,0)
EntityPhysicBody(leftWall, #PB_Entity_StaticBody,1,1,0)
rightWall = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(rightWall,0,0,90)
EntityLocate(rightWall,10,10,0)
EntityPhysicBody(rightWall, #PB_Entity_StaticBody,1,1,0)
; balls
sphereMesh = CreateSphere(#PB_Any, 0.5)
For i=1 To 20
ballcolor = Random(6)
AddElement(ball())
ball()\numEntity = CreateEntity(#PB_Any, MeshID(sphereMesh), MaterialID(ballcolor))
EntityLocate(ball()\numEntity, 8 - Random(16),10 + 8 - Random(16),8 - Random(16))
EntityPhysicBody(ball()\numEntity, #PB_Entity_SphereBody, 1,0.7,1)
ApplyEntityImpulse(ball()\numEntity,20-Random(40),20-Random(40),20-Random(40) )
;- Ribbons
ball()\numNode = CreateNode(#PB_Any)
ball()\numRibbon = CreateRibbonEffect(#PB_Any,MaterialID(998),NodeID(ball()\numNode),1,20,0.8,10)
RibbonEffectColor(ball()\numRibbon,color(ballcolor),$FFFFFF)
Next i
;- Camera
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,10,35)
CameraLookAt(0,0,10,0)
;- Light
AmbientColor(RGB(92,92,92))
CreateLight(0,RGB(160,160,255),-200,300,0)
WorldShadows(#PB_Shadow_Additive)
;- Main loop
Repeat
Delay(1)
While WindowEvent() : Wend
If ExamineKeyboard()
;- Return : Display FPS
If KeyboardReleased(#PB_Key_Return)
MessageRequester("Infos","FPS = " + Str(Engine3DFrameRate(#PB_Engine3D_Average)))
EndIf
EndIf
; Move the balls
ForEach ball()
; If the ball is on the ground for too long, give it a little impulse
If EntityY(ball()\numEntity) < 0.7
ball()\timer + 1
Else
ball()\timer = 0
EndIf
If ball()\timer > 50
ApplyEntityImpulse(ball()\numEntity,20-Random(40),15+Random(15),20-Random(40) )
EndIf
; The ribbon is attached to the node, so the node must follow the ball
NodeLocate(ball()\numNode,EntityX(ball()\numEntity),EntityY(ball()\numEntity),EntityZ(ball()\numEntity))
Next ball()
; Render
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End