50 Sinbads on a circle
Posted: Thu Mar 10, 2016 11:33 am
seems this week is the 3D demos week with great demos from Hades, DK_PETER, mrw, and others. here is a little play. press space to let the ball hit one sinbad to cause it falling over other sinbad and so on
change the Radius to 30 to get the sinbads more closer. change it to 20 to have the right sinbads collide with the left sinbads
to know how to orient the sinbads in a suitable way look this thread about Calculus Lesson, Tangents to curves:
http://purebasic.fr/english/viewtopic.php?f=36&t=61469

tested PB 5.42LTS on winxp32, win7 x64, ubuntu 14.x x64
change the Radius to 30 to get the sinbads more closer. change it to 20 to have the right sinbads collide with the left sinbads
to know how to orient the sinbads in a suitable way look this thread about Calculus Lesson, Tangents to curves:
http://purebasic.fr/english/viewtopic.php?f=36&t=61469

tested PB 5.42LTS on winxp32, win7 x64, ubuntu 14.x x64
Code: Select all
Define.f KeyX, KeyY, MouseX, MouseY
Enumeration
#Window
#SinbadMat
#SinbadMesh
#Sinbad
#PlaneMesh
#Plane
#Camera
#Light1
#Light2
EndEnumeration
If InitEngine3D() ;#PB_Engine3D_DebugLog
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Packs/Sinbad.zip", #PB_3DArchive_Zip)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)
If OpenWindow(#Window, 0, 0, DesktopW, DesktopH, "press 'Space' to push the Ball ... move/rotate camera with arrow keys and mouse ")
If OpenWindowedScreen(WindowID(#Window), 0, 0, DesktopW, DesktopH, 0, 0, 0)
;Ground
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "snow_1024.jpg")))
Plane = CreateEntity(#PB_Any, MeshID(CreatePlane(#PB_Any, 1000, 1000, 100, 100, 10, 10)), MaterialID(Material))
CreateEntityBody(Plane, #PB_Entity_StaticBody, 1, 0.5, 10)
LoadMesh(#SinbadMesh, "Sinbad.mesh")
Total=50
angle.f = #PI*2/Total
Radius.f = 50
For EN=1 To Total
angle + #PI*2/50
x.f=Cos(angle)*Radius
z.f=Sin(angle)*Radius
slope.f= -z/x ; the derivative
slope = Degree(ATan(slope))
If en=36
CreateSphere(10, 0.5)
CreateMaterial(1, LoadTexture(1, "Geebee2.bmp"))
CreateEntity(10, MeshID(10), MaterialID(1), x-2, 1,z)
CreateEntityBody(10, #PB_Entity_ConvexHullBody )
EndIf
sinbad=CreateEntity(#PB_Any, MeshID(#SinbadMesh), #PB_Material_None)
MoveEntity(Sinbad,x,5, z, #PB_Absolute)
RotateEntity(Sinbad, 0,slope,0)
ScaleEntity(Sinbad,1,1,0.01)
CreateEntityBody(Sinbad, #PB_Entity_ConvexHullBody )
StartEntityAnimation(Sinbad, "IdleTop")
Next
CreateCamera(#Camera, 0, 0, 100, 100)
MoveCamera(#Camera, 0, 50, 100, #PB_Absolute)
CameraLookAt(#Camera,0,0,0)
CreateLight(#Light1, RGB(255, 255, 255), -20, 40, 20)
CreateLight(#Light2, RGB(250, 250, 250), 20, 40, 20)
AmbientColor(RGB(200, 200, 200))
EndIf
EndIf
Repeat
Repeat
event = WindowEvent()
Until event = 0
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 1
Else
KeyY = 0
EndIf
If KeyboardReleased(#PB_Key_Space)
ApplyEntityImpulse(10, 8, 0, 0 );[, PositionX, PositionY, PositionZ])
EndIf
EndIf
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End

