javaparametersjbullet

How to Create a "BoxShape" in jBullet?


I want to create a BoxShape in jBullet. The constructor asks for a Vector3f object as parameter which asks for three float parameters.

BoxShape(Vector3f boxHalfExtends) //The constructor for the "BoxShape" class.

I have looked at the jBullet page and couldn't find what boxHalfExtends is.

What am I supposed to enter to the constructor parameter for the BoxShape?


Solution

  • "To create a box you have to pass a vector with the half-extents."

    Source: http://www.panda3d.org/manual/index.php/Bullet_Collision_Shapes

    What that means is, you need to pass in half of the width and height for the box on the x,y,z axises.

    float dx = 0.5f; //X Width = 0.5 * 2 = dx - (-dx) = 1
    float dy = 0.5f; //Y Width = 0.5 * 2 = dy - (-dy) = 1
    float dz = 1.0f; //Z Width = 1.0 * 2 = dz - (-dz) = 2
    
    CollisionObject boxShape = BoxShape(Vector3f(dx, dy, dz));
    

    The dx,dy,dz values aren't about where on the world the box is placed but how big it is.