avoid gravity and rubber

Everything related to 3D programming
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

avoid gravity and rubber

Post by Psychophanta »

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?
Thanks in advance.
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
User avatar
STARGÅTE
Addict
Addict
Posts: 2086
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: avoid gravity and rubber

Post by STARGÅTE »

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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: avoid gravity and rubber

Post by Psychophanta »

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: Select all

IncludeFile #PB_Compiler_Home+"examples/3d/Screen3DRequester.pb"
If InitEngine3D()=0
  MessageRequester("Error","The 3D Engine can't be initialized",0):End
EndIf
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/fonts", #PB_3DArchive_FileSystem)
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)
; Entidades
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

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: avoid gravity and rubber

Post by Comtois »

use this

Code: Select all

SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping,0.0)
Please correct my english
http://purebasic.developpez.com/
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: avoid gravity and rubber

Post by Psychophanta »

Comtois wrote:use this

Code: Select all

SetEntityAttribute(varilla,#PB_Entity_LinearSleeping,0)
SetEntityAttribute(varilla,#PB_Entity_AngularSleeping,0.0)
Waaaaa!
Comtois = my Hero :!:

Thanks!
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: avoid gravity and rubber

Post by Psychophanta »

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

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: avoid gravity and rubber

Post by DK_PETER »

but i get 0.0 every time...
I don't get 0.0 values. (on windows)

Code: Select all

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
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/fonts", #PB_3DArchive_FileSystem)
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)
; Entidades
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)
 
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: avoid gravity and rubber

Post by Psychophanta »

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

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
Post Reply