Jointrelated changes

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Jointrelated changes

Post by Bananenfreak »

Hey @ all,

there´s a bad thing with Joints. OGRES standart worldscaling is:
Bullet assumes units to be in meters and time in seconds
http://bulletphysics.org/mediawiki-1.5. ... _The_World
But there is a odd thing with Joints an this Default worlddimensions. If you´re using scaling by 1WU = 1meters, a Joint makes a "big" gap between its entities.
(Related Topic: http://www.purebasic.fr/english/viewtop ... 36&t=59726)

For Demonstration, start first code, nothing seems irregular (100WU = 1m), but if you´re start my second code, there´s a big gap between the entities (1WU = 1m).

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: Jointtest            >>
;>>                             >>
;>>  Author: Bananenfreak       >>
;>>                             >>
;>>  Date: 24.06.2014           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>                             >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1, Yaw.f, Pitch.f
Define.i Quit, boden, cyl, count, joint
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0
#CylHeight = 3
#cylMat = 0

Dim cyls.i(#CylHeight - 1)

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, "Jointtest", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 0, 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))
  
  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, 1000)
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 20, 20, 20, #PB_Absolute)
  CameraLookAt(#kam_0, 20, 0, 20)
  CameraRange (#kam_0, 2, 5000)
  CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  
  cyl = CreateCylinder(#PB_Any, 10, 100)
  CreateMaterial(#cylMat, LoadTexture(1, "Wood.jpg"))
  
  For count = 0 To #CylHeight - 1
    cyls(count) = CreateEntity(#PB_Any, MeshID(cyl), MaterialID(#cylMat), 0, count * 100 + 50, 0)
    EntityPhysicBody(cyls(count), #PB_Entity_ConvexHullBody, 10, 0.4, 0.1)
  Next count
  
  ;-opening too big
;   joint = PointJoint(#PB_Any, EntityID(cyls(0)), 0, 5, 0, EntityID(cyls(1)), 0, -5, 0)
;   SetJointAttribute(joint, #PB_PointJoint_Tau, 0)       ;damping decrement
;   SetJointAttribute(joint, #PB_PointJoint_Damping, 2)       ;Speed-Up-Value
  ;-opening too big
  joint = ConeTwistJoint(#PB_Any, EntityID(cyls(0)), 0, 50, 0, EntityID(cyls(1)), 0, -50, 0)
  SetJointAttribute(joint, #PB_ConeTwistJoint_SwingSpan, 0)
  SetJointAttribute(joint, #PB_ConeTwistJoint_SwingSpan2, 0)
  SetJointAttribute(joint, #PB_ConeTwistJoint_TwistSpan, 0)
;-Wobbling and opening too big
; joint = SliderJoint(#PB_Any, EntityID(cyls(0)), 0, 5, 0, EntityID(cyls(1)), 0, -5, 0)
; SetJointAttribute(joint, #PB_SliderJoint_LowerLimit, 0)
; SetJointAttribute(joint, #PB_SliderJoint_UpperLimit, 0)
  
  
  Repeat
    Repeat
    Until WindowEvent() = 0
    
    
    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 
      
    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

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: Jointtest            >>
;>>                             >>
;>>  Author: Bananenfreak       >>
;>>                             >>
;>>  Date: 24.06.2014           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>                             >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1, Yaw.f, Pitch.f
Define.i Quit, boden, cyl, count, joint
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0
#CylHeight = 3
#cylMat = 0

Dim cyls.i(#CylHeight - 1)

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, "Jointtest", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 0, 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))
  
  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, 1000)
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 20, 20, 20, #PB_Absolute)
  CameraLookAt(#kam_0, 20, 0, 20)
  CameraRange (#kam_0, 2, 5000)
  CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  
  cyl = CreateCylinder(#PB_Any, 1, 10)
  CreateMaterial(#cylMat, LoadTexture(1, "Wood.jpg"))
  
  For count = 0 To #CylHeight - 1
    cyls(count) = CreateEntity(#PB_Any, MeshID(cyl), MaterialID(#cylMat), 0, count * 10 + 5, 0)
    EntityPhysicBody(cyls(count), #PB_Entity_ConvexHullBody, 10, 0.4, 0.1)
  Next count
  
  ;-opening too big
;   joint = PointJoint(#PB_Any, EntityID(cyls(0)), 0, 5, 0, EntityID(cyls(1)), 0, -5, 0)
;   SetJointAttribute(joint, #PB_PointJoint_Tau, 0)       ;damping decrement
;   SetJointAttribute(joint, #PB_PointJoint_Damping, 2)       ;Speed-Up-Value
  ;-opening too big
  joint = ConeTwistJoint(#PB_Any, EntityID(cyls(0)), 0, 5, 0, EntityID(cyls(1)), 0, -5, 0)
  SetJointAttribute(joint, #PB_ConeTwistJoint_SwingSpan, 0)
  SetJointAttribute(joint, #PB_ConeTwistJoint_SwingSpan2, 0)
  SetJointAttribute(joint, #PB_ConeTwistJoint_TwistSpan, 0)
;-Wobbling and opening too big
; joint = SliderJoint(#PB_Any, EntityID(cyls(0)), 0, 5, 0, EntityID(cyls(1)), 0, -5, 0)
; SetJointAttribute(joint, #PB_SliderJoint_LowerLimit, 0)
; SetJointAttribute(joint, #PB_SliderJoint_UpperLimit, 0)
  
  
  Repeat
    Repeat
    Until WindowEvent() = 0
    
    
    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 
      
    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
Badly, I found no Parameter or function for this in OGREdocumentation (http://stderr.org/doc/ogre-doc/api/clas ... Joint.html). So, after I wrote this text, I wonder if there is such an paratmeter or not...
Image
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: Jointrelated changes

Post by Bananenfreak »

Here´s a screenshot describing the Problem:
Image

So now I think it´s not caused by the Jointsection. Please move this to Trash ^^
Image
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Jointrelated changes

Post by Comtois »

Mesh's BoudingBox is used to calculate the body.
But Ogre add a pad by default (btw it's optional, we will have to let choice):
"a certain padding will be added to the bounding box to separate it from the mesh"
it's what you can see on your picture.
Please correct my english
http://purebasic.developpez.com/
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: Jointrelated changes

Post by Bananenfreak »

Thank you Comtois :)
Image
Post Reply