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
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 aussi essayé de faire un joint du mur sur le sol mais le mur n'est plus fixe.