Page 1 sur 2

Re: [4.60 beta] Ribbon Effect

Publié : mar. 12/avr./2011 14:23
par kelebrindae
Magnifique !
Bon, je comprends un peu mieux comment ça marche, merci beaucoup!

Et quand même, parce que quelquefois c'est pratique de créer un material en dans le code (et aussi parce que je suis un peu pénible :mrgreen: ), j'ai modifié mon code pour que les ribbons soient transparents sans utiliser de ".material":

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")

; Ribbon texture
CreateImage(0,128, 1) 
StartDrawing(ImageOutput(0)) 
  DrawingMode(#PB_2DDrawing_Gradient)      
  BackColor($000000)
  GradientColor(0.5, $FFFFFF)
  FrontColor($0000)
  LinearGradient(0, 0, 128, 0)
  Box(0, 0, 128, 1)
StopDrawing()
SaveImage(0,"temp2.bmp")
FreeImage(0)
LoadTexture(1,"temp2.bmp")
DeleteFile("temp2.bmp")

; Colors
Global Dim color.i(7)
Global Dim ribbonColor.i(7)
color(0) = $FF0000:ribbonColor(0) = $770000
color(1) = $00FF00:ribbonColor(1) = $007700
color(2) = $0000FF:ribbonColor(2) = $000077
color(3) = $FFFF00:ribbonColor(3) = $777700
color(4) = $FF00FF:ribbonColor(4) = $770077
color(5) = $00FFFF:ribbonColor(5) = $007777
color(6) = $0077FF:ribbonColor(6) = $003377

;-Materials
CreateMaterial(999,TextureID(0)) ; walls

CreateMaterial(998,TextureID(1)) ; ribbons
MaterialDepthWrite(998, #False)
DisableMaterialLighting(998,#True)
MaterialBlendingMode(998,#PB_Material_Add)
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,0)
  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,50,0.8,20)
  RibbonEffectColor(ball()\numRibbon,ribbonColor(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

Re: [4.60 beta] Ribbon Effect

Publié : mar. 12/avr./2011 14:42
par blendman
c'est classe tous ces exemples.

pour un lancé de boules de feu, ça va le faire :D

Re: [4.60 beta] Ribbon Effect

Publié : mar. 12/avr./2011 16:06
par G-Rom
Voici un autre exemple ( qui utilise l'archive : http://code.google.com/p/purebasic-ogre ... akechanges )

Code : Tout sélectionner

Structure vector3
  x.f
  y.f
  z.f
EndStructure

Structure Katioucha
  position.vector3
  pitch.f
  yaw.f
  nodeID.i
  ribbonID.i
  billBoardGRP.i
  billboardID.i
  rotationTimer.i
EndStructure

Global NewList Katioucha.Katioucha()

Procedure new_Katioucha(x,y,z,pitch,yaw,RibbonMaterial,HeadMaterial)
  AddElement(Katioucha())
  
  Katioucha()\position\x   = x
  Katioucha()\position\y   = y 
  Katioucha()\position\z   = z
  
  Katioucha()\pitch        = pitch
  Katioucha()\yaw          = yaw
  
  Katioucha()\nodeID       = CreateNode(#PB_Any,X,Y,Z)
  Katioucha()\ribbonID     = CreateRibbonEffect(#PB_Any, MaterialID(RibbonMaterial), NodeID(Katioucha()\nodeID), 1, 20, 100, 8500)
  Katioucha()\billBoardGRP = CreateBillboardGroup(#PB_Any,MaterialID(HeadMaterial),512,512)
  Katioucha()\billboardID  = AddBillboard(#PB_Any,Katioucha()\billBoardGRP ,0,0,0)
  
  RibbonEffectColor(Katioucha()\ribbonID, RGBA(255, 255, 255, 255), RGBA(0,0,0,255))
  
  
  AttachNodeObject( Katioucha()\nodeID ,BillboardGroupID(Katioucha()\billBoardGRP),#PB_Node_BillboardGroup)


  
  
EndProcedure

Procedure Katioucha_runtime()
  ForEach Katioucha()
    With Katioucha()
      
      If \rotationTimer < ElapsedMilliseconds()
        \rotationTimer = ElapsedMilliseconds() + 5
        \pitch - 0.7
      EndIf 
      
      If \pitch < -90
        \pitch = -90
      EndIf 
      
      RotateNode(\nodeID,-\pitch,\yaw,0)
      MoveNode(\nodeID,0,0,100)
      
      
      If NodeX(\nodeID)<-20000 Or NodeX(\nodeID)>20000 Or NodeZ(\nodeID)<-20000 Or NodeZ(\nodeID)>20000 
        FreeNode(\nodeID)
        DeleteElement(Katioucha())
        Continue
      EndIf 
      
      If NodeY(\nodeID)<0
       \pitch = 45 + (Random(10)-Random(10))
      EndIf 
      
    EndWith
  Next
EndProcedure



InitSprite()
InitEngine3D()
InitKeyboard()
InitMouse()


OpenWindow(0,0,0,1280,800,"")
OpenWindowedScreen(WindowID(0),0,0,1280,800,1,0,0)


cameranode = CreateNode(#PB_Any,500,0,500)

camera = CreateCamera(#PB_Any,0,0,800,500)
CameraLocate(camera,3000,100,3000)
CameraLookAt(camera,0,1000,0)
CameraFOV(camera,90)
AttachNodeObject(cameranode,CameraID(camera),#PB_Node_Camera)


Add3DArchive("./Medias",#PB_3DArchive_FileSystem)
Parse3DScripts()

SkyBox("desert07.jpg")

material  = GetScriptMaterial(#PB_Any,"GroundBlend")
mesh      = CreatePlane(#PB_Any,100,100,500,500,50,50)
ground    = CreateEntity(#PB_Any,MeshID(mesh),MaterialID(material))


RibbonMaterial  = GetScriptMaterial(#PB_Any, "RibbonTrail")
Headmaterial    = GetScriptMaterial(#PB_Any,"burst")



ReleaseMouse(1)
Repeat
  event = WindowEvent()
    ClearScreen(0)
    
     
    If Timer < ElapsedMilliseconds()
      Timer = ElapsedMilliseconds() + 5
      yaw.f + 0.1
    EndIf 
    
    If Timer2 < ElapsedMilliseconds()
      Timer2 = ElapsedMilliseconds() + 200
      new_Katioucha(-5000,100,-5000,45 + (Random(5)-Random(5))  ,45+(Random(5)-Random(5)),RibbonMaterial, Headmaterial) 
      
      new_Katioucha(5000,100,5000,45 + (Random(5)-Random(5))  ,(45+180) +(Random(5)-Random(5)),RibbonMaterial, Headmaterial) 
    EndIf 
    
    
    
    RotateNode(cameranode,0,yaw,0)
    
    Katioucha_runtime()
    

        
    RenderWorld()
   FlipBuffers()

Until event = #PB_Event_CloseWindow

Re: [4.60 beta] Ribbon Effect

Publié : mar. 12/avr./2011 18:30
par venom
Sympa tous ces rebonds 8)






@++

Re: [4.60 beta] Ribbon Effect

Publié : mer. 13/avr./2011 7:41
par blendman
c'est classe :D

Re: [4.60 beta] Ribbon Effect

Publié : mer. 13/avr./2011 9:15
par djes
Y'a du potentiel :)

Re: [4.60 beta] Ribbon Effect

Publié : mer. 13/avr./2011 17:24
par Guimauve
La commande "OpenWindowedScreen()" semble ne pas fonctionner sous Linux Ubuntu 10.10 x64.

A+
Guimauve

Re: [4.60 beta] Ribbon Effect

Publié : mer. 13/avr./2011 18:36
par G-Rom
La commande "OpenWindowedScreen()" semble ne pas fonctionner sous Linux Ubuntu 10.10 x64.

A+
Guimauve

subsystem opengl?

Re: [4.60 beta] Ribbon Effect

Publié : mer. 13/avr./2011 23:54
par Guimauve
G-Rom a écrit :subsystem opengl?
Effectivement, avec le subsystem opengl dans les options du compilateur, ça fonctionne.

A+
Guimauve