3

i am using blender to create my models, and loading them into Libgdx, if i create them with the Origin in the center of the model like below and then use this code to create the rigid body, all works fine

        Vector3 hescoWallHalfExtents = new Vector3(hescoWall.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);

enter image description here

however if i place the bottom of the model level with the ground like this

enter image description here

then the btRigidbody is offset like this

enter image description here

is there an obvious way that i can offset the height of the rigidbody?

many thanks.

Spriggsy

Spriggsy
  • 196
  • 1
  • 18

1 Answers1

6

The center (origin) of the rigid body is the same as the center of mass and therefor an important property for the physics simulation. You could "move" this center using a btCompoundShape if you like, but this will also influence the physics simulation and therefore probably won't give you satisfying results.

Alternatively, you could compensate for the difference of physics origin and visual origin in your btMotionState. For example by setting ModelInstance#transform to the provided worldTransform multiplied by the a Matrix4 instance which contains the offset (use Matrix4#translate for example).

However, this is probably just making it more complex than it needs to be. You could say that the real question is why you want offset the center of model compared to the body? For example, in you second image the center of the model appears to be same as the in the first image. You only moved the Node, basically indicating that you want to provide an initial value for the ModelInstance#transform member. You can achieve this by instantiating the ModelInstance as follows:

modelInstance = new ModelInstance(model, "coneNode", true);

Replace "coneNode" with the name of the node as created it in your modeling application. The last (true) argument tells the ModelInstance to set its transform member to the transformation you've given it in the modeling application. If needed, you can call modelInstance.transform.translate(x, y, z); or modelInstance.transform.trn(x, y, z); to move the modelInstance relative to this transformation.

A more in-depth explanation of this can be found here: http://blog.xoppa.com/loading-a-scene-with-libgdx/

Note that this only works if you're using .g3db or .g3dj files (e.g. using fbx-conv) created from a file format that supports node transformations (e.g. .fbx, but not .obj)

Xoppa
  • 7,983
  • 1
  • 23
  • 34
  • I am been reading your tutorial for 2 days now, searching the entire web to figure out what went wrong, until I found this. Wow this solves everything for me. Tnx a lot! – Ilya Gazman May 20 '16 at 09:20