[PB4 Beta8] Collisions

Advanced game related topics
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

[PB4 Beta8] Collisions

Post 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
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Seen by 54 people, but no answer or ideas...
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Sorry I don't want to be bad with you.
Sorry again !
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Feel better, PB?
@}--`--,-- A rose by any other name ..
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post 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
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
pjay
Enthusiast
Enthusiast
Posts: 282
Joined: Thu Mar 30, 2006 11:14 am

Post 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.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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 :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
pjay
Enthusiast
Enthusiast
Posts: 282
Joined: Thu Mar 30, 2006 11:14 am

Post 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?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post 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!
Paid up PB User !
pjay
Enthusiast
Enthusiast
Posts: 282
Joined: Thu Mar 30, 2006 11:14 am

Post by pjay »

Sorry for taking your thread off in a different direction Progi1984.

Thanks for the physics lesson guys :D
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Re: [PB4 Beta8] Collisions

Post 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 :(
Paid up PB User !
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Post 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:
Post Reply