Collision issue
Posted: Sat Mar 02, 2013 1:03 pm
This code:
1) a flat ground, with a upper portion
2) a ball
Both have a physic body. Ground is static, ball is spherical.
You can use the up arrow key to slowly move the ball accros the ground
The collision flag betwen ground & ball is displayed in the top left corner of the screen
Try slowly rolling the ball on the upper section of the ground.
Here, when the ball is on the lower section of the ground, the collision flag is alway true, when the ball roll on the upper section of the ground, the collision is not allway true.
_____________________________
5.10 win32 DirectX
1) a flat ground, with a upper portion
2) a ball
Both have a physic body. Ground is static, ball is spherical.
You can use the up arrow key to slowly move the ball accros the ground
The collision flag betwen ground & ball is displayed in the top left corner of the screen
Try slowly rolling the ball on the upper section of the ground.
Here, when the ball is on the lower section of the ground, the collision flag is alway true, when the ball roll on the upper section of the ground, the collision is not allway true.
_____________________________
5.10 win32 DirectX
Code: Select all
EnableExplicit
InitEngine3D()
InitSprite()
InitKeyboard()
Define width=50
Define depth=30
Define i,j,y
Define win=OpenWindow(#PB_Any,0,0,800,600,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(win),0,0,800,600)
Global monitor=CreateSprite(#PB_Any,320,200)
Define cam=CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(cam,25,10,-20,#PB_Absolute)
CameraLookAt(cam,25,0,15)
CameraRenderMode(cam,#PB_Camera_Wireframe)
Define lampe=CreateLight(#PB_Any,RGB(255,255,255),20,20,20)
;____________________________ creating the ground
Define mesh=CreateMesh(#PB_Any,#PB_Mesh_TriangleList,#PB_Mesh_Static)
For i=0 To width-1
If i>20 And i<30
y=1
Else
y=0
EndIf
For j=0 To depth-1
MeshVertexPosition(i,y,j)
Next j
Next i
For i=0 To width-2
For j=0 To depth-2
MeshFace((i*depth)+j,(i*depth)+j+1,((i+1)*depth)+j)
MeshFace( ((i+1)*depth)+j , (i*depth)+(j+1), ((i+1)*depth)+(j+1) )
Next j
Next i
FinishMesh(#True)
Global plan_e=CreateEntity(#PB_Any,MeshID(mesh),#PB_Material_None)
;__________________________________ creating the ball
Define balle_m=CreateSphere(#PB_Any,1)
Global balle_e=CreateEntity(#PB_Any,MeshID(balle_m),#PB_Material_None,10,5,15)
EntityPhysicBody(plan_e,#PB_Entity_StaticBody)
EntityPhysicBody(balle_e,#PB_Entity_SphereBody,5,1.2,5)
;_______________________________ scan keyboard
Procedure scan()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
End
EndIf
If KeyboardPushed(#PB_Key_Up)
ApplyEntityImpulse(balle_e,1,0,0)
EndIf
EndProcedure
;____________________________ display collision flag
Procedure monitor()
StartDrawing(SpriteOutput(monitor))
DrawText(5,5,"Collision : "+Str(EntityCollide(plan_e,balle_e)))
StopDrawing()
DisplaySprite(monitor,0,0)
EndProcedure
;__________________________ rendering
Procedure render()
RenderWorld()
monitor()
FlipBuffers()
EndProcedure
;________________________ main loop
Repeat
scan()
render()
Until WaitWindowEvent(10)=#PB_Event_CloseWindow
End
