[3D] Les jointures résistent !
Publié : lun. 15/juil./2013 16:20
Dans le code ci-dessous, j'assemble 5 planches avec des jointures pour former un pont.
Le but recherché et que quand je presse la touche espace, les joints lâchent et trois des 5 planches tombent.
- Tant que les planches sont en mouvement pas de souci ça fonctionne.
- Attendez maintenant que les planches soit fixent et pressez la touche espace : Rien ne se passe.
Le but recherché et que quand je presse la touche espace, les joints lâchent et trois des 5 planches tombent.
- Tant que les planches sont en mouvement pas de souci ça fonctionne.
- Attendez maintenant que les planches soit fixent et pressez la touche espace : Rien ne se passe.
Code : Tout sélectionner
Enumeration
#Joint1
#Joint2
#Joint3
#Joint4
EndEnumeration
InitEngine3D()
InitKeyboard()
InitSprite()
window = OpenWindow(#PB_Any,0,0,1024,768,"Les jointures font de la résistance")
OpenWindowedScreen(WindowID(window),0,0,1024,768)
EnableWorldPhysics(#True)
EnableWorldCollisions(#True)
; Une forme
Cube_Mesh = CreateCube(#PB_Any, 1)
; Materiel
Texture1 = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture1))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()
Material1 = CreateMaterial(#PB_Any,TextureID(texture1))
Plank0 = CreateEntity(#PB_Any, MeshID(Cube_Mesh), MaterialID(Material1), 0, 0, 0)
ScaleEntity(Plank0, 4, 0.2, 2.5)
EntityPhysicBody(Plank0, #PB_Entity_StaticBody)
Plank1 = CreateEntity(#PB_Any, MeshID(Cube_Mesh), MaterialID(Material1), 0, 0, 8)
ScaleEntity(Plank1, 4, 0.2, 2.5)
EntityPhysicBody(Plank1, #PB_Entity_BoxBody, 0.1)
Plank2 = CreateEntity(#PB_Any, MeshID(Cube_Mesh), MaterialID(Material1), 0, 0, 8)
ScaleEntity(Plank2, 4, 0.2, 2.5)
EntityPhysicBody(Plank2, #PB_Entity_BoxBody, 0.1)
Plank3 = CreateEntity(#PB_Any, MeshID(Cube_Mesh), MaterialID(Material1), 0, 0, 8)
ScaleEntity(Plank3, 4, 0.2, 2.5)
EntityPhysicBody(Plank3, #PB_Entity_BoxBody, 0.1)
Plank4 = CreateEntity(#PB_Any, MeshID(Cube_Mesh), MaterialID(Material1), 0, 0, 13)
ScaleEntity(Plank4, 4, 0.2, 2.5)
EntityPhysicBody(Plank4, #PB_Entity_StaticBody)
;
;Jointures
HingeJoint(#Joint1, EntityID(Plank0), 0, 0.1, 1.7, 1, 0, 0, EntityID(Plank1), 0, 0.1, -1.7, 1, 0, 0)
HingeJoint(#Joint2, EntityID(Plank1), 0, 0.1, 1.7, 1, 0, 0, EntityID(Plank2), 0, 0.1, -1.7, 1, 0, 0)
HingeJoint(#Joint3, EntityID(Plank2), 0, 0.1, 1.7, 1, 0, 0, EntityID(Plank3), 0, 0.1, -1.7, 1, 0, 0)
HingeJoint(#Joint4, EntityID(Plank3), 0, 0.1, 1.7, 1, 0, 0, EntityID(Plank4), 0, 0.1, -1.7, 1, 0, 0)
;
;Lumiere et ombre
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -1.8, 10, 5)
WorldShadows(#PB_Shadow_Additive)
;
; Une camera
Camera = CreateCamera(#PB_Any,0,0,100,100)
While #True
Event = WindowEvent()
If ExamineKeyboard()
If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
Break
EndIf
If KeyboardPushed(#PB_Key_Space)
FreeJoint(#PB_All)
EndIf
EndIf
MoveCamera(Camera, 8, 8 , 25, #PB_Absolute)
CameraLookAt(camera,0,0,0)
; Affiche le rendu de la scène
ClearScreen(RGB(0, 0, 0))
RenderWorld()
FlipBuffers()
Wend