[Résolu] Souci avec la Physic : CreateEntityBody()

Généralités sur la programmation 3D
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

[Résolu] Souci avec la Physic : CreateEntityBody()

Message par falsam »

Bonjour. J'ai un souci avec la physic. Sinbad refuse de chuter :wink:

Code : Tout sélectionner

EnableExplicit

Global camera

; Sommaire
Declare Start()
Declare DownLoad(Url.s)
Declare Exit()

CompilerIf Subsystem("OpenGL") = #False
  MessageRequester("Information", "Vous devez activer OpenGL dans les options de compilation !")
  Exit()
CompilerEndIf

Start()

Procedure Start()
  Protected Window, ww, wh, Event
  Protected Texture, Material, Mesh
  Protected Ground, Box, Player, PlayerSpeed, CurrentAnimation.s
  
  ; Initialisation de l'environnemet 3D
  If Not (InitEngine3D(#PB_Engine3D_DebugLog) And InitKeyboard() And InitSprite())
    MessageRequester("Information", "Impossible d'initialiser l'environnement 3D")
    Exit()
  EndIf
    
  ; Window & Screen 3D
  Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
  ww = WindowWidth (Window, #PB_Window_InnerCoordinate)
  wh = WindowHeight(Window, #PB_Window_InnerCoordinate)
  SetWindowColor(Window, 0)
  
  OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
  
  ; Localisation des elements 3D
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
  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()
    
  KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
  
  ; Camera
  camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
  MoveCamera(camera, 0, 10, 40)

  ; Environnement
  SkyBox("desert07.jpg", RGB(255, 255, 255), 1, 900, 6000)

  CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, -1000)
  WorldShadows(#PB_Shadow_Additive)
  
  ; Physics
  EnableWorldPhysics(#True)
  WorldGravity(-20)

  ;- Entités
  Texture   = LoadTexture(-1, "Dirt.jpg")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreatePlane(-1, 10000, 10000, 100, 100, 30, 30)
  Ground    = CreateEntity(-1, MeshID(Mesh), MaterialID(Material))
  CreateEntityBody(Ground, #PB_Entity_StaticBody, 1, 0, 0)
  
  Mesh      = LoadMesh(#PB_Any, "sinbad.mesh")
  Player    = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 10, 600, -40)
  ScaleEntity(Player, 25, 25, 25)
  CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 1, 3, 20)
  EntityAngularFactor(Player, 0, 1, 0)
  
  Texture   = LoadTexture(-1, "Caisse.png")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreateCube(-1, 100)
  Box       = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 200, 600, 500)
  CreateEntityBody(Box, #PB_Entity_BoxBody, 1, 1, 1)
  
  ; Render
  While #True
    event = WindowEvent()
    ExamineKeyboard() 
    
    ExamineKeyboard()
    
    ;-Evenement clavier : Déplacement
    If KeyboardPushed (#PB_Key_Up)
      PlayerSpeed = 300
      CurrentAnimation = "RunBase"
    ElseIf KeyboardPushed (#PB_Key_Down)
      PlayerSpeed = -300
      CurrentAnimation = "RunBase"
    Else
      CurrentAnimation = "IdleTop"
      PlayerSpeed = 0
    EndIf
    
    ;-Evenement clavier : Rotation
    If KeyboardPushed (#PB_Key_Left)
      RotateEntity(Player, 0, 3, 0, #PB_Relative)
      CurrentAnimation = "RunBase"
    ElseIf KeyboardPushed (#PB_Key_Right)
      RotateEntity(Player, 0, -3, 0, #PB_Relative)
      CurrentAnimation = "RunBase"
    EndIf   
    
    If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Exit()
    EndIf 
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
    CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 125, 500, 1, #True)

    ;Play animation
    If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
      StartEntityAnimation(Player, CurrentAnimation)
    EndIf
        
    RenderWorld()
    FlipBuffers()
  Wend
EndProcedure

Procedure Exit()
  End  
EndProcedure

d'avance merci pour votre aide.
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Re: Souci avec la Physic : CreateEntityBody()

Message par SPH »

Il y a un probleme avec ton ombre. Elle ne te suis pas.
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Souci avec la Physic : CreateEntityBody()

Message par falsam »

SPH a écrit :Il y a un probleme avec ton ombre. Elle ne te suis pas.
C'est normal car Sinbad ne touche pas le sol.

Bien sur je pourrais le poser au sol. Mais je veux que Sinbad se positionne avec la physic.
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Re: Souci avec la Physic : CreateEntityBody()

Message par SPH »

Haaa, fallait le savoir. Je pensais que tu voulais qu'il tombe en quittant le sol (ca n'empeche que j'ai repondu de travers plus haut)
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Souci avec la Physic : CreateEntityBody()

Message par falsam »

Nouveau code. J'ai supprimé ce qui ne sert à rien.

Il y a un sol et deux cubes. Un seul cube chute. Je ne comprend pas !

Code : Tout sélectionner

EnableExplicit

Global camera

; Sommaire
Declare Start()
Declare DownLoad(Url.s)
Declare Exit()

CompilerIf Subsystem("OpenGL") = #False
  MessageRequester("Information", "Vous devez activer OpenGL dans les options de compilation !")
  Exit()
CompilerEndIf

Start()

Procedure Start()
  Protected Window, ww, wh, Event
  Protected Texture, Material, Mesh
  Protected Ground, Box, Player, PlayerSpeed, CurrentAnimation.s
  
  ; Initialisation de l'environnemet 3D
  If Not (InitEngine3D(#PB_Engine3D_DebugLog) And InitKeyboard() And InitSprite())
    MessageRequester("Information", "Impossible d'initialiser l'environnement 3D")
    Exit()
  EndIf
    
  ; Window & Screen 3D
  Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
  ww = WindowWidth (Window, #PB_Window_InnerCoordinate)
  wh = WindowHeight(Window, #PB_Window_InnerCoordinate)
  SetWindowColor(Window, 0)
  
  OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
  
  ; Localisation des elements 3D
  Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
      
  ; Camera
  camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
  MoveCamera(camera, 0, 10, 40)

  ; Environnement
  CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, -1000)
  WorldShadows(#PB_Shadow_Additive)
  
  ;- Entités
  Texture   = LoadTexture(-1, "Dirt.jpg")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreatePlane(-1, 10000, 10000, 100, 100, 30, 30)
  Ground    = CreateEntity(-1, MeshID(Mesh), MaterialID(Material))
  CreateEntityBody(Ground, #PB_Entity_StaticBody, 1, 0, 0)
  
  Texture   = LoadTexture(-1, "Caisse.png")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreateCube(-1, 100)  
  Player    = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 10, 600, -40)
  CreateEntityBody(Player, #PB_Entity_BoxBody, 1, 1, 1)
  
  Texture   = LoadTexture(-1, "Caisse.png")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreateCube(-1, 100)
  Box       = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 200, 600, 500)
  CreateEntityBody(Box, #PB_Entity_BoxBody, 1, 1, 1)
  
  ; Render
  While #True
    event = WindowEvent()
    ExamineKeyboard() 
    
    ExamineKeyboard()
        
    If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Exit()
    EndIf 
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
    CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 125, 500, 1, #True)
        
    RenderWorld()
    FlipBuffers()
  Wend
EndProcedure

Procedure Exit()
  End  
EndProcedure
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Souci avec la Physic : CreateEntityBody()

Message par falsam »

je suis une quiche !!!! MoveEntity() maintient Sinbad en l'air :|
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Souci avec la Physic : CreateEntityBody()

Message par falsam »

Je pense que mon souci est résolu. Voici le nouveau code. Si quelqu'un a mieux je suis preneur.

Utiliser les touches du clavier pour vous déplacer et shooter dans la caisse ;)

Code : Tout sélectionner

EnableExplicit

Global camera

; Sommaire
Declare Start()
Declare DownLoad(Url.s)
Declare Exit()

CompilerIf Subsystem("OpenGL") = #False
  MessageRequester("Information", "Vous devez activer OpenGL dans les options de compilation !")
  Exit()
CompilerEndIf

Start()

Procedure Start()
  Protected Window, ww, wh, Event
  Protected Texture, Material, Mesh
  Protected Ground, Box, Player, PlayerSpeed, CurrentAnimation.s
  
  ; Initialisation de l'environnemet 3D
  If Not (InitEngine3D(#PB_Engine3D_DebugLog) And InitKeyboard() And InitSprite())
    MessageRequester("Information", "Impossible d'initialiser l'environnement 3D")
    Exit()
  EndIf
   
  ; Window & Screen 3D
  Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
  ww = WindowWidth (Window, #PB_Window_InnerCoordinate)
  wh = WindowHeight(Window, #PB_Window_InnerCoordinate)
  SetWindowColor(Window, 0)
 
  OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
 
  ; Localisation des elements 3D
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
  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()
   
  KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
 
  ; Camera
  camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
  MoveCamera(camera, 0, 10, 40)

  ; Environnement
  SkyBox("desert07.jpg", RGB(255, 255, 255), 1, 900, 6000)

  CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, -1000)
  WorldShadows(#PB_Shadow_Additive)
 
  ; Physics
  EnableWorldPhysics(#True)
  WorldGravity(-20)

  ;- Entités
  Texture   = LoadTexture(-1, "Dirt.jpg")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreatePlane(-1, 10000, 10000, 100, 100, 30, 30)
  Ground    = CreateEntity(-1, MeshID(Mesh), MaterialID(Material))
  CreateEntityBody(Ground, #PB_Entity_StaticBody, 1, 0, 100)
 
  Mesh      = LoadMesh(#PB_Any, "sinbad.mesh")
  Player    = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 10, 600, -40)
  ScaleEntity(Player, 25, 25, 25)
  CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 200, 1, 100)
  EntityAngularFactor(Player, 0, 1, 0)
 
  Texture   = LoadTexture(-1, "Caisse.png")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreateCube(-1, 100)
  Box       = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 200, 600, 500)
  CreateEntityBody(Box, #PB_Entity_BoxBody, 100, 1, 100)
 
  ; Render
  While #True
    event = WindowEvent()
    ExamineKeyboard()
      
    ;-Evenement clavier : Déplacement
    If KeyboardPushed (#PB_Key_Up)
      PlayerSpeed = 200
      CurrentAnimation = "RunBase"
    ElseIf KeyboardPushed (#PB_Key_Down)
      PlayerSpeed = -200
      CurrentAnimation = "RunBase"
    Else
      CurrentAnimation = "IdleTop"
      PlayerSpeed = 0
    EndIf
   
    ;-Evenement clavier : Rotation
    If KeyboardPushed (#PB_Key_Left)
      RotateEntity(Player, 0, 3, 0, #PB_Relative)
      CurrentAnimation = "RunBase"
    ElseIf KeyboardPushed (#PB_Key_Right)
      RotateEntity(Player, 0, -3, 0, #PB_Relative)
      CurrentAnimation = "RunBase"
    EndIf   
   
    If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Exit()
    EndIf

    If PlayerSpeed
      DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
      MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
    EndIf
    
    CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 125, 500, 1, #True)

    ;Play animation
    If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
      StartEntityAnimation(Player, CurrentAnimation)
    EndIf
       
    RenderWorld(100)
    FlipBuffers()
  Wend
EndProcedure

Procedure Exit()
  End 
EndProcedure
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
venom
Messages : 3072
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Souci avec la Physic : CreateEntityBody()

Message par venom »

Pas mieux a te proposé car je suis une quiche ne 3D.
Mais ça a le mérite de fonctionner maintenant 8)






@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Répondre