Page 1 sur 1

[PB 5.20] AttachEntityObject & Collision tardive

Publié : mar. 20/août/2013 9:42
par falsam
■ 1er cas
Un sol et un mur que j'attache sur le sol.
Rotation du sol de trois degrés.
La collision n'est pas traité au premier rebond de la sphére mais bien plus tard comme le montre ce code

Code : Tout sélectionner

EnableExplicit

Define.l Event

Global Window.i, Texture.i, Mesh.i, Material.i
Global Camera.i, Ground.i, Wall.i, Sphere.i

InitEngine3D()
InitKeyboard()
InitSprite()

ExamineDesktops()

Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "")
OpenWindowedScreen(WindowID(Window), 0, 0,DesktopWidth(0), DesktopHeight(0))

;
; Physics 
EnableWorldPhysics(#True) 
EnableWorldCollisions(#True)
WorldGravity(-200)

;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -10, 100, 20)
WorldShadows(#PB_Shadow_Additive)

;
; Camera 
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(173, 216, 230))

; 
; Texture (Ground, Obstacle, Sphere)
Texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()

;
; Material (Ground, Wall, Sphere)
Material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialFilteringMode(Material, #PB_Material_Anisotropic, 6)

;
; Ground
Mesh = CreatePlane(#PB_Any, 100, 100, 10, 10, 10, 10)
Ground = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
EntityPhysicBody(Ground, #PB_Entity_StaticBody)

;
; Wall
Mesh = CreateCube(#PB_Any, 1)
Wall = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 50, 5, 0)
ScaleEntity(Wall, 1, 10, 100)
EntityPhysicBody(Wall, #PB_Entity_StaticBody, 0 , 1 ,0)
AttachEntityObject(Ground, "", EntityID(Wall))

;
;Rotate ground
RotateEntity(Ground, 0, 0, -3, #PB_Absolute)

;
; Sphere
Mesh = CreateSphere(#PB_Any, 1.5)
Sphere = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 1, 0, 0)
EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 1, 1, 9)

While #True
  Event = WindowEvent()
  
  ExamineKeyboard()  
   
  If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    Break
  EndIf  
  
  If EntityCollide(Sphere, Wall)
    Debug "Collision"
  EndIf 
 
  MoveCamera(Camera, 0, 40 , 110, #PB_Absolute)
  CameraLookAt(camera, 0, 0, 0)
  
  RenderWorld()
  FlipBuffers()
  
Wend
■ 2eme cas.
Même projet mais l'angle de rotation passe à cinq degres.
La sphère traverse le mur.

Code : Tout sélectionner

EnableExplicit

Define.l Event

Global Window.i, Texture.i, Mesh.i, Material.i
Global Camera.i, Ground.i, Wall.i, Sphere.i

InitEngine3D()
InitKeyboard()
InitSprite()

ExamineDesktops()

Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "")
OpenWindowedScreen(WindowID(Window), 0, 0,DesktopWidth(0), DesktopHeight(0))

;
; Physics 
EnableWorldPhysics(#True) 
EnableWorldCollisions(#True)
WorldGravity(-200)

;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -10, 100, 20)
WorldShadows(#PB_Shadow_Additive)

;
; Camera 
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(173, 216, 230))

; 
; Texture (Ground, Obstacle, Sphere)
Texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()

;
; Material (Ground, Wall, Sphere)
Material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialFilteringMode(Material, #PB_Material_Anisotropic, 6)

;
; Ground
Mesh = CreatePlane(#PB_Any, 100, 100, 10, 10, 10, 10)
Ground = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
EntityPhysicBody(Ground, #PB_Entity_StaticBody)

;
; Wall
Mesh = CreateCube(#PB_Any, 1)
Wall = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 50, 5, 0)
ScaleEntity(Wall, 1, 10, 100)
EntityPhysicBody(Wall, #PB_Entity_StaticBody, 0 , 1 ,0)
AttachEntityObject(Ground, "", EntityID(Wall))

;
;Rotate ground
RotateEntity(Ground, 0, 0, -5, #PB_Absolute)

;
; Sphere
Mesh = CreateSphere(#PB_Any, 1.5)
Sphere = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 1, 0, 0)
EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 1, 1, 9)

While #True
  Event = WindowEvent()
  
  ExamineKeyboard()  
   
  If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    Break
  EndIf  
  
  If EntityCollide(Sphere, Wall)
    Debug "Collision"
  EndIf 
 
  MoveCamera(Camera, 0, 40 , 110, #PB_Absolute)
  CameraLookAt(camera, 0, 0, 0)
  
  RenderWorld()
  FlipBuffers()
  
Wend
J'ai essayé de faire autrement en créant un node pour le sol et le mur. Mais la Sphère ne bouge plus.
J'ai aussi essayé de faire un joint du mur sur le sol mais le mur n'est plus fixe.

Re: [PB 5.20] AttachEntityObject & Collision tardive

Publié : mar. 20/août/2013 13:40
par falsam
Vous vous demandez surement (ou pas :mrgreen: ) pourquoi je m’embête à vouloir absolument attacher mes entités les unes aux autres ? Je cherche à faire rouler une bille sur un plateau que je peux incliner avec les touches de direction du clavier. Quand cette bille touche un des murs qui délimite le périmètre du plateau, elle est censée rebondir ou s’arrêter.

Tout se passe bien si la vitesse de la bille est faible. Par contre si la vitesse est un peu plus importante, la bille passe à travers les murs !!

Code si vous voulez essayer.
- Touches gauche, droite, haut et bas pour incliner le plateau.
- Touche F2 pour recommencer.

Code : Tout sélectionner

EnableExplicit

Define.l Event

Define.f X, Y, Z
Global Window.i, Texture.i, Mesh.i, Material.i, Entity.i
Global Camera.i, Ground.i, Sphere.i
Global Wall1.i, Wall2.i, Wall3.i, Wall4.i
Global EntityMove.i

InitEngine3D()
InitKeyboard()
InitSprite()

ExamineDesktops()

Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "")
OpenWindowedScreen(WindowID(Window), 0, 0,DesktopWidth(0), DesktopHeight(0))

;
; Physics 
EnableWorldPhysics(#True) 

;
;Light and shadow
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -10, 100, 20)
WorldShadows(#PB_Shadow_Additive)

;
; Camera 
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(173, 216, 230))

; 
; Texture (Ground, Walls, Sphere)
Texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(Texture))
Box(0,0,512,512,RGB(0, 0, 0))
Box(1,1,510,510,RGB(255, 216, 0))
StopDrawing()

;
; Material (Ground, Walls, Sphere)
Material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialFilteringMode(Material, #PB_Material_Anisotropic, 6)

;
; Ground
Mesh = CreatePlane(#PB_Any, 100, 100, 10, 10, 10, 10)
Ground = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
EntityPhysicBody(Ground, #PB_Entity_StaticBody, 1, 0.5, 1)

;
; Walls
Mesh = CreateCube(#PB_Any, 1)

;Wall East
Wall1 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 50, 2, 0)
ScaleEntity(Wall1, 1, 4, 99)
EntityPhysicBody(Wall1, #PB_Entity_StaticBody, 9, 1, 1)

;Wall West
Wall2 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -50, 2, 0)
ScaleEntity(Wall2, 1, 4, 99)
EntityPhysicBody(Wall2, #PB_Entity_StaticBody, 1, 1, 1)

;Wall South
Wall3 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 50)
ScaleEntity(Wall3, 99, 4, 1)
EntityPhysicBody(Wall3, #PB_Entity_StaticBody, 1, 1, 1)

;Wall North
Wall4 = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, -50)
ScaleEntity(Wall4, 99, 4, 1)
EntityPhysicBody(Wall4, #PB_Entity_StaticBody, 1, 1, 1)

AttachEntityObject(Ground, "", EntityID(Wall1), 50, 0, 20, 0, 0, 0)
AttachEntityObject(Ground, "", EntityID(Wall2))
AttachEntityObject(Ground, "", EntityID(Wall3))
AttachEntityObject(Ground, "", EntityID(Wall4))

;
; Sphere
Mesh = CreateSphere(#PB_Any, 1.5)
Sphere = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), 0, 2, 0)
EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 1, 1, 9)

While #True
  Event = WindowEvent()
 
  If ExamineKeyboard()  
    EntityMove=#False
    
    If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Break
    EndIf  
    
    If KeyboardPushed(#PB_Key_Left)
      Z = 0.1 : EntityMove=#True
    ElseIf KeyboardPushed(#PB_Key_Right)
      Z = -0.1 : EntityMove=#True
    Else
      Z = 0
    EndIf
  
    If KeyboardPushed(#PB_Key_Up)
      X = -0.1 : EntityMove=#True  
    ElseIf KeyboardPushed(#PB_Key_Down)
      X = 0.1 : EntityMove=#True
    Else
      X = 0
    EndIf
    
    If KeyboardPushed(#PB_Key_F2)
      RotateEntity(Ground, 0, 0, 0, #PB_Absolute)
      MoveEntity(Sphere, 0, 1, 0, #PB_Absolute)
    EndIf
    
  EndIf
  
  If EntityMove = #True
    ;BugWare quand la sphere ne bouge plus
    ApplyEntityImpulse(Sphere, 0, 0.01, 0)
    ;Commentez la ligne au dessus pour voir la différence
    
    RotateEntity(Ground, X, 0, Z, #PB_Relative)
  EndIf
  
  MoveCamera(Camera, 0, 40 , 110, #PB_Absolute)
  CameraLookAt(camera, 0, 0, 0)
  
  ; RenderWorld
  RenderWorld(40)
  FlipBuffers()
  
Wend

Re: [PB 5.20] AttachEntityObject & Collision tardive

Publié : mar. 20/août/2013 14:12
par falsam
Je pense que c'est un souci d'implémentation de la fonction AttachEntityObject().
J'ai l'impression que le mur que j'attache au sol reste dans sa position initiale lors de la rotation du sol bien que visuellement il reste bien attaché sur le sol.

Si on replace le plateau dans sa position horizontal pendant que la bille est en mouvement, le rebond s'effectue bien contre le mur.

j'ai insérer WorldDebug(#PB_World_DebugEntity) après l'ouverture de la fenêtre 3D mais je ne suis pas certain de mon interprétation.