i suggest this plan: create a ground with sides, several balls with physics body (
) and in the main loop apply continuous force or pulses in xyz directions to each of the balls.
i have found this example (not optimized, just a showcase). there are many spheres inside a big static transparent sphere, it is giving force to the smaller spheres by illegal and unapproved method:
instead.
Code: Select all
Enumeration
#Tex = 50
#MAT
#MAT_plane
#plane
#LIGHT
#camera
#mainwin
#ball
#bigSphere
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
Declare Gear_Make()
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "space to start the machine ... V to stop , arrow keys + mouse: rotate camera ", #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))
;Circle(127, 127, 50, RGBA(0, 0, 0, 0))
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)
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane), 0, -1.5,-0.7)
RotateEntity(#plane, 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, 4, 13)
RotateCamera(#camera, -15, 0, 0)
;the mother of the jumping balls wich we will make 500 copies
CreateSphere(#ball, 1)
CreateEntity(#ball, MeshID(#ball),#PB_Material_None )
ScaleEntity(#ball, 0.1, 0.1, 0.1)
MoveEntity(#ball, 0,2,3)
CreateEntityBody(#ball, #PB_Entity_SphereBody , 1, 0.3, 1)
;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 500
CopyEntity(#ball , 100+i) ; entities numbering begins from 100
x.f = Random(1, 0)
y.f= Random(3, 0)
z.f = Random(2, 0)
SetEntityMaterial(100+i, MaterialID(0))
MoveEntity(100+i, x,y,z)
CreateEntityBody(100+i, #PB_Entity_SphereBody , 1, 0.2, 1)
Next
CreateSphere(#bigSphere, 3, 20, 20)
CreateEntity(#bigSphere, MeshID(#bigSphere), MaterialID(#MAT), 0,3.5,1 )
CreateEntityBody(#bigSphere, #PB_Entity_StaticBody , 1, 2, 2)
EndIf
WorldGravity(-9.8)
;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
If KeyboardReleased(#PB_Key_Space)
MoveEntity(#bigsphere,0,4,0)
ElseIf KeyboardPushed(#PB_Key_V)
MoveEntity(#bigsphere,0,0,0)
EndIf
MoveCamera (#camera, KeyX, 0, KeyY)
RotateCamera(#camera, MouseY, MouseX, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until Quit = #True Or Event = #PB_Event_CloseWindow
and using thick container will prevent the spheres from escaping it. there is a discussions about this in the forum.
there is example SetMeshData.pb : it creates a plane mesh then it animate it like a flag :
the method is by getting the mesh info into a structured array using GetMeshData function and then changing the array values according to a formula, after that we inject this modified array again to the mesh using SetMeshData function, this is done millions of time giving the impression of animation. this same approach can be used with any other mesh