Re: Just to play with 3D (4.60 beta 2)
Posted: Tue Apr 02, 2013 5:40 am
now it works in PB v5.11, in docs the PointJoint refers to the EntityID(...) and not #Entity, the same for HingeJoint.
so here the Kelebrindae example working in full glory, should be in official 3D examples. press space to move the hammer
so here the Kelebrindae example working in full glory, should be in official 3D examples. press space to move the hammer

Code: Select all
; Window size
#SCREENWIDTH = 800
#SCREENHEIGHT = 500
;- initialization
InitEngine3D()
InitSprite()
InitKeyboard()
;- Window
OpenWindow(0, 0, 0, #SCREENWIDTH, #SCREENHEIGHT, "Joint test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, #SCREENWIDTH,#SCREENHEIGHT, 0, 0, 0,#PB_Screen_SmartSynchronization)
;-Texture
Add3DArchive(".",#PB_3DArchive_FileSystem)
CreateImage(0,128, 128)
StartDrawing(ImageOutput(0))
Box(0, 0, 128, 128, $FFFFFF)
StopDrawing()
SaveImage(0,"temp.bmp")
FreeImage(0)
LoadTexture(0,"temp.bmp")
DeleteFile("temp.bmp")
;-Material
CreateMaterial(1,TextureID(0))
;MaterialAmbientColor(1,#PB_Material_AmbientColors)
SetMaterialColor(1, #PB_Material_AmbientColor, RGB(100,100,100))
CreateMaterial(2,TextureID(0))
;MaterialAmbientColor(2,$FFFF00)
SetMaterialColor(2, #PB_Material_AmbientColor, $FFFF00)
CreateMaterial(3,TextureID(0))
;MaterialAmbientColor(3,$0077FF)
SetMaterialColor(3, #PB_Material_AmbientColor, $0077FF)
CreateMaterial(4,TextureID(0))
;MaterialAmbientColor(4,$FF00FF)
SetMaterialColor(4, #PB_Material_AmbientColor, $FF00FF)
CreateMaterial(5,TextureID(0))
;MaterialAmbientColor(5,$0055BB)
SetMaterialColor(5, #PB_Material_AmbientColor, $FF00FF)
;- Entities
CreatePlane(1,30,30,20,20,1,1)
sol = CreateEntity(#PB_Any, MeshID(1), MaterialID(1))
EntityPhysicBody(sol, #PB_Entity_StaticBody)
; Ball and tee
CreateCube(2, 1.0)
socle = CreateEntity(#PB_Any,MeshID(2), MaterialID(1))
ScaleEntity(socle,0.5,1,0.5)
MoveEntity(socle,2.6,0.5,0)
EntityPhysicBody(socle, #PB_Entity_StaticBody)
CreateSphere(3,0.5)
ball = CreateEntity(#PB_Any, MeshID(3), MaterialID(3))
MoveEntity(ball,2.6,1.5,0)
EntityPhysicBody(ball, #PB_Entity_SphereBody,1,4,1)
; Targets
For i = 1 To 4
temp = CreateEntity(#PB_Any, MeshID(2), MaterialID(4))
MoveEntity(temp,-10,0.5,(i*1.1)-2.8)
EntityPhysicBody(temp, #PB_Entity_BoxBody, 0.25)
Next i
For i = 1 To 3
temp = CreateEntity(#PB_Any, MeshID(2), MaterialID(4))
MoveEntity(temp,-10,1.5,(i*1.1)-2.3)
EntityPhysicBody(temp, #PB_Entity_BoxBody, 0.25)
Next i
For i = 1 To 2
temp = CreateEntity(#PB_Any, MeshID(2), MaterialID(4))
MoveEntity(temp,-10,2.5,(i*1.1)-1.8)
EntityPhysicBody(temp, #PB_Entity_BoxBody, 0.25)
Next i
; Mobile
Global hammerX.f = 5,hammerY.f = 8.5,hammerZ.f
CreateSphere(4,0.4)
axe = CreateEntity(#PB_Any, MeshID(4), MaterialID(2))
MoveEntity(axe,hammerX,hammerY,hammerZ)
EntityPhysicBody(axe, #PB_Entity_StaticBody)
shaft = CreateEntity(#PB_Any, MeshID(2), MaterialID(5))
ScaleEntity(shaft,0.3,6,0.3)
MoveEntity(shaft,hammerX,hammerY - 3.5,hammerZ)
EntityPhysicBody(shaft, #PB_Entity_BoxBody,0.1)
hammerhead = CreateEntity(#PB_Any,MeshID(2), MaterialID(2))
ScaleEntity(hammerhead,2,1,1)
MoveEntity(hammerhead,hammerX,hammerY - 7,hammerZ)
EntityPhysicBody(hammerhead,#PB_Entity_BoxBody,20)
PointJoint(0,EntityID(shaft),0,-3.1 ,0, EntityID(hammerhead),0,0.5,0) ; Attach the hammerhead to the shaft
; Attach the hammer to axis.
HingeJoint(1,EntityID(axe),0,0,0, #False,#False,#True, EntityID(shaft),0,3.5,0, #False,#False,#True)
HingeJoint(2,EntityID(axe),0,0,0, #False,#False,#True, EntityID(hammerhead),0,7,0, #False,#False,#True)
;- Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,-2,8,18)
CameraLookAt(0,-2,5,0)
;-Light
AmbientColor($666666)
CreateLight(0,RGB(160,160,255),200,400,200)
WorldShadows(#PB_Shadow_Additive)
KeyboardMode(#PB_Keyboard_International)
;ApplyEntityImpulse(hammerhead, 20, 0, 0) ; not necessary anymore since 4.60 RC2
;- Main loop
Repeat
Delay(1)
While WindowEvent() : Wend
;- F1, F2, F3 : Change view
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F1)
MoveCamera(0,-18,2,0)
CameraLookAt(0,0,3,0)
EndIf
If KeyboardReleased(#PB_Key_F2)
MoveCamera(0,0,12,20)
CameraLookAt(0,0,5,0)
EndIf
If KeyboardReleased(#PB_Key_F3)
MoveCamera(0,1,5,10)
CameraLookAt(0,-3,3,0)
EndIf
;- [Space] : Throw hammer
If KeyboardPushed(#PB_Key_Space)
ApplyEntityImpulse(hammerhead, 5, 0, 0)
EndIf
;- R : Reset ball's position (doesn't work)
If KeyboardReleased(#PB_Key_R)
FreeEntity(ball)
EndIf
;- Return : Display FPS
If KeyboardReleased(#PB_Key_Return)
MessageRequester("Infos","FPS = " + Str(Engine3DFrameRate(#PB_Engine3D_Average)))
EndIf
EndIf
; Render
RenderWorld()
FlipBuffers()
If Not IsEntity(ball)
ball = CreateEntity(#PB_Any, MeshID(3), MaterialID(3))
MoveEntity(ball,2.6,1.5,0)
EntityPhysicBody(ball, #PB_Entity_SphereBody,1,4,1)
EndIf
Until KeyboardPushed(#PB_Key_Escape)
End