/** * @param restitution反弹系数 * @param friction摩擦力系数 * @param mass */ public void init(float restitution, float friction, float mass) { this.restitution = restitution; this.friction = friction; this.mass = mass; intertia = new javax.vecmath.Vector3f(); RigidBodyConstructionInfo info; if (mass == 0) { info = new RigidBodyConstructionInfo(this.mass, state, shape); } else { shape.calculateLocalInertia(mass, intertia); info = new RigidBodyConstructionInfo(this.mass, state, shape, intertia); } rigidBody = new RigidBody(info); rigidBody.setFriction(friction); rigidBody.setRestitution(restitution); world.addRigidBody(rigidBody); }
private RigidBody localCreateRigidBody( float mass, Transform startTransform, CollisionShape shape) { boolean isDynamic = (mass != 0f); Vector3f localInertia = new Vector3f(); localInertia.set(0f, 0f, 0f); if (isDynamic) { shape.calculateLocalInertia(mass, localInertia); } DefaultMotionState myMotionState = new DefaultMotionState(startTransform); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia); RigidBody body = new RigidBody(rbInfo); ownerWorld.addRigidBody(body); return body; }