[No bug] AppliedImpulse - Same value for X/Y/Z

Just starting out? Need help? Post your questions and find answers here.
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

[No bug] AppliedImpulse - Same value for X/Y/Z

Post by Bananenfreak »

Hello friends,

I found a possible bug. When Worldcollisions are used the values for the applied Impulses received via GetX/Y/Z() are always equal.
Even if there´s only an applied Impulse in one direction (In my code it´s X).

Please try my code and tell my your result. With "Q" you can apply an Impulse on one ball:

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: GetX/Y/Z()-Error     >>
;>>                             >>
;>>  Author: Bananenfreak       >>
;>>                             >>
;>>  Date: 14.02.2016           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>                             >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1, Yaw.f, Pitch.f
Define.i Quit
Global.i boden, ball
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0


Procedure BuildUp()
  Protected.i mesh, ent
  
  
  mesh = CreateSphere(#PB_Any, 0.25, 16, 16)
  ball = CreateEntity(#PB_Any, MeshID(mesh), MaterialID(boden), -5, 10.25, 0)
  EntityPhysicBody(ball, #PB_Entity_SphereBody, 5, 0, 0)
  ent = CreateEntity(#PB_Any, MeshID(mesh), MaterialID(boden), 5, 10.25, 0)
  EntityPhysicBody(ent, #PB_Entity_SphereBody, 5, 0, 0)
  mesh = CreateCube(#PB_Any, 1)
  TransformMesh(mesh, 0,0,0, 11, 0.1, 1, 0, 0, 0)
  ent = CreateEntity(#PB_Any, MeshID(mesh), #PB_Material_None, 0, 9.9, 0)
  EntityPhysicBody(ent, #PB_Entity_StaticBody, 5, 0, 0)
  mesh = CreateCube(#PB_Any, 1)
  TransformMesh(mesh, 0,0,0, 11, 1, 0.2, 0, 0, 0)
  ent = CreateEntity(#PB_Any, MeshID(mesh), #PB_Material_None, 0, 10.4, -0.4)
  EntityPhysicBody(ent, #PB_Entity_StaticBody, 5, 0, 0)
  mesh = CreateCube(#PB_Any, 1)
  TransformMesh(mesh, 0,0,0, 11, 1, 0.2, 0, 0, 0)
  ent = CreateEntity(#PB_Any, MeshID(mesh), #PB_Material_None, 0, 10.4, 0.4)
  EntityPhysicBody(ent, #PB_Entity_StaticBody, 5, 0, 0)
  mesh = CreateCube(#PB_Any, 1)
  TransformMesh(mesh, 0,0,0, 0.2, 1, 0.6, 0, 0, 0)
  ent = CreateEntity(#PB_Any, MeshID(mesh), #PB_Material_None, 5.6, 10.4, 0)
  EntityPhysicBody(ent, #PB_Entity_StaticBody, 5, 0, 0)
    mesh = CreateCube(#PB_Any, 1)
  TransformMesh(mesh, 0,0,0, 0.2, 1, 0.6, 0, 0, 0)
  ent = CreateEntity(#PB_Any, MeshID(mesh), #PB_Material_None, -5.6, 10.4, 0)
  EntityPhysicBody(ent, #PB_Entity_StaticBody, 5, 0, 0)
EndProcedure


Procedure PhysikWorker()
  Protected.i first, sec
  
  
  ExamineWorldCollisions(#True)
  
  While NextWorldCollision()
    first = FirstWorldCollisionEntity()
    sec = SecondWorldCollisionEntity()
    
    WorldCollisionAppliedImpulse()
    Debug "X: " + GetX()
    Debug "Y: " + GetY()
    Debug "Z: " + GetZ()
  Wend
EndProcedure


If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  OpenWindow(#window, 0, 0, 1800, 1000, "GetX/Y/Z-Bug", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 1, 10, 10, #PB_Screen_SmartSynchronization)
  
  WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
  
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  EnableWorldPhysics(#True)
  EnableWorldCollisions(#True)
  
  CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
  boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
  EntityPhysicBody(#planent, #PB_Entity_StaticBody)
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 0, 20, 0, #PB_Absolute)
  CameraLookAt(#kam_0, 20, 0, 20)
  CameraRange (#kam_0, 2, 5000)
  CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  
  BuildUp()
  
  
  Repeat
    Debug "---------------------------------------"
    Repeat
    Until WindowEvent() = 0
    
    PhysikWorker()
    
    If ExamineMouse()
      Yaw   = -MouseDeltaX() * 0.05
      Pitch = -MouseDeltaY() * 0.05
    EndIf
    
    If ExamineKeyboard()
      
      If KeyboardPushed(#PB_Key_Up)    
        MoveCamera(0,  0, 0, -1 * Boost)
      ElseIf KeyboardPushed(#PB_Key_Down)
        MoveCamera(0,  0, 0,  1 * Boost)
      EndIf 
      
      If KeyboardPushed(#PB_Key_Left)  
        MoveCamera(0, -1 * Boost, 0, 0) 
      ElseIf KeyboardPushed(#PB_Key_Right)
        MoveCamera(0,  1 * Boost, 0, 0)
      EndIf 
      
      If KeyboardReleased(#PB_Key_Q)
        ApplyEntityImpulse(ball, 100, 0, 0)
      EndIf
      
    EndIf
    
    RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
    
    RenderWorld()
    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 Bananenfreak on Mon Feb 29, 2016 7:29 pm, edited 1 time in total.
Image
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: AppliedImpulse - Same value for X/Y/Z

Post by Comtois »

in previous version WorldCollisionAppliedImpulse() was wrong, it is not a vector, but a float.
Result.f = WorldCollisionAppliedImpulse()
Please correct my english
http://purebasic.developpez.com/
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: AppliedImpulse - Same value for X/Y/Z

Post by Bananenfreak »

Uh, sorry :oops:
I'm using 5.41 LTS, but haven't looked in the documentation yet.
Haven't used PB for a while (no time for it) and a new Version was released :shock:

What about the direction of the applied Impulse? We can get the vector normal to the surface and the Position, but not the direction of the applied Impulse.

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

Re: AppliedImpulse - Same value for X/Y/Z

Post by Comtois »

Bananenfreak wrote:What about the direction of the applied Impulse? We can get the vector normal to the surface and the Position, but not the direction of the applied Impulse.
Erwin Coumans wrote:Indeed, m_appliedImpulse*m_normalWorldOnB is your applied impulse vector.
With PB
m_appliedImpulse = WorldCollisionAppliedImpulse()
m_normalWorldOnB = WorldCollisionNormal()

http://www.bulletphysics.org/Bullet/php ... f=9&t=2568
Please correct my english
http://purebasic.developpez.com/
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: [No bug] AppliedImpulse - Same value for X/Y/Z

Post by Bananenfreak »

Yes Comtois, you're right.
The contact normals are the inversed direction of the applied impulse for the second entity.
Image
Post Reply