Page 1 of 1

Strange things with Physicsbodies

Posted: Sat May 03, 2014 4:45 pm
by Bananenfreak
Heyho,

I found a few strange things with Physicsbodies. These types:

Code: Select all

#PB_Entity_CylinderBody
#PB_Entity_BoxBody
#PB_Entity_CapsuleBody
do a strange effect with my Meshes... Capsulebody ist too Little, cylinder and box are shifted down (I think ~1 WU).

Here´s my code (You can test it with your entities, too):

Code: Select all

;
; ------------------------------------------------------------
;
;   Entity-Physicsbodybug
;
;   (c) 2014 - Chimorin
;
; ------------------------------------------------------------
;
EnableExplicit


Structure Vektor3
  x.d
  y.d
  z.d
EndStructure


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Yaw.f, Pitch.f
Define.i Quit, boden, zaehler, toggler, mesh, red, blue, green, test1, test2, test3, tree, test4, test5
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0
#light = 0


If InitEngine3D()
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive("\", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  ;-Window
  OpenWindow(#window, 0, 0, 1800, 1000, "Entityphysicsbug", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 0, 10, 10, #PB_Screen_SmartSynchronization)
  
  ;-Light
  CreateLight(#light, RGB(255, 255, 255), 30, 20, 30)
  
  ;-World
  EnableWorldPhysics(#True)
  EnableWorldCollisions(#True)
  WorldGravity(-9.81)
  WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
  WorldDebug(#PB_World_DebugBody)
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  
  ;-Allgemein
  CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
  boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  red = GetScriptMaterial(#PB_Any, "Color/Red")
  blue = GetScriptMaterial(#PB_Any, "Color/Blue")
  green = GetScriptMaterial(#PB_Any, "Color/Green")
  MaterialFilteringMode(boden, #PB_Material_Anisotropic, 16)
  CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
  EntityPhysicBody(#planent, #PB_Entity_StaticBody)
  EntityRenderMode(#planent, 0)
  
  ;Mesh and Entities
  tree = LoadMesh(#PB_Any, "ninja.mesh")        ;-Here you have to load your mesh.
  test1 = CreateEntity(#PB_Any, MeshID(tree), MaterialID(red), 0, 10, 0)
  ScaleEntity(test1, 0.01, 0.01, 0.01, #PB_Relative)
  EntityPhysicBody(test1, #PB_Entity_BoxBody, 30)
  
  test2 = CreateEntity(#PB_Any, MeshID(tree), MaterialID(blue), 10, 10, 0)
  ScaleEntity(test2, 0.01, 0.01, 0.01, #PB_Relative)
  EntityPhysicBody(test2, #PB_Entity_CylinderBody, 30)
  
  test3 = CreateEntity(#PB_Any, MeshID(tree), MaterialID(green), 0, 11, 10)
  ScaleEntity(test3, 0.01, 0.01, 0.01, #PB_Relative)
  EntityPhysicBody(test3, #PB_Entity_ConvexHullBody, 30)
  
  test4 = CreateEntity(#PB_Any, MeshID(tree), MaterialID(green), 10, 10, 20)
  ScaleEntity(test4, 0.01, 0.01, 0.01, #PB_Relative)
  EntityPhysicBody(test4, #PB_Entity_CapsuleBody, 30)
  
  test5 = CreateEntity(#PB_Any, MeshID(tree), MaterialID(green), 20, 10, 30)
  ScaleEntity(test5, 0.01, 0.01, 0.01, #PB_Relative)
  EntityPhysicBody(test5, #PB_Entity_ConvexHullBody, 30)
  
  
  ;-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))
  
  Repeat
    If ExamineMouse()
      Yaw   = -MouseDeltaX() * 0.05
      Pitch = -MouseDeltaY() * 0.05
    EndIf
    
    If ExamineKeyboard()
      
      If KeyboardPushed(#PB_Key_Up)    
        MoveCamera(0,  0, 0, -2)
      ElseIf KeyboardPushed(#PB_Key_Down)
        MoveCamera(0,  0, 0,  2)
      EndIf 
      
      If KeyboardPushed(#PB_Key_Left)  
        MoveCamera(0, -2, 0, 0) 
      ElseIf KeyboardPushed(#PB_Key_Right)
        MoveCamera(0,  2, 0, 0)
      EndIf
      
      If KeyboardReleased(#PB_Key_Q)
        If Not toggler
          toggler = 1
        Else
          toggler = 0
        EndIf
      EndIf
      
    EndIf
    
    RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
    
    If toggler
      RenderWorld()
    Else
      RenderWorld(0)
    EndIf
    FlipBuffers()
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End
And here´s a Picture (for the lazy ones :twisted: ):
Image
How to Change the size of Pictures? It´s very small (Just click on it)

Re: Strange things with Physicsbodies

Posted: Sat May 03, 2014 10:18 pm
by Comtois
'ConvexHullBody' is built using mesh's vertices.
'BoxBody' is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates.
idem for 'CapsuleBody' and 'CylinderBody'.

[EDIT]
You can use MeshMagick to translate ninja's origin

Re: Strange things with Physicsbodies

Posted: Sun May 04, 2014 8:30 am
by Bananenfreak
Hey Comtois,
this should be referenced in the doc (This is an important Thing).
Another Thing: Origin of Mesh is also Center of mass of any mesh, so you can´t move it anywhere, because bullet rotates every entity around its com.

I don´t know there´s an program for translating origin of meshes, good to know, thank you :)