# PureBasic Forum

 It is currently Thu Apr 18, 2019 4:01 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: avoid gravity and rubberPosted: Wed Aug 15, 2018 7:44 am

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4548
Location: Spa, relaxing and thinking, and learning...
Hello, I have got a 0 gravity , I have tried to do collissions with some objects , and after collisions I have noticed every object acquire lower and lower speed ... until it stops any movement.
Any trick to maintain the speed and rotation of an entity?

_________________
http://www.zeitgeistmovie.com

Top

 Post subject: Re: avoid gravity and rubberPosted: Wed Aug 15, 2018 9:50 am

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1196
Location: Germany, Glienicke
If you create your bodies, you have to set the Restitution and the Friction values.
SetEntityAttribute().

For the conservation of velocity (or energy) you have to set Restitution = 1 and Friction = 0.
But be carefully with such settings. In physical simulations it more stable to have restitution < 1 and frictions > 0.

_________________

Top

 Post subject: Re: avoid gravity and rubberPosted: Thu Aug 16, 2018 9:12 pm

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4548
Location: Spa, relaxing and thinking, and learning...
STARGÅTE wrote:
If you create your bodies, you have to set the Restitution and the Friction values.
SetEntityAttribute().

For the conservation of velocity (or energy) you have to set Restitution = 1 and Friction = 0.
But be carefully with such settings. In physical simulations it more stable to have restitution < 1 and frictions > 0.

Sorry, but it is not so simple as you can test with this:
Code:
IncludeFile #PB_Compiler_Home+"examples/3d/Screen3DRequester.pb"
If InitEngine3D()=0
MessageRequester("Error","The 3D Engine can't be initialized",0):End
EndIf
Parse3DScripts()
InitSprite():InitKeyboard():InitMouse()
If Screen3DRequester()=0
MessageRequester("Error","Screen3DRequester can't be initialized",0):End
EndIf
; Textura
CreateTexture(0,128,128)
StartDrawing(TextureOutput(0))
Box(0,0,128,128,\$EEEEEE)
StopDrawing()
WorldGravity(0.0)
; Materiales
CreateMaterial(2,TextureID(0))
SetMaterialColor(2,2,\$D0B86B)
CreateCylinder(3,0.1,7,20,1,1)
varilla.i=CreateEntity(#PB_Any,MeshID(3),MaterialID(2))
MoveEntity(varilla,0,8,0,#PB_Absolute)
CreateEntityBody(varilla,#PB_Entity_CylinderBody,1.0,1.0,0.0)
; Camara
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,12,20,#PB_Absolute)
CameraLookAt(0,0,5,0)
; Luz
CreateLight(0,RGB(160,160,254),0,300,0)
AmbientColor(RGB(105,105,105))

SetEntityAttribute(varilla,#PB_Entity_Restitution,1.0)
SetEntityAttribute(varilla,#PB_Entity_Friction,0.0)
Repeat
Screen3DEvents()
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_M)
ApplyEntityImpulse(varilla,0.14,0,0,0,-2,0)
EndIf
EndIf
TimeSinceLastFrame.i=RenderWorld(50)
Screen3DStats()
FlipBuffers():Delay(9)
Until KeyboardPushed(#PB_Key_Escape)

_________________
http://www.zeitgeistmovie.com

Top

 Post subject: Re: avoid gravity and rubberPosted: Thu Aug 16, 2018 9:34 pm

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1418
Location: Doubs - France
use this

Code:
SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping,0.0)

_________________
http://purebasic.developpez.com/

Top

 Post subject: Re: avoid gravity and rubberPosted: Fri Aug 17, 2018 8:44 am

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4548
Location: Spa, relaxing and thinking, and learning...
Comtois wrote:
use this

Code:
SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping,0.0)

Waaaaa!
Comtois = my Hero

Thanks!

_________________
http://www.zeitgeistmovie.com

Top

 Post subject: Re: avoid gravity and rubberPosted: Fri Aug 24, 2018 5:11 pm

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4548
Location: Spa, relaxing and thinking, and learning...
Hi again Comtois.
After doing that, and after bar is in movement, how can i get linear velocity or angular velocity of the bar?
I tried it with GetEntityAttribute() and several atributes to get it like #PB_Entity_LinearVelocity, #PB_Entity_LinearSleeping, but i get 0.0 every time...

_________________
http://www.zeitgeistmovie.com

Top

 Post subject: Re: avoid gravity and rubberPosted: Sat Aug 25, 2018 7:54 am
 Enthusiast

Joined: Sat Feb 19, 2011 10:06 am
Posts: 767
Location: Denmark
Quote:
but i get 0.0 every time...

I don't get 0.0 values. (on windows)

Code:
IncludeFile #PB_Compiler_Home+"examples/3d/Screen3DRequester.pb"
Global lin.f, ang.f
If InitEngine3D()=0
MessageRequester("Error","The 3D Engine can't be initialized",0):End
EndIf
Parse3DScripts()
InitSprite():InitKeyboard():InitMouse()
If Screen3DRequester()=0
MessageRequester("Error","Screen3DRequester can't be initialized",0):End
EndIf
; Textura
CreateTexture(0,128,128)
StartDrawing(TextureOutput(0))
Box(0,0,128,128,\$EEEEEE)
StopDrawing()
WorldGravity(0.0)
; Materiales
CreateMaterial(2,TextureID(0))
SetMaterialColor(2,2,\$D0B86B)
CreateCylinder(3,0.1,7,20,1,1)
varilla.i=CreateEntity(#PB_Any,MeshID(3),MaterialID(2))
MoveEntity(varilla,0,8,0,#PB_Absolute)
CreateEntityBody(varilla,#PB_Entity_CylinderBody,1.0,1.0,0.0)
; Camara
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,12,20,#PB_Absolute)
CameraLookAt(0,0,5,0)
; Luz
CreateLight(0,RGB(160,160,254),0,300,0)
AmbientColor(RGB(105,105,105))

SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping, 0.0)

Repeat
Screen3DEvents()
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_M)
ApplyEntityImpulse(varilla,0.14,0,0,0,-2,0)
EndIf
EndIf
lin = GetEntityAttribute(varilla,#PB_Entity_LinearVelocity)
ang = GetEntityAttribute(varilla,#PB_Entity_AngularVelocity)
TimeSinceLastFrame.i=RenderWorld(50)
Screen3DStats()

SetWindowTitle(0, StrF(lin) + " - " + StrF(ang))
FlipBuffers():Delay(9)
Until KeyboardPushed(#PB_Key_Escape)

_________________
“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

 Post subject: Re: avoid gravity and rubberPosted: Sat Aug 25, 2018 8:54 am

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4548
Location: Spa, relaxing and thinking, and learning...
You are right DK_PETER,
my problem was i made a collision a ball with the bar, and in the main loop i stupidly retrieved the result of the bar attributes only one time (just after the ball impulsation), and now i've corrected: I retrieve the attribute of the bar one time per loop.

Thanks.

_________________
http://www.zeitgeistmovie.com

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 8 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 4 guests

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

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite