Page 1 of 1

subjecting a huge number of balls to vibration

Posted: Tue Jan 23, 2018 8:41 pm
by applePi
the only way i know to do vibration is to do something like this:
1- CreateEntityBody(BigSphere, #PB_Entity_StaticBody , 1, 2, 2)
2-
t.f+0.001
MoveEntity(BigSphere,1.2*Sin(t),1,1.2*Cos(t))

the BigSphere will not move really because it is defined as static, but as a side effect it will vibrate, and here it will vibrate in a special way

works in 5.46 and 5.6x but works better in 5.46. and better to disable the debugger
you may try it in a flat box instead of a flattened sphere

my Far target is to simulate this experiment which is very nice:
https://www.youtube.com/watch?v=wvJAgrUBF4w

Code: Select all

Enumeration
   #Tex 
   #MAT
   #MAT_plane
   #LIGHT
   #camera
   #mainwin
   
EndEnumeration
Global Quit.b = #False
Global x.f = 0
Global y.f = 10
Global z.f = -30
Global zoom.f = 13
Global ballNum.l
#cameraSpeed = 0.4

Define.f KeyX, KeyY, MouseX, MouseY
Structure position
 x.f
 y.f
 z.f
EndStructure 

Global pos.position


Global golden_angle.f = 137.508 ; in degrees  
Global golden.f = golden_angle*#PI/180 ; in radians
                                       ;Debug golden
;the purpose of this proc is to allign balls in space conveniently like a sun flower
Procedure floret(n.i) 
  r.f : angle.f 
  r =(1.01 * Sqr(n * golden))
  angle = (n * golden)
  pos\x = r*Cos(angle)/10
  pos\z = r*Sin(angle)/10
  
EndProcedure

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "use arrow keys + mouse: to navigate around the scene  ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-4, 0, 0, 0)
    
  
EnableWorldPhysics(#True)
EnableWorldCollisions(#True)
SetFrameRate(60)

Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
; transparent Texture from example CreateTextureAlpha.pb in Purebasic 3D folder
    CreateTexture(#mat, 256, 256)
      StartDrawing(TextureOutput(#mat))
      DrawingMode(#PB_2DDrawing_AllChannels | #PB_2DDrawing_AlphaBlend)
      Box(0, 0, 256, 256, RGBA(0, 0, 0, 255))
      Box(0, 0, 256, 256, RGBA(100, 255, 0, 20)) 
      StopDrawing()
      CreateMaterial(#mat, TextureID(#mat))
      MaterialBlendingMode(#mat, #PB_Material_AlphaBlend)
      MaterialCullingMode(#MAT, #PB_Material_NoCulling)
      DisableMaterialLighting(#mat, 1)
      

CreateMaterial(#MAT_plane, LoadTexture(#MAT_plane, "Wood.jpg"))
;CreatePlane(#Mesh, TileSizeX, TileSizeZ, TileCountX, TileCountZ, TextureRepeatCountX, TextureRepeatCountZ)
plane = CreatePlane(#PB_Any, 20, 20, 1, 1, 1, 1)
Plane2 = CreateEntity (#PB_Any, MeshID(plane), MaterialID(#MAT_plane),  0, -4.5,-0.7)
RotateEntity(Plane2, 6,0,0)

;CreateEntityBody(#plane, #PB_Entity_StaticBody )  

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(255,255,255))

CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 10, 40)
RotateCamera(#camera, -15, 0, 0)
;the mother of the jumping balls wich we will make 800 copies
ball = CreateSphere(#PB_Any, 0.2)

;material for the jumping balls
LoadTexture(0, "ground_diffuse.png")
CreateMaterial(0, TextureID(0))
DisableMaterialLighting(0, 1)
MaterialCullingMode(0, #PB_Material_NoCulling)
;make 501 small balls 
For i=0 To 1200  ; number of objects
     
     floret(i)
     CreateEntity(i, MeshID(ball), MaterialID(0),pos\x, 0, pos\z)
     CreateEntityBody(i, #PB_Entity_SphereBody  , 1, 0.2, 1)
            
Next
   
   

Sphere = CreateSphere(#PB_Any, 3, 20, 20)

BigSphere = CreateEntity(#PB_Any, MeshID(Sphere), MaterialID(#MAT), 0,0,0 )
ScaleEntity(BigSphere, 6,1,6)
CreateEntityBody(BigSphere, #PB_Entity_StaticBody  , 1, 2, 2)


EndIf
WorldGravity(-9.8); normal gravity, +1, +2, etc :negative gravity
;WorldGravity(0)

SkyBox("desert07.jpg")

;Main loop
Repeat
  
  Repeat   
    Event  = WindowEvent()
  Until Event = 0
  
If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.2
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.2
EndIf
      
      
  ExamineKeyboard()
  
  If KeyboardPushed(#PB_Key_Left)
          KeyX = -#cameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #cameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#cameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #cameraSpeed
        Else
          KeyY = 0
        EndIf
        
  
        
   If KeyboardReleased(#PB_Key_Escape)
      Quit = #True
    EndIf
        
    MoveCamera  (#camera, KeyX, 0, KeyY)
    RotateCamera(#camera,  MouseY, MouseX, 0, #PB_Relative)
    
    t.f+0.001
    ;MoveEntity(BigSphere,1.2*Sin(t), 2*Cos(t) ,1.2*Cos(t))
    MoveEntity(BigSphere,1.2*Sin(t), 2*Cos(t)*Sin(t) ,1.2*Cos(t))
    
  RenderWorld()
   
  FlipBuffers()
    Until Quit = #True Or Event = #PB_Event_CloseWindow

Re: subjecting a huge number of balls to vibration

Posted: Wed Jan 24, 2018 1:24 pm
by Hades
subjecting a huge number of balls to vibration
Man, and here I thought this is about a gay party... turns out the video is actually safe for viewing. :D

Joking aside, I love your idea of simulating that.
But I don't think using balls is a good choice for this. You want something that settles quickly in areas with no vibration, not something that rolls around.
Also those entities colliding with each other and having any (significant) volume is unnecessary.
On top of that you could 'freeze' objects in place, when they haven't moved for some time, then add more 'free' objects.

I haven't played around with PBs native physics, so I have absolutely no idea what is possible with it.


Please continue. This could become pretty awesome!

Edit: spelling

Re: subjecting a huge number of balls to vibration

Posted: Wed Jan 24, 2018 8:31 pm
by applePi
Thanks Hades for the comments, you are right the balls should not roll or jump. in the video the powder particles is too fine and it is most likely irregular, but i am surprised of the video if the curves are not produced by a collective behavior of the particles then every particle pushed away by (luck confined or limited by the vibration or Resonance formula) still can't imagine that.
i am experimenting, and first will make the vibrations seen by a heavy box over the static object. or attaching a strong spring to the static object. i have many ideas and will post the findings.
about the balls i was about to use the word "spheres" in the title since it appears more scientific , but searching google he said: https://www.quora.com/Whats-the-differe ... d-a-sphere
there is many limitations in any physics engine: the limited number of objects managed at the same time. and the developer of the engine can't predict all the complexities of the real nature exactly by his formulas. but they do a good job in any case. the engine used by PB is called Bullet physics engine, search youtube with "Bullet physics engine" and you will see impressive many videos

Re: subjecting a huge number of balls to vibration

Posted: Wed Jan 24, 2018 9:11 pm
by Hades
Well, it's just guesswork by me, but I assume that the plate in the video actually deforms like if you grab a long wobbly stick in the center and shake it up and down. And at certain frequencies parts of the plate simply become static. The particles just get bounced around on the plate until they land on a static part.
Again, that's just my assumption, but it would mean that you need to model the plate in great detail, while the particles are just there for making the vibrations visible, and could even be replaced by coloring parts of the plate differently based on the speed that part is moving at.

For now I'll just wait what you come up with. I'm much to lazy for doing any research right now. :D

Re: subjecting a huge number of balls to vibration

Posted: Sat Feb 03, 2018 10:06 am
by DK_PETER
Nice applePi.
It's not a simple task to realize.
Imo, the way would be to create very minute vibration and deform the 'ground' based on a specific wavetype (frequency).
Also, I recommend to use small elongated cubes to stop the rotation.
It's going to be interesting to see what you'll come up with.