作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在LibGDX Bullet Physics中如何使软体弹跳。我将“软体球的复原”设置为0.5,将“刚体地面的恢复”设置为1.0。我为球对象尝试了btSoftBody,为地面对象尝试了btRigidBody。击球时球不会反弹。
@Override
public void create() {
super.create();
world.maxSubSteps = 20;
world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f));
final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
final Model sphere = modelBuilder.createSphere(0.5f, 0.5f, 0.5f, 24, 24, material, attributes);
model = sphere;
MeshPart meshPart = model.nodes.get(0).parts.get(0).meshPart;
meshPart.mesh.scale(6, 6, 6);
indexMap = BufferUtils.newShortBuffer(meshPart.size);
positionOffset = meshPart.mesh.getVertexAttribute(Usage.Position).offset;
normalOffset = meshPart.mesh.getVertexAttribute(Usage.Normal).offset;
softBody = new btSoftBody(worldInfo, meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset, normalOffset, meshPart.mesh.getIndicesBuffer(), meshPart.offset, meshPart.size, indexMap, 0);
btSoftBody.Material pm = softBody.appendMaterial();
pm.setKLST(0.9f);
pm.setFlags(0);
softBody.generateBendingConstraints(2, pm);
softBody.setConfig_piterations(90);
softBody.setConfig_kDF(0.5f);
softBody.setConfig_kCHR(1);
softBody.setConfig_kDP(0);
softBody.randomizeConstraints();
softBody.setTotalMass(0.01f, true);
softBody.setContactStiffnessAndDamping(2000f, 0f);
softBody.generateClusters(1);
softBody.setConfig_maxvolume(200f);
softBody.setRestitution(0.5f);
softBody.setCollisionFlags(softBody.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
softBody.setFriction(0f);
((btSoftRigidDynamicsWorld) (world.collisionWorld)).addSoftBody(softBody);
world.entities.get(0).body.setRestitution(1f);
world.add(entity = new BulletEntity(model, (btCollisionObject) null, 1, 5, 1));
softBody.setActivationState(Collision.WANTS_DEACTIVATION);
softBody.translate(tmpV.set(1, 5, 1));
}
最佳答案
试试这个:
softBody.generateBendingConstraints(2, pm);
pm.setKLST(0.2f);
pm.setFlags(0);
softBody.generateBendingConstraints(2, pm);
softBody.setConfig_piterations(7);
softBody.setConfig_kDF(0.2f);
softBody.randomizeConstraints();
softBody.setTotalMass(1);
softBody.translate(tmpV.set(1, 5, 1));
((btSoftRigidDynamicsWorld)(world.collisionWorld)).addSoftBody(softBody);
pm.setKLST(0.9f);
pm.setFlags(0);
softBody.generateBendingConstraints(2, pm);
softBody.setConfig_piterations(90);
softBody.setConfig_kDF(0.5f);
softBody.setConfig_kCHR(1);
softBody.setConfig_kDP(0);
softBody.randomizeConstraints();
softBody.setTotalMass(0.01f, true);
softBody.setContactStiffnessAndDamping(2000f, 0f);
softBody.generateClusters(1);
softBody.setConfig_maxvolume(200f);
softBody.setRestitution(0.5f);
softBody.setCollisionFlags(softBody.getCollisionFlags() |
btCollisionObject.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
softBody.setFriction(0f);
关于libgdx - 如何在LibGDX Bullet Physics中使软体弹跳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52454042/
我是一名优秀的程序员,十分优秀!