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