Collision issue

Everything related to 3D programming
Azur
User
User
Posts: 63
Joined: Sat Jan 28, 2012 11:13 am

Collision issue

Post by Azur »

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

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

applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Collision issue

Post by applePi »

this is an interesting issue , if we added this after line 59
If KeyboardPushed(#PB_Key_F2)
WorldDebug(#PB_World_DebugEntity)
EndIf
we see that the ball are inside the plane and not over it (as considered by WorldDebug ie it is now considered a thick plane _just my opinion_):
Image
, i suggest this is the reason it is always 1, while when it is on the upper portion then it is rolling over the normal plane (ie a flicker true/false like real life ball rolling situation) but this needs a check in the Ogre sdk to see if this the normal behaviour for a ball over a plane.
Post Reply