Page 2 of 3

Re: [PB4 Beta8] Collisions

Posted: Sun Apr 02, 2006 1:08 pm
by Progi1984
dontmailme wrote:
Progi1984 wrote:The problem is how having, by example, a sphere which use ODE collision without having inertia (or inertie) - do you understand ? I'm not sure of the translation.
Maybe I could help? But I don't understand the question :(
I give you an example dontmailme.

I would want to do a easy FPS. So I use a sphere for the player. And others mesh for the map :)

I apply at meshs (those of the map) this command for collisions:

Code: Select all

EntityPhysicBody(#Mesh, #PB_Entity_StaticBody)
And my sphere (the player), this command for collisions :

Code: Select all

EntityPhysicBody(#Player, #PB_Entity_SphereBody)
But the problem, when i move my sphere, it has inertia on it. How could i have collisions between sphere and map without having inertia on sphere ?

Do you understand dontmailme ?

Posted: Mon Apr 03, 2006 9:30 pm
by dontmailme
Yes, I think I understand!

If you don't want the inertia (Physics) then I suggest you use another way to test for collisions and not use the built in ODE commands as it appears that it must be turned on for collisions to work :(

Comtois has some nice code here ;)

http://www.purebasic.fr/english/viewtop ... sc&start=0

Posted: Tue Apr 04, 2006 6:42 am
by Progi1984
I know, I'm a french user, too.

But i would want to user ODE.

Posted: Tue Apr 04, 2006 6:47 am
by dagcrack
Can't you use an ODE wrapper instead?. Mine works fine!

Posted: Tue Apr 04, 2006 7:57 am
by dontmailme
Progi1984 wrote:I know, I'm a french user, too.

But i would want to user ODE.
I don't understand why this is?

The whole point of using ODE is for the inertia etc...... but you don't want it !

Posted: Tue Apr 04, 2006 8:13 am
by Progi1984
@Dontmailme
I want to use ODE, because i want to use inertia on objects which have collisions on player but not on the player

@dagcrack
I prefer use the pb commands :)

Posted: Tue Apr 04, 2006 8:53 am
by dagcrack
You'll be limited then!.
Hope you feel comfy in that box though :lol:

Posted: Tue Apr 04, 2006 9:03 am
by dontmailme
Progi1984 wrote:@Dontmailme
I want to use ODE, because i want to use inertia on objects which have collisions on player but not on the player

@dagcrack
I prefer use the pb commands :)
If you used an ODE wrapper then you'd have more control over the physics settings and would be able to do what you want to a lot easier! Hopefully PB will support ODE fully in the near future so we could do this sort of thing.

All I can suggest you to try is something like this.....

Setup all physics bodies, except for the 'player' sphere

Main Loop:-

Do

Move player
create temp physics entity for player
test collisions
act on collisions
remove temp entity

Loop

Although the problem here might be that if the temporary player physics body is inside another physics body you might get them both shooting off at very high speed !!!

If you are adamant you have to use PB-ODE, then something like this is your only hope I think.

Much better to either use own wrapper or to code the inertia and collisions yourself!

When PB has more ODE functionality we will be able to do more complex things!

Posted: Tue Apr 04, 2006 9:33 am
by dagcrack
I might be releasing my wrapper if theres enough love in the air (NOT hassel love)...

Posted: Tue Apr 04, 2006 9:48 am
by dontmailme
dagcrack wrote:I might be releasing my wrapper if theres enough love in the air (NOT hassel love)...
Oh, do release.... go on !!!

How much love do you need ? ;)

:D

Posted: Tue Apr 04, 2006 10:21 am
by Progi1984
@dontmailme

Your idea is very interesting

@dagcrack
You'll be limited then!.
Hope you feel comfy in that box though
My english is not enough good to understand that !

Posted: Tue Apr 04, 2006 10:46 am
by Progi1984
My test :
Uncomment line 177-179 and 191

Code: Select all

Define.f KeyX, KeyY,KeyXCam, KeyYCam, MouseX, MouseY
Define.l actif
Global actifmesh.s

IncludeFile "Screen3DRequester.pb"



#PB_Entity_StaticBody = 1
#PB_Entity_BoxBody    = 2
#PB_Entity_SphereBody = 3

#PB_Shadow_None = 0
#PB_Shadow_Modulative = 1 
#PB_Shadow_Additive = 2   
    
#PB_Entity_Solid      = 0
#PB_Entity_Wireframe  = 1 << 0
#PB_Entity_Plot       = 1 << 1
#PB_Entity_CastShadow = 1 << 2

#PB_3DArchive_Recursive = 2


Enumeration 
  #TrackEntity
  #OgreEntity
  #CubeEntity
  #NinjaEntity
  #SphereEntity
EndEnumeration

actif=#SphereEntity
actifmesh="Sphere" 

If InitEngine3D()

  Add3DArchive("Data\Skybox.zip", #PB_3DArchive_Zip)
  Add3DArchive("Data\Dragon.zip", #PB_3DArchive_Zip)
  
  Add3DArchive("Data\Ogre\"   , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Circuit\", #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Cube\"   , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Ninja\"  , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Sphere\" , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\"        , #PB_3DArchive_FileSystem)
  
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
 
    AmbientColor(RGB(128,128,128))
        
    EnableWorldPhysics(1)
    
    WorldShadows(#PB_Shadow_Additive)
    
    EnableWorldCollisions(1)

    
    OgreMesh   = LoadMesh(#PB_Any, "OgreHead.mesh")
    TrackMesh  = LoadMesh(#PB_Any, "racingcircuit.mesh")
    CubeMesh   = LoadMesh(#PB_Any, "Cube.mesh")
    SphereMesh = LoadMesh(#PB_Any, "Sphere.mesh")
    
    Text = LoadTexture(#PB_Any, "r2skin.jpg")
    Mat = CreateMaterial(#PB_Any, TextureID(Text))
    
    Steel = LoadTexture(#PB_Any, "RustySteel.jpg")
    SteelMaterial = CreateMaterial(#PB_Any, TextureID(Steel))
   
    DisableDebugger
    CreateEntity(#OgreEntity  , MeshID(OgreMesh), 0, 10, 40, 0)
    CreateEntity(#TrackEntity , MeshID(TrackMesh), 0, 0, 00, 0)
    CreateEntity(#CubeEntity  , MeshID(CubeMesh), MaterialID(Mat), 20, 40, 0)
    CreateEntity(#SphereEntity, MeshID(SphereMesh), MaterialID(SteelMaterial), 0, 0, 0)
    EnableDebugger

    EntityPhysicBody(#TrackEntity, #PB_Entity_StaticBody)
    EntityRenderMode(#TrackEntity, 0) 
    
    EntityPhysicBody(#OgreEntity, #PB_Entity_BoxBody)
    EntityRenderMode(#OgreEntity, 0) 
    ScaleEntity(#OgreEntity, 0.1, 0.1, 0.1)
    SetEntityMass(#OgreEntity, 1)
    SetEntityFriction(#OgreEntity,30)
    
    
    ;EntityPhysicBody(#SphereEntity, #PB_Entity_SphereBody)
    EntityRenderMode(#SphereEntity,0)
    ScaleEntity(#SphereEntity, 0.05, 0.05, 0.05)
    ;SetEntityMass(#SphereEntity,1)
    ;SetEntityFriction(#SphereEntity, 30)
       

       
    EntityPhysicBody(#CubeEntity, #PB_Entity_BoxBody)
    EntityRenderMode(#CubeEntity,0)
    ScaleEntity(#CubeEntity, 0.1, 0.1, 0.1)
    SetEntityMass(#CubeEntity, 1)
    SetEntityFriction(#CubeEntity, 30)
    
        
    CreateLight(0, RGB(255,255,255),  100.0, 100, 0)
    
    SkyBox("desert07.jpg")
   
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0,0,0,30)
     
    Repeat
      Screen3DEvents()
      
      ClearScreen(RGB(0, 0, 0))
            
      If ExamineKeyboard()
        If KeyboardPushed(#PB_Key_Pad1) Or KeyboardPushed(#PB_Key_1)
          actif=#CubeEntity
          actifmesh="Cube" 
        ElseIf KeyboardPushed(#PB_Key_Pad2) Or KeyboardPushed(#PB_Key_2)
          actif=#SphereEntity
          actifmesh="Sphere" 
        ElseIf KeyboardPushed(#PB_Key_Pad3) Or KeyboardPushed(#PB_Key_3)
          actif=#OgreEntity
          actifmesh="Ogre" 
        EndIf
        
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -1
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 1
        Else
          KeyX = 0
        EndIf
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -1
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 1
        Else
          KeyY = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_A)
          KeyXCam = -1
        ElseIf KeyboardPushed(#PB_Key_D)
          KeyXCam = 1
        Else
          KeyXCam = 0
        EndIf
        If KeyboardPushed(#PB_Key_W)
         KeyYCam = -1
        ElseIf KeyboardPushed(#PB_Key_S)
          KeyYCam = 1
        Else
          KeyYCam = 0
        EndIf
             
        If KeyboardPushed(#PB_Key_Space)
          MoveEntity(#OgreEntity, 10, 40, 0)
        EndIf
    
      EndIf
      
      If ExamineMouse()
        MouseX = -MouseDeltaX()/10 
        MouseY = -MouseDeltaY()/10
      EndIf
      RotateCamera(0, MouseX, MouseY, 0)
      MoveCamera  (0, KeyXCam, 0, KeyYCam)
      
      MoveEntity(actif,KeyX, 0, KeyY)
      ;EntityPhysicBody(#SphereEntity, #PB_Entity_SphereBody)
      ;SetEntityMass(#SphereEntity,1)
      ;SetEntityFriction(#SphereEntity, 30)
      If ExamineWorldCollisions()
        While NextWorldCollision()
          If CheckEntityCollision(#CubeEntity, #SphereEntity)
            Debug "Cube and Sphere collide !"
          ElseIf CheckEntityCollision(#CubeEntity, #OgreEntity)
           Debug "Cube and Ogre collide !"
          ElseIf CheckEntityCollision(#SphereEntity, #OgreEntity)
            Debug "Sphere and Ogre collide !"
          EndIf
        Wend
      EndIf
      ;EntityPhysicBody(#SphereEntity, #PB_Entity_None)
      RenderWorld()
      
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End
We will arrive to do that :)

@Fred : I want ODE in full version in native commands :)

Posted: Tue Apr 04, 2006 10:50 am
by dagcrack
Progi1984 wrote: My english is not enough good to understand that !
Oh I meant: if you feel comfy trapped with limited functionality and having to live with workarounds...

Posted: Tue Apr 04, 2006 11:40 am
by Progi1984
I agree with you. But as we say in france :
On fait avec les moyens du bord
In english, simply :
We make with we have
It will difficult for waiting for next version of pB !

Posted: Tue Apr 04, 2006 1:21 pm
by dagcrack
Oh no! I sense high amounts of conformism at the forums today!