0
\$\begingroup\$

How do I make a btBoxShape around a Model or ModelInstance in Libgdx? This is my code:

modelInstance.calculateBoundingBox(boundingBox);
collisionShape = new btBoxShape(boundingBox.getDimensions(tempVector3).scl(.5f));

This works and creates a box of the right size but it is offset from the model. I cant figure out how to make it around the model and not offset.

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

You have to use a btMotionState to synchronize model and bullet transforms. You use it like this (example taken from LibGDX wiki):

// Create your own implementation
public class MyMotionState extends btMotionState {
    Matrix4 transform;

    @Override
    public void getWorldTransform (Matrix4 worldTrans) {
        worldTrans.set(transform);
    }

    @Override
    public void setWorldTransform (Matrix4 worldTrans) {
        transform.set(worldTrans);
    }
}

// Then attach it to your body
btRigidBody body = ...;
ModelInstance instance = ...;
MyMotionState motionState = new MyMotionState();
motionState.transform = instance.transform;
body.setMotionState(motionState);

The wiki is a very good place to get information about how to use the wrapper. You should also check out Xoppa's blog on the subject as he goes into more in-depth solutions.

\$\endgroup\$
0
\$\begingroup\$

You are setting it to offset with scaling dimensions with 0.5f . Try not to scale it or just create new vector3 at {0,0,0} .

collisionShape = new btBoxShape(boundingBox.getDimensions(tempVector3));
\$\endgroup\$
2
  • \$\begingroup\$ The scaling is because the parameters for the btBoxShape are half extents. I have tried making a new vector without scaling and it still doesn't work. \$\endgroup\$ Commented Aug 14, 2016 at 20:33
  • \$\begingroup\$ Can you provide screen capture. \$\endgroup\$ Commented Aug 14, 2016 at 20:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .