Page 1 of 3

[PB4 Beta8] Collisions

Posted: Wed Mar 29, 2006 5:01 pm
by Progi1984
In this example, i use the ode test of fred. And i worked on it. It is possible to move anything else. There are collisions between differents objects and the map.
1-2-3 choose between ogre, sphere and cube
F1 for informations

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.

Thank you !

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Entity
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;
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 ; Black shadow (fast)
#PB_Shadow_Additive = 2   ; Additive translucent shadow (more expensive with severl lights)
   
#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=#CubeEntity
actifmesh="Cube"

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, 40, 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 = -100
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 100
        Else
          KeyX = 0
        EndIf
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -100
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 100
        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
      ;If KeyXCam<>0: Debug "KeyXCam"+Str(KeyXCam):EndIf
      ;If KeyYCam<>0:Debug "KeyYCam"+Str(KeyYCam):EndIf
      ;If KeyX<>0:Debug "KeyX"+Str(KeyX):EndIf
      ;If KeyY<>0:Debug "KeyY"+Str(KeyY):EndIf
      RotateCamera(0, MouseX, MouseY, 0)
      MoveCamera  (0, KeyXCam, 0, KeyYCam)
      MoveEntity(actif,KeyX, 0, KeyY)
      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
     
      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

Posted: Thu Mar 30, 2006 6:43 am
by Progi1984
Seen by 54 people, but no answer or ideas...

Posted: Thu Mar 30, 2006 10:45 am
by PB
> Seen by 54 people, but no answer or ideas

Yep, we'll stop our lives just for you. It hasn't even been 24 hours since your
original post. Have some patience, man. We're not a personal support service.

Posted: Thu Mar 30, 2006 12:19 pm
by Progi1984
Sorry I don't want to be bad with you.
Sorry again !

Posted: Thu Mar 30, 2006 1:09 pm
by Dare2
Feel better, PB?

Posted: Thu Mar 30, 2006 1:16 pm
by Thalius
Inertia.. hmm you mean without a static body ( eg the track ? ).

I fiddled aroudn with ODE myself a bit and yes its possible to use ODE without a static body .. well just have Box, Sphere etc. .. works for things like a pinball or something i guess. Tho am still busy writing on some Projects here ( fricken customer pressure ! /rude Timelines! ) or id make an example.

Patience Patience...

Thalius

Posted: Thu Mar 30, 2006 9:11 pm
by PB
> Feel better, PB?

Yes. :twisted:

@Progi1984: History here shows that if people can help, they WILL. So just
post a request and wait. Maybe do a bump after a week if nobody replies,
but there's no need to bump in less than 24 hours with a message like that.

Posted: Fri Mar 31, 2006 6:16 am
by pjay
Off topic a little here, i'm new to ODE & I'm curious as to why objects with increased mass don't fall to earth faster.

I've been playing with the example above and varying the mass only seems to change the collision response.

Posted: Fri Mar 31, 2006 7:34 am
by blueznl
pjay, i'm not the biggest scientist in the world, but would you think that a 100 kg man would fall slower than a 2000 kg car?

no points for the right answer :-)

Posted: Fri Mar 31, 2006 8:36 am
by pjay
I'm not quite sure what you're saying TBH :oops:

I've set the sphere mass at 0.01, and I've set the cube mass at 1.00.

Now, even though the cube is 100 times heavier, they're still dropping at an even rate.

It's not behaving as I'd expect, so am I missing something important?

Posted: Fri Mar 31, 2006 11:38 am
by Dare2
Old experiment: Stand on the leaning tower of Pisa and do a Galileo with two cannonballs of different mass.


Try again with a cannonball and a feather. Air friction and aerodynamics is the difference.

Posted: Fri Mar 31, 2006 11:46 am
by dontmailme
Here's an equation.

Image

You'll find that ODE isn't modelling Air!

Thus the drag isn't apparent.

Remember that ODE is good, but it's not perfect by any means!

Posted: Fri Mar 31, 2006 8:05 pm
by pjay
Sorry for taking your thread off in a different direction Progi1984.

Thanks for the physics lesson guys :D

Re: [PB4 Beta8] Collisions

Posted: Fri Mar 31, 2006 9:28 pm
by dontmailme
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 :(

Posted: Sat Apr 01, 2006 2:43 am
by SoulReaper
physics whats that :shock: :lol:

joking sorry :wink:

nice liked it very much thanks again I will need these equations soon :lol:
for my upcoming 3d stuff :wink: :twisted: :lol: