It is currently Thu Dec 13, 2018 6:49 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Double pendulum
PostPosted: Fri Jul 06, 2018 4:31 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1406
Location: Doubs - France
Adapted from @Fig's demo

Using PointJoint

Code:
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

If InitEngine3D()
 
  InitSprite()
  InitKeyboard()
  InitMouse()
 
  If Screen3DRequester()
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts" , #PB_3DArchive_FileSystem)
    Parse3DScripts()
   
    ; First create materials
    ;
    CreateMaterial(0, LoadTexture(0, "Wood.jpg"))
    CreateMaterial(1, LoadTexture(1, "Dirt.jpg"))
    GetScriptMaterial(2, "Examples/LightRibbonTrail")
   
    ; Meshes
    ;
    CreateCube(0, 1)
    CreateSphere(1, 0.5)
   
    ; Entities
    ;
    CreateEntity(0, MeshID(0), MaterialID(0), 0,  0, 0)
    CreateEntity(1, MeshID(0), MaterialID(0), 0, -5.1, 0)
    CreateEntity(2, MeshID(1), MaterialID(1), 0, -5.1, 0)
    CreateEntity(3, MeshID(1), MaterialID(1), 0, 0, 0)
   
    ScaleEntity(0,1,10,1)
    ScaleEntity(1,1,10,1)   
   
    ;Ribbon
   
    CreateRibbonEffect(0, MaterialID(2), 1, 2800, 180)
    RibbonEffectColor(0, 0, RGBA(0, 255*0.8, 255*0.8, 255), RGBA(0, 255, 0, 5))
    RibbonEffectWidth(0, 0, 0.5, 0.2)
    AttachRibbonEffect(0, EntityParentNode(3))
   
    ; Bodies
    ;
    CreateEntityBody(0, #PB_Entity_BoxBody   , 1.0)
    CreateEntityBody(1, #PB_Entity_BoxBody   , 1.0)
    CreateEntityBody(2, #PB_Entity_SphereBody, 1.0)
    CreateEntityBody(3, #PB_Entity_SphereBody, 0.00001)   
   
    ; PointJoint
    ;
    PointJoint(0, EntityID(0), 0, 5.5, 0)
    PointJoint(1, EntityID(0),  0, -5.5, 0, EntityID(2), 0, 0, 0)
    PointJoint(2, EntityID(1),  0, 5.5, 0, EntityID(2), 0, 0, 0)
    PointJoint(3, EntityID(1),  0, -5.5, 0, EntityID(3), 0, 0, 0)   
       
    For i=0 To 3
      EntityLinearFactor(i, 1, 1, 0)
    Next
       
    ; Camera
    ;
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 0, 50, #PB_Absolute)
   
    ;- Light
    ;
    AmbientColor(RGB(25, 25, 25))
    CreateLight(0, RGB(215, 190, 40), 75, 75, 75)
   
    ; GO
    ;
    ApplyEntityImpulse(1,  10, 0, 0)
   
    Repeat
      Screen3DEvents()
      ExamineKeyboard()
     
      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


Using HingeJoint

Code:
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

If InitEngine3D()
 
  InitSprite()
  InitKeyboard()
  InitMouse()
 
  If Screen3DRequester()
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts" , #PB_3DArchive_FileSystem)
    Parse3DScripts()
   
    ; First create materials
    ;
    CreateMaterial(0, LoadTexture(0, "Wood.jpg"))
    CreateMaterial(1, LoadTexture(1, "Dirt.jpg"))
    GetScriptMaterial(2, "Examples/LightRibbonTrail")
   
    ; Meshes
    ;
    CreateCube(0, 1)
    CreateSphere(1, 0.5)
   
    ; Entities
    ;
    CreateEntity(0, MeshID(0), MaterialID(0), 0,  0, 0)
    CreateEntity(1, MeshID(0), MaterialID(0), 0, -5.1, 0)
    CreateEntity(2, MeshID(1), MaterialID(1), 0, -5.1, 0)
    CreateEntity(3, MeshID(1), MaterialID(1), 0, 0, 0)
   
    ScaleEntity(0,1,10,1)
    ScaleEntity(1,1,10,1)   
   
    ;Ribbon
   
    CreateRibbonEffect(0, MaterialID(2), 1, 2800, 180)
    RibbonEffectColor(0, 0, RGBA(0, 255*0.8, 255*0.8, 255), RGBA(0, 255, 0, 5))
    RibbonEffectWidth(0, 0, 0.5, 0.2)
    AttachRibbonEffect(0, EntityParentNode(3))
   
    ; Bodies
    ;
    CreateEntityBody(0, #PB_Entity_BoxBody   , 1.0)
    CreateEntityBody(1, #PB_Entity_BoxBody   , 1.0)
    CreateEntityBody(2, #PB_Entity_SphereBody, 1.0)
    CreateEntityBody(3, #PB_Entity_SphereBody, 0.00001)   
   
    ; HingeJoint
    ;
    HingeJoint(0, EntityID(0), 0,  5.5, 0, 0, 0, 1,         -2 , 0, 0, 0, 0, 0, 0)   
    HingeJoint(1, EntityID(0), 0, -5.5, 0, 0, 0, 1, EntityID(2), 0, 0, 0, 0, 0, 1)
    HingeJoint(2, EntityID(1), 0,  5.5, 0, 0, 0, 1, EntityID(2), 0, 0, 0, 0, 0, 1)
    HingeJoint(3, EntityID(1), 0, -5.5, 0, 0, 0, 1, EntityID(3), 0, 0, 0, 0, 0, 1)   
     
    ;SetJointAttribute(0,  #PB_HingeJoint_LowerLimit, -45)
    ;SetJointAttribute(0,  #PB_HingeJoint_UpperLimit,  45)
   
    ; Camera
    ;
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 0, 50, #PB_Absolute)
   
    ;- Light
    ;
    AmbientColor(RGB(25, 25, 25))
    CreateLight(0, RGB(215, 190, 40), 75, 75, 75)
   
    ; GO
    ;
    ApplyEntityImpulse(1,  10, 0, 0)
   
    Repeat
      Screen3DEvents()
      ExamineKeyboard()
     
      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

_________________
Please correct my english
http://purebasic.developpez.com/


Last edited by Comtois on Wed Aug 15, 2018 9:03 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Fri Jul 06, 2018 6:08 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 745
Location: Denmark
So simple and nice.
Thx. :-)

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 7/10, Intel 6800K, Gtx 970, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Sat Jul 07, 2018 6:39 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 287
Location: Côtes d'Azur, France
So simple and elegant ! :shock:
What about a third pendulum ?

_________________
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x86 5.62


Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Sat Jul 07, 2018 10:53 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 8:51 am
Posts: 1447
Location: Germany
Fig wrote:
What about a third pendulum ?

Thats not so much interessting as using only double.

_________________
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...


Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Tue Jul 10, 2018 9:33 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 710
Location: Berlin and Ibiza
Nice

_________________
ImageImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Wed Jul 11, 2018 7:51 am 
Offline
Addict
Addict
User avatar

Joined: Wed Apr 30, 2003 8:15 am
Posts: 957
Location: Germany
Amazing! :o Especially with so few lines of code.

_________________
"Daddy, I'll run faster, then it is not so far..."


Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Wed Jul 11, 2018 12:52 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:10 pm
Posts: 462
Location: Doubs - France
Slt Comtois,

excellent !

_________________
A+
Denis


Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Thu Jul 12, 2018 4:54 am 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1327
Thanks Comtois and Fig for these great demos, i thought before that CreateLine3D is ugly and static while this demo show that we can use it to simulate a thread.
let me hijack the Comtois demo, to look at the pendulum (the Gymnast) in a more 3D sensation by rotating the camera around the pendulum and to put references such as a ground , a wall, and a tree . so we have more experience of the pendulum in the space.
in short we can use PB 2D/3D Graphics in Art and science show
Code:
    #MaxHistoricNumber=200
    Structure Vector3
      x.f
      y.f
      z.f
    EndStructure

    NewList trace.Vector3()

    Declare Draw(List ptr.Vector3())

    IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

    If InitEngine3D()
     
      InitSprite()
      InitKeyboard()
      InitMouse()
     
      If Screen3DRequester()
        Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
        Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
       
        ; First create materials
        ;
        CreateMaterial(0, LoadTexture(0, "Wood.jpg"))
        CreateMaterial(1, LoadTexture(1, "Dirt.jpg"))
        CreateMaterial(2, LoadTexture(2, "ground_diffuse.png"))
        CreateMaterial(3, LoadTexture(3, "MRAMOR6X6.jpg"))
        CreateMaterial(4, LoadTexture(4, "RustyBarrel.png"))
       
        ; Meshes
        ;
        CreateCube(0, 1)
        CreateSphere(1, 0.5)
       
        ; Entities
        ;
        CreateEntity(0, MeshID(0), MaterialID(0), 0,  0, 0)
        CreateEntity(1, MeshID(0), MaterialID(0), 0, -5.1, 0)
        CreateEntity(2, MeshID(1), MaterialID(1), 0, -5.1, 0)
        CreateEntity(3, MeshID(1), MaterialID(1), 0, 0, 0)
       
        ScaleEntity(0,1,10,1)
        ScaleEntity(1,1,10,1)   
       
        ; Bodies
        ;
        CreateEntityBody(0, #PB_Entity_BoxBody   , 1.0)
        CreateEntityBody(1, #PB_Entity_BoxBody   , 1.0)
        CreateEntityBody(2, #PB_Entity_SphereBody, 1.0)
        CreateEntityBody(3, #PB_Entity_SphereBody, 0.00001)   
       
        ; PointJoint
        ;
        PointJoint(0, EntityID(0), 0, 5.5, 0)
        PointJoint(1, EntityID(0),  0, -5.5, 0, EntityID(2), 0, 0, 0)
        PointJoint(2, EntityID(1),  0, 5.5, 0, EntityID(2), 0, 0, 0)
        PointJoint(3, EntityID(1),  0, -5.5, 0, EntityID(3), 0, 0, 0)   
       
       
        For i=0 To 3
          EntityLinearFactor(i, 1, 1, 0)
        Next
       
       
        ; Camera
        ;
        CreateCamera(0, 0, 0, 100, 100)
        MoveCamera(0, 0, 0, 50, #PB_Absolute)
       
        ;- Light
        ;
        AmbientColor(RGB(25, 25, 25))
        CreateLight(0, RGB(215, 250, 260), 75, 75, 75)
        CreateLight(1, RGB(215, 250, 260), 0, 75, -20)
        LightLookAt(1,0,0,0)
       
        ; GO
        ;
        ApplyEntityImpulse(1,  10, 0, 0)
       
        Plane = CreateEntity(#PB_Any, MeshID(CreatePlane(#PB_Any, 1000, 1000, 100, 100, 10, 10)), MaterialID(2))
        MoveEntity(Plane, 0,-100,0)
        CopyEntity(Plane, 30)
        MoveEntity(30, 0,0,-200)
        RotateEntity(30, 90,0,0)
        SetEntityMaterial(30, MaterialID(3))
       
       
        CreateCapsule(5, 4,70)
        CreateEntity(5, MeshID(5), MaterialID(4), 30,-70,120)
        CreateSphere(6, 20)
        CreateEntity(6, MeshID(6), MaterialID(1), 30,-30,120)
        ScaleEntity(6,1,0.1,1)
       
       
        CameraBackColor(0, RGB(19, 34, 49))
        ;glLineWidth_(3)
       
        Repeat
          Screen3DEvents()
          ExamineKeyboard()
          angle.f + #PI*1/1000
          x.f=Cos(angle)*60
          z.f=Sin(angle)*60
          MoveCamera(0, x, 30, z, #PB_Absolute)
          CameraLookAt(0, 0,0,0)
         
          Draw(trace())
         
          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

    Procedure Draw(List ptr.Vector3())
      If FirstElement(ptr())
        xold.f=ptr()\x
        yold.f=ptr()\y
        zold.f=ptr()\z
       
        If ListSize(ptr())>#MaxHistoricNumber
          DeleteElement(ptr())
        EndIf
        LastElement(ptr())
      EndIf
     
      AddElement(ptr())
      ptr()\x=EntityX(3)
      ptr()\y=EntityY(3)
      ptr()\z=EntityZ(3)
     
      n=10
     
      ForEach ptr()
        colorR.i=ListIndex(ptr())*255/ListSize(ptr())
        CreateLine3D(n, ptr()\x,ptr()\y,ptr()\z,RGB(colorR,0,0),xold,yold,zold,RGB(colorR,0,0))
        xold=ptr()\x
        yold=ptr()\y
        zold=ptr()\z
        n + 1
      Next
    EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Thu Jul 12, 2018 7:09 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3346
Location: New Zealand
8)

_________________
Got winter blues?
Enjoy a Caravan Trip into, "The Land of Grey and Pink", wine and punk weed optional!
https://www.youtube.com/watch?v=9hmFzGTxod4


Top
 Profile  
Reply with quote  
 Post subject: Re: Double pendulum
PostPosted: Mon Jul 16, 2018 11:53 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1406
Location: Doubs - France
With your demo you can comment these lines

Code:
   For i=0 To 3
      EntityLinearFactor(i, 1, 1, 0)
   Next


Quote:
i thought before that CreateLine3D is ugly and static while this demo show that we can use it to simulate a thread.


I used CreateLine3D because i wasnt able to use Ribbon. Since i found goods parameters i changed my code (see first post)

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye