Page 1 of 1

About Collision physics behaviour

Posted: Mon Sep 03, 2018 7:22 pm
by Psychophanta
Commented in the tip.
(1) When an impulse is given too low for the ball (for example ApplyEntityImpulse(bola.i,0.1,0,0,0,0,0) ), then the collision physics behaviour seems not correct.
(2) When make a rotation for a mesh then the physic body created after the transformation (rotation) seems not to be correct working for collision. I think it should work, because CreateEntityBody() is called after the mesh transformation, so CreateEntityBody() should catch the shape as it is.

Code: Select all

ExamineDesktops()
bitplanes.a=DesktopDepth(0):RX.u=DesktopWidth(0):RY.u=DesktopHeight(0)
InitEngine3D()
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,RX,RY,"tip",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,RX,RY,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)

luz.i=CreateLight(#PB_Any,$EEEEEE,4,4,2,#PB_Light_Point):SetLightColor(luz.i,#PB_Light_DiffuseColor,$EEEEEE):MoveLight(luz,4,4,2,#PB_Absolute)
camara.i=CreateCamera(#PB_Any,0,0,100,100):MoveCamera(camara.i,0,0,3,#PB_Absolute)
cuerpotextura.i=LoadTexture(#PB_Any,"soil_wall.jpg")
cuerpomaterial.i=CreateMaterial(#PB_Any,TextureID(cuerpotextura.i))
cuerpomalla.i=CreateCylinder(#PB_Any,0.05,2,10,1,1)
cuerpo.i=CreateEntity(#PB_Any,MeshID(cuerpomalla.i),MaterialID(cuerpomaterial.i),0,0,0)

bolatextura.i=LoadTexture(#PB_Any,"snow_1024.jpg")
bolamaterial.i=CreateMaterial(#PB_Any,TextureID(bolatextura.i))
bolamalla.i=CreateSphere(#PB_Any,0.05,25,10)
bola.i=CreateEntity(#PB_Any,MeshID(bolamalla.i),MaterialID(bolamaterial.i),-0.3,0.8,0)

WorldGravity(0.0)
CreateEntityBody(cuerpo,#PB_Entity_CylinderBody,1.0,1.0,0.0):SetEntityAttribute(cuerpo,#PB_Entity_LinearSleeping,0.0):SetEntityAttribute(cuerpo,#PB_Entity_AngularSleeping,0.0)
CreateEntityBody(bola,#PB_Entity_SphereBody,1.0,1.0,0.0):SetEntityAttribute(bola,#PB_Entity_LinearSleeping,0.0):SetEntityAttribute(bola,#PB_Entity_AngularSleeping,0.0)
Repeat
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_Space)
    ApplyEntityImpulse(bola.i,0.3,0,0,0,0,0); <------------------  if the impulse is too low (for example ApplyEntityImpulse(bola.i,0.1,0,0,0,0,0) ), then the collision physics behaviour is not fine
  ElseIf KeyboardReleased(#PB_Key_Return)
    EntityVelocity(cuerpo,0,0,0)
    MoveEntity(cuerpo,0.0,0.0,0.0,#PB_Absolute)
    RotateEntity(cuerpo,0.0,0.0,0.0,#PB_Absolute)
    EntityVelocity(bola,0,0,0)
    MoveEntity(bola,-0.3,0.8,0,#PB_Absolute)
    FreeEntityBody(cuerpo)
    FreeEntity(cuerpo)
    FreeMesh(cuerpomalla.i)
    cuerpomalla.i=CreateCylinder(#PB_Any,1,0.1,80,1,1)
    cuerpo.i=CreateEntity(#PB_Any,MeshID(cuerpomalla.i),MaterialID(cuerpomaterial.i),0,0,0)
    TransformMesh(cuerpomalla.i,0,0,0,1,1,1,0,0,90,0); <----------------------   does not work when collision ?? (Must rotate the entity, whic suposes an inconvenient).
    CreateEntityBody(cuerpo,#PB_Entity_CylinderBody,1.0,1.0,0.0):SetEntityAttribute(cuerpo,#PB_Entity_LinearSleeping,0.0):SetEntityAttribute(cuerpo,#PB_Entity_AngularSleeping,0.0)
  EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
CloseWindow(0)

Re: About Collision physics behaviour

Posted: Tue Sep 04, 2018 8:04 pm
by applePi
Psychophanta, after every change to the mesh use UpdateMeshBoundingBox(cuerpomalla) so the collision will be effective
also :
WorldDebug(#PB_World_DebugBody) Or
WorldDebug(#PB_World_DebugEntity)

before the main loop is useful for debugging

Re: About Collision physics behaviour

Posted: Tue Sep 04, 2018 8:58 pm
by Psychophanta
applePi wrote:Psychophanta, after every change to the mesh use UpdateMeshBoundingBox(cuerpomalla) so the collision will be effective
Thank you very much. I must learn the essentials, i think :?

Re: About Collision physics behaviour

Posted: Tue Sep 04, 2018 11:17 pm
by Comtois
Body is wrong, you need to change cylinder's body orientation using axisX/Y/Z parameters
CreateEntityBody(cuerpo,#PB_Entity_CylinderBody,1.0,1.0,0.0,#PB_Default,#PB_Default,#PB_Default,1,0,0)

Code: Select all

ExamineDesktops()
bitplanes.a=DesktopDepth(0):RX.u=DesktopWidth(0):RY.u=DesktopHeight(0)
InitEngine3D()
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,RX,RY,"tip",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,RX,RY,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)

WorldDebug(#PB_World_DebugBody)

luz.i=CreateLight(#PB_Any,$EEEEEE,4,4,2,#PB_Light_Point):SetLightColor(luz.i,#PB_Light_DiffuseColor,$EEEEEE):MoveLight(luz,4,4,2,#PB_Absolute)
camara.i=CreateCamera(#PB_Any,0,0,100,100):MoveCamera(camara.i,0,0,3,#PB_Absolute)
CameraRenderMode(camara,  #PB_Camera_Wireframe)
cuerpotextura.i=LoadTexture(#PB_Any,"soil_wall.jpg")
cuerpomaterial.i=CreateMaterial(#PB_Any,TextureID(cuerpotextura.i))
cuerpomalla.i=CreateCylinder(#PB_Any,0.05,2,10,1,1)
cuerpo.i=CreateEntity(#PB_Any,MeshID(cuerpomalla.i),MaterialID(cuerpomaterial.i),0,0,0)

bolatextura.i=LoadTexture(#PB_Any,"snow_1024.jpg")
bolamaterial.i=CreateMaterial(#PB_Any,TextureID(bolatextura.i))
bolamalla.i=CreateSphere(#PB_Any,0.05,25,10)
bola.i=CreateEntity(#PB_Any,MeshID(bolamalla.i),MaterialID(bolamaterial.i),-0.3,0.8,0)

WorldGravity(0.0)
CreateEntityBody(cuerpo,#PB_Entity_CylinderBody,1.0,1.0,0.0):SetEntityAttribute(cuerpo,#PB_Entity_LinearSleeping,0.0):SetEntityAttribute(cuerpo,#PB_Entity_AngularSleeping,0.0)
CreateEntityBody(bola,#PB_Entity_SphereBody,1.0,1.0,0.0):SetEntityAttribute(bola,#PB_Entity_LinearSleeping,0.0):SetEntityAttribute(bola,#PB_Entity_AngularSleeping,0.0)
Repeat
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_Space)
    ApplyEntityImpulse(bola.i,0.3,0,0,0,0,0); <------------------  if the impulse is too low (for example ApplyEntityImpulse(bola.i,0.1,0,0,0,0,0) ), then the collision physics behaviour is not fine
  ElseIf KeyboardReleased(#PB_Key_Return)
    EntityVelocity(cuerpo,0,0,0)
    MoveEntity(cuerpo,0.0,0.0,0.0,#PB_Absolute)
    RotateEntity(cuerpo,0.0,0.0,0.0,#PB_Absolute)
    EntityVelocity(bola,0,0,0)
    MoveEntity(bola,-0.3,0.8,0,#PB_Absolute)
    FreeEntityBody(cuerpo)
    FreeEntity(cuerpo)
    FreeMesh(cuerpomalla.i)
    cuerpomalla.i=CreateCylinder(#PB_Any,1,0.1,80,1,1)
    TransformMesh(cuerpomalla.i,0,0,0,1,1,1,0,0,90);  
    UpdateMeshBoundingBox(cuerpomalla)
    cuerpo.i=CreateEntity(#PB_Any,MeshID(cuerpomalla.i),MaterialID(cuerpomaterial.i),0,0,0)
    
    CreateEntityBody(cuerpo,#PB_Entity_CylinderBody,1.0,1.0,0.0,#PB_Default,#PB_Default,#PB_Default,1,0,0)
    
    ;CreateEntityBody(cuerpo,#PB_Entity_CylinderBody,1.0,1.0,0.0)
    :SetEntityAttribute(cuerpo,#PB_Entity_LinearSleeping,0.0):SetEntityAttribute(cuerpo,#PB_Entity_AngularSleeping,0.0)
  EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
CloseWindow(0)

Re: About Collision physics behaviour

Posted: Wed Sep 05, 2018 8:11 am
by Psychophanta
Thanks!, interesting new.