Reputation: 40
I am new to bullet physics and already facing annoying problem with shapes,...I have this java class that extends ModelInstance:
public class CustomModel extends ModelInstance implements Disposable {
RigidBodyInfo rigidBodyInfo;
btRigidBody rigidBody;
//btBvhTriangleMeshShape shape;
btCollisionShape shape;
btTriangleIndexVertexArray vertexArray;
public CustomModel(Model model,btDynamicsWorld world,float mass){
super(model);
vertexArray = new btTriangleIndexVertexArray(model.meshParts);
if(mass==0){
shape=new btBvhTriangleMeshShape(vertexArray,true);
} else{
shape=new btGImpactMeshShape(vertexArray);
shape.setLocalScaling(new Vector3(1,1,1));
shape.setMargin(0);
((btGImpactMeshShape)shape).updateBound();
}
rigidBodyInfo=new RigidBodyInfo(mass,shape);
rigidBody = new btRigidBody(rigidBodyInfo);
rigidBody.setRestitution(0);
rigidBody.setMotionState(new GameMotionState(this));
world.addRigidBody(rigidBody);
//rigidBody.setActivationState(Collision.DISABLE_DEACTIVATION);
}
public btRigidBody getRigidBody(){
return rigidBody;
}
public void setTranslation(Vector3 vector3){
transform.setTranslation(vector3);
rigidBody.setWorldTransform(transform);
rigidBody.setLinearVelocity(new Vector3());
rigidBody.setActivationState(Collision.ACTIVE_TAG);
}
public void setTranslation(float x,float y,float z){
transform.setTranslation(x,y,z);
rigidBody.setWorldTransform(transform);
rigidBody.setLinearVelocity(new Vector3());
rigidBody.setActivationState(Collision.ACTIVE_TAG);
}
@Override
public void dispose() {
rigidBody.dispose();
rigidBodyInfo.dispose();
if(vertexArray!=null)
vertexArray.dispose();
shape.dispose();
}
}
the problem is happening when I add two Boxes using ModelBuilder.createBox, the two boxes doesn't collide with each other.. i have read that btBvhTriangleMeshShape is for only static bodies, also i have tried Bullet.obtainStaticNodeShape(...), and it doesn't work for me. how i create the Model :
Model cubeModel = new ModelBuilder().createBox(0.25f,0.25f,0.25f,material,VertexAttributes.Usage.Position|VertexAttributes.Usage.Normal|VertexAttributes.Usage.TextureCoordinates);
modelInstance = new CustomModel(cubeModel,world,0);
cube = new CustomModel(cubeModel,world,1);
cube.setTranslation(0f,10,0f);
then render it normally .. RigidBodyInfo class :
public class RigidBodyInfo extends btRigidBody.btRigidBodyConstructionInfo {
public static Vector3 tempV=new Vector3();
public RigidBodyInfo(float mass,btCollisionShape shape){
super(mass,null,shape,calc(mass,shape));
}
public static Vector3 calc(float mass,btCollisionShape shape){
shape.calculateLocalInertia(mass,tempV);
return tempV;
}
@Override
public void dispose() {
super.dispose();
}
}
i have have tried: Bullet.obtainStaticNodeShape() and it works good with btBoxShape but I don't need it ...
Upvotes: 1
Views: 48