Bridge using PointJoint (4.60 beta 2)

Advanced game related topics
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Bridge using PointJoint (4.60 beta 2)

Post by Comtois »

Use Cursor, mouse and SpaceBar.

Code: Select all

#CameraSpeed = 1
#Nb = 40
Define.f KeyX, KeyY, MouseX, MouseY
Dim Planche(#Nb)

If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  ExamineDesktops()
  OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0), "joint")
  
  ;-Pont
  CreateCube(1, 1.0)
  For i = 1 To #Nb
    Planche(i)=CreateEntity(#PB_Any, MeshID(1), #PB_Material_None)
    ScaleEntity(Planche(i), 2.8, 0.2, 20)
    EntityLocate(Planche(i), i*3,0,0)
    EntityPhysicBody(Planche(i), #PB_Entity_BoxBody, 1.0)
  Next i
  
  Pas.f = 1.5
  PointJoint(Planche(1),  -Pas, 0, -5)
  For i= 1 To #Nb-2
    PointJoint(Planche(i+1),  -Pas, 0, -5, Planche(i), Pas, 0, -5)
  Next i
  PointJoint(Planche(#Nb),  Pas, 0, -5)
  PointJoint(Planche(#Nb-1),  Pas, 0, -5, Planche(#Nb), -Pas, 0, -5)
  
  PointJoint(Planche(1),  -Pas, 0, 5)
  For i= 1 To #Nb-2
    PointJoint(Planche(i+1),  -Pas, 0, 5, Planche(i), Pas, 0, 5)
  Next i
  PointJoint(Planche(#Nb),  Pas, 0, 5)
  PointJoint(Planche(#Nb-1),  Pas, 0, 5, Planche(#Nb), -Pas, 0, 5)
  
  ;-Objets
  CreateSphere(2, 2)
  
  C = Planche(1)
  For i = 1 To #Nb/2
    Perso = CreateEntity(#PB_Any, MeshID(2), #PB_Material_None, EntityX(C) +i * 5, EntityY(C)+ i * 2, EntityZ(C))
    EntityPhysicBody(Perso, #PB_Entity_SphereBody, 1.0)
  Next i
  For i = 1 To #Nb/2
    Perso = CreateEntity(#PB_Any, MeshID(1), #PB_Material_None, EntityX(C) +i * 5, EntityY(C)+ i * 4, EntityZ(C))
    ScaleEntity(Perso, 3, 3, 3)
    EntityPhysicBody(Perso, #PB_Entity_BoxBody, 1.0)
  Next i
  
  ;-Camera
  CreateCamera(0, 0, 0, 100, 100)
  CameraLocate(0, -20, 30, -40)
  CameraLookAt(0, EntityX(C) + 25, EntityY(C) + 10,  EntityZ(C))
  
  ;-Light
  CreateLight(0, RGB(255, 255, 255))
  AmbientColor(RGB(80, 80, 80))
  
  ;-Sprite
  CreateSprite(0, 300, 60)
  
  ;-Main loop
  Repeat
    
    If ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Space)
        ApplyEntityImpulse(Planche(#Nb/2), 0, -9, 0)
      EndIf
      
      If KeyboardPushed(#PB_Key_Left)
        KeyX = -#CameraSpeed
      ElseIf KeyboardPushed(#PB_Key_Right)
        KeyX = #CameraSpeed
      Else
        KeyX = 0
      EndIf
      
      If KeyboardPushed(#PB_Key_Up)
        KeyY = -#CameraSpeed
      ElseIf KeyboardPushed(#PB_Key_Down)
        KeyY = #CameraSpeed
      Else
        KeyY = 0
      EndIf
      
    EndIf
    
    If ExamineMouse()
      MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
      MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
    EndIf
    MoveCamera  (0, KeyX, 0, KeyY)
    RotateCamera(0,  MouseY, MouseX, 0)
    
    RenderWorld()
    StartDrawing(SpriteOutput(0))
    DrawText(10,10, "FPS = " +Str(Engine3DFrameRate(#PB_Engine3D_Current)), $FFFF00, $FF0000)
    StopDrawing()
    DisplayTransparentSprite(0,0,0)
    FlipBuffers()
    
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Last edited by Comtois on Wed May 04, 2011 5:26 am, edited 3 times in total.
Please correct my english
http://purebasic.developpez.com/
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Bridge using PointJoint (4.60 beta 2)

Post by netmaestro »

Very cool! 8)
BERESHEIT
dige
Addict
Addict
Posts: 1420
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Bridge using PointJoint (4.60 beta 2)

Post by dige »

Indeed! ... and with so few lines of code - cool!
"Daddy, I'll run faster, then it is not so far..."
User avatar
IceSoft
Addict
Addict
Posts: 1699
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Bridge using PointJoint (4.60 beta 2)

Post by IceSoft »

Works not with the PB 64bit version
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Bridge using PointJoint (4.60 beta 2)

Post by djes »

8)
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Bridge using PointJoint (4.60 beta 2)

Post by Comtois »

IceSoft wrote:Works not with the PB 64bit version
Work fine here with PB x64 and PB x86 (4.60 beta 2)
Please correct my english
http://purebasic.developpez.com/
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Bridge using PointJoint (4.60 beta 2)

Post by PMV »

it's really cool :shock: , bit it looks like it has a low fps. :?
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Bridge using PointJoint (4.60 beta 2)

Post by Comtois »

PMV wrote:it's really cool :shock: , bit it looks like it has a low fps. :?
I have updated the code to display fps. I get 60 here with Geforce GTS 240.

You can change #Nb to reduce Number of joints :)
Please correct my english
http://purebasic.developpez.com/
User avatar
IceSoft
Addict
Addict
Posts: 1699
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Bridge using PointJoint (4.60 beta 2)

Post by IceSoft »

First: with the beta2 of the 64bit version it works for me too.

You got 60 because the default is #PB_Screen_WaitSynchronization (= 60fps)
Change this line and you get your real fps value:

Code: Select all

  OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0), "joint",#PB_Screen_NoSynchronization)
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Lebostein
Addict
Addict
Posts: 849
Joined: Fri Jun 11, 2004 7:07 am

Re: Bridge using PointJoint (4.60 beta 2)

Post by Lebostein »

Very cool!

Works fine, fast and without problems here with Mac OS X on a MacBook Pro with PB 4.60 b2.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Bridge using PointJoint (4.60 beta 2)

Post by PMV »

Comtois wrote:I have updated the code to display fps. I get 60 here with Geforce GTS 240.

You can change #Nb to reduce Number of joints :)
I doesn't know why it looks some times like it would lagging, it looks like it is
not updated equable (not in every frame) ... but thank you for that. I have
also added an timer so it will run smooth with more FPS ... i get 430-500 now.

Code: Select all

#CameraSpeed = 0.1
#Nb = 40
Define.f KeyX, KeyY, MouseX, MouseY
Dim Planche(#Nb)

If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  ExamineDesktops()
  OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0), "joint", #PB_Screen_NoSynchronization   )
  
  ;-Pont
  CreateCube(1, 1.0)
  For i = 1 To #Nb
    Planche(i)=CreateEntity(#PB_Any, MeshID(1), #PB_Material_None)
    ScaleEntity(Planche(i), 2.8, 0.2, 20)
    EntityLocate(Planche(i), i*3,0,0)
    EntityPhysicBody(Planche(i), #PB_Entity_BoxBody, 1.0)
  Next i
  
  Pas.f = 1.5
  PointJoint(Planche(1),  -Pas, 0, -5)
  For i= 1 To #Nb-2
    PointJoint(Planche(i+1),  -Pas, 0, -5, Planche(i), Pas, 0, -5)
  Next i
  PointJoint(Planche(#Nb),  Pas, 0, -5)
  PointJoint(Planche(#Nb-1),  Pas, 0, -5, Planche(#Nb), -Pas, 0, -5)
  
  PointJoint(Planche(1),  -Pas, 0, 5)
  For i= 1 To #Nb-2
    PointJoint(Planche(i+1),  -Pas, 0, 5, Planche(i), Pas, 0, 5)
  Next i
  PointJoint(Planche(#Nb),  Pas, 0, 5)
  PointJoint(Planche(#Nb-1),  Pas, 0, 5, Planche(#Nb), -Pas, 0, 5)
  
  ;-Objets
  CreateSphere(2, 2)
  
  C = Planche(1)
  For i = 1 To #Nb/2
    Perso = CreateEntity(#PB_Any, MeshID(2), #PB_Material_None, EntityX(C) +i * 5, EntityY(C)+ i * 2, EntityZ(C))
    EntityPhysicBody(Perso, #PB_Entity_SphereBody, 1.0)
  Next i
  For i = 1 To #Nb/2
    Perso = CreateEntity(#PB_Any, MeshID(1), #PB_Material_None, EntityX(C) +i * 5, EntityY(C)+ i * 4, EntityZ(C))
    ScaleEntity(Perso, 3, 3, 3)
    EntityPhysicBody(Perso, #PB_Entity_BoxBody, 1.0)
  Next i
  
  ;-Camera
  CreateCamera(0, 0, 0, 100, 100)
  CameraLocate(0, -20, 30, -40)
  CameraLookAt(0, EntityX(C) + 25, EntityY(C) + 10,  EntityZ(C))
  
  ;-Light
  CreateLight(0, RGB(255, 255, 255))
  AmbientColor(RGB(80, 80, 80))
  
  ;-Sprite
  CreateSprite(0, 300, 60)
  TransparentSpriteColor(0, 0)
  
  ;-Main loop
  Repeat
    TimerNow = ElapsedMilliseconds()
    TimeLoop = TimerNow - Timer
    If TimeLoop > 0
      TimeLoop = TimerNow - Timer
      Timer = TimerNow
      
      If ExamineKeyboard()
        If KeyboardPushed(#PB_Key_Space)
          ApplyEntityImpulse(Planche(#Nb/2), 0, -0.9 * TimeLoop, 0)
        EndIf
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed * TimeLoop
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed * TimeLoop
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed * TimeLoop
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed * TimeLoop
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      If ExamineMouse()
        MouseX = -(MouseDeltaX()/3)*#CameraSpeed/2  * TimeLoop
        MouseY = -(MouseDeltaY()/3)*#CameraSpeed/2  * TimeLoop
      EndIf
      MoveCamera  (0, KeyX, 0, KeyY)
      RotateCamera(0,  MouseY, MouseX, 0)
        
      
    Else
      TimeLoop = 0
      ;Delay(1)
    EndIf
      
    RenderWorld()
    StartDrawing(SpriteOutput(0))
    DrawText(10,10, "FPS = " +Str(Engine3DFrameRate(#PB_Engine3D_Current)), $FF4F00, 0)
    StopDrawing()
    DisplayTransparentSprite(0,0,0)
    FlipBuffers()
    
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Post Reply