i have used geometric movements like RotateEntity, MoveEntity. we should not use these functions if we want the Compound to have physical properties. note the high quality of AddSubEntity.
Sinbad is the Captain of the Helicopter, note Sinbad is still animated.
works only with PB 5.50
Code: Select all
#CameraSpeed = 0.5
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "...Compound Entity..... 'Space' to stop/rotate the Helicopter....use mouse and arrows to move/rotate the camera", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 1, 1, DesktopWidth(0), DesktopHeight(0), 0, 10, 10, #PB_Screen_SmartSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Packs/Sinbad.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI" , #PB_3DArchive_FileSystem)
Parse3DScripts()
;-------------------------------
; create material
CreateMaterial(1, LoadTexture(1, "wood.jpg"))
MaterialBlendingMode(1, #PB_Material_AlphaBlend)
SetMaterialColor(1, #PB_Material_DiffuseColor, RGBA(255, 255, 0, 220))
;SetMaterialColor(1, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
;
CreateMaterial(2, LoadTexture(2, "snow_1024.jpg"))
SetMaterialColor(2, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
CreateMaterial(3, LoadTexture(3, "clouds.jpg"))
SetMaterialColor(3, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
CreateMaterial(4, LoadTexture(4, "Geebee2.bmp"))
CreateMaterial(5, LoadTexture(5, "MRAMOR6X6.jpg"))
CreateLight(0, RGB(255,255,255))
;-------------------------------
CreateCube(1, 2)
CreateEntity(1, MeshID(1),MaterialID(1), 0, 0, 0)
ScaleEntity(1, 5,1,1)
CreateEntity(2, MeshID(1),MaterialID(3), 4, 2, 0)
ScaleEntity(2, 3,0.2,0.6)
CreateEntity(3, MeshID(1),MaterialID(3), -4, 2, 0)
ScaleEntity(3, 3,0.2,0.6)
CreateEntity(4, MeshID(1),MaterialID(3), 8, 0, 0)
ScaleEntity(4, 3,0.2,0.6)
RotateEntity(4, 0,0,90)
CreateEntity(5, MeshID(1),MaterialID(4), -11, 4.0, 0.5)
ScaleEntity(5, 2,0.2,0.1)
CreateCube(2, 2)
TransformMesh(2, 0,0,4, 1,0.2,4, 0,0,0)
CreateEntity(6, MeshID(2),MaterialID(4), 0, 0, 0)
CreateCube(3, 2)
TransformMesh(3, 0,0,-4, 1,0.2,4, 0,0,0)
CreateEntity(7, MeshID(3),MaterialID(4), 0, 0, 0)
CreateEntity(8, MeshID(1),MaterialID(1), -8, 2.5, 0)
ScaleEntity(8, 4,0.2,0.2)
RotateEntity(8, 0,0,-35)
;CreateCone(#Mesh, Radius.f, Height.f [, NbBaseSegments, NbHeightSegments])
CreateCone(9, 1.5,3,4,4)
CreateEntity(9, MeshID(9),MaterialID(5), 6.5, 0, 0)
RotateEntity(9, 0,45,-90)
Sinbad = CreateEntity(#PB_Any, MeshID(LoadMesh(#PB_Any, "Sinbad.mesh")), #PB_Material_None, 0, 2.5, 0)
ScaleEntity(Sinbad, 0.3, 0.3, 0.3)
RotateEntity(Sinbad, 0,90,0)
;
Global Compound = CreateEntity(#PB_Any,0,0)
AddSubEntity(Compound, 1, #PB_Entity_BoxBody)
AddSubEntity(Compound, 2, #PB_Entity_BoxBody)
AddSubEntity(Compound, 3, #PB_Entity_BoxBody)
AddSubEntity(Compound, 4, #PB_Entity_BoxBody)
AddSubEntity(Compound, 5, #PB_Entity_BoxBody)
AddSubEntity(Compound, 6, #PB_Entity_BoxBody)
AddSubEntity(Compound, 7, #PB_Entity_BoxBody)
AddSubEntity(Compound, 8, #PB_Entity_BoxBody)
AddSubEntity(Compound, 9, #PB_Entity_BoxBody)
AddSubEntity(Compound, Sinbad, #PB_Entity_ConvexHullBody)
StartEntityAnimation(Sinbad, "IdleTop")
;===================================================================
;Ground
;
Ground = CreateEntity(#PB_Any, MeshID(1), MaterialID(2), 0, -7, 0)
ScaleEntity(Ground, 40, 0.4, 40)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
; camera
CreateCamera(0, 0, 0, 100, 100, #True)
MoveCamera(0,1.5,25,80, #PB_Absolute)
CameraLookAt(0, 0,-3,0)
angle.f = 1
Global srcX.f = 0, srcZ.f = 30
Global radius.f = Sqr(srcX*srcX+srcZ*srcZ)
Repeat
Repeat
Until WindowEvent() = 0
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
EndIf
If 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_Space)
stop ! 1
EndIf
EndIf
If stop = #False
ang.f + 0.3 ; determine the rotational speed
srcX = radius * Sin(Radian(ang)) ; formula for the circular motion
srcZ = radius * Cos(Radian(ang)) ; formula for the circular motion
MoveEntity(Compound, srcX, 2, srcZ, #PB_Absolute)
EntityLookAt(Compound, 0, 2, 0)
EntityFixedYawAxis(Compound, 1 , 0, 1, 0)
EndIf
RotateEntity(2, 0,1,0, #PB_Relative)
RotateEntity(3, 0,-1,0, #PB_Relative)
RotateEntity(4, 0,2,0, #PB_Relative)
RotateEntity(5, 0,0,4, #PB_Relative)
RotateEntity(6, wingRot.f,0,0, #PB_Absolute)
RotateEntity(7, -wingRot.f,0,0, #PB_Absolute)
If wingRot.f => 60 Or wingRot <=-10 ; for the wings movement
angle.f * -1
EndIf
wingRot.f + angle.f
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
End