Ich bin neu in der Bullet Physics und hat bereits ein nerviges Problem mit Formen, ... Ich habe diese Java -Klasse, die Modellinstanz erweitert: < /p>
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();
}
}
< /code>
Das Problem tritt auf, wenn ich zwei Kästchen mit ModelBuilder.createbox hinzufüge. Die beiden Boxen kollidieren nicht miteinander.
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);
< /code>
Dann rendern Sie es normal ..
starridbodyInfo -Klasse: < /p>
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();
}
}
< /code>
Ich habe es versucht:
bullet.obtainstaticNoDeshape()
und es funktioniert gut mit BTBoxShape, aber ich brauche es nicht ... < /p>
Libgdx-Bullet BtgimpactMeshshape funktioniert für starrkörper nicht ⇐ Android
-
- Similar Topics
- Replies
- Views
- Last post