[3D] Les jointures résistent !

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
falsam
Messages : 7323
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

[3D] Les jointures résistent !

Message par falsam »

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.

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
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
kelebrindae
Messages : 579
Inscription : ven. 11/mai/2007 15:21

Re: [3D] Les jointures résistent !

Message par kelebrindae »

Je n'ai pas encore essayé le code, mais je pense que ton problème est dû au fait que les bodies physiques de tes entités sont passés en "sommeil" (Pour optimiser les calculs, Bullet passe en sommeil tous les corps immobiles ou presque dès lors qu'ils ne subissent aucune influence extérieure).

Essaye de faire un "DisableEntityBody(plank[n],#False)" sur chacune de tes entités au moment où tu casses le joint, ça devrait arranger les choses... :wink:
Les idées sont le souvenir de choses qui ne se sont pas encore produites.
Fred
Site Admin
Messages : 2807
Inscription : mer. 21/janv./2004 11:03

Re: [3D] Les jointures résistent !

Message par Fred »

Si c'est le cas, il faudra modifier FreeJoint() pour que ca le fasse automatiquement.
Avatar de l’utilisateur
falsam
Messages : 7323
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: [3D] Les jointures résistent !

Message par falsam »

Bonjour kelebrindae et merci pour cette suggestion. Il faut effectivement insérer DisableEntityBody(Entity, #False) juste avant freejoint() pour que le ou les entités qui sont passée(s) en sommeil (Planches immobiles dans mon cas)
Fred a écrit :Si c'est le cas, il faudra modifier FreeJoint() pour que ca le fasse automatiquement.
Bonjour Fred. Apparement c'est le cas.

je joint le bout de code corrigé avec cette suggestion.
J'ai volontairement commenter cette suggestion pour la planche du milieu.
Attender que toutes les planches soient immobilisées et appuyer sur la touche Espace pour détruire tous les joints (FreeJoint(#PB_All)). La planche du milieu ne chutera pas.

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)
      DisableEntityBody(plank1, #False)
      ;DisableEntityBody(plank2, #False)
      DisableEntityBody(plank3, #False)
      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
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Répondre