About Collision physics behaviour

Everything related to 3D programming
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

About Collision physics behaviour

Post 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)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: About Collision physics behaviour

Post 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
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: About Collision physics behaviour

Post 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 :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: About Collision physics behaviour

Post 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)
Please correct my english
http://purebasic.developpez.com/
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: About Collision physics behaviour

Post by Psychophanta »

Thanks!, interesting new.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply