/**
  * @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);
 }
Beispiel #2
0
  RigidBody createBody(
      float mass,
      Vector3f position,
      CollisionShape shape,
      Float initialVelocity,
      Matrix3f orientation) {

    // Create Dynamic Objects
    Transform startTransform = new Transform();
    startTransform.setIdentity();
    // rigidbody is dynamic if and only if mass is non zero,
    // otherwise static
    boolean isDynamic = (mass != 0f);
    Vector3f localInertia = new Vector3f(0, 0, 0);
    if (isDynamic) {
      shape.calculateLocalInertia(mass, localInertia);
    }
    if (orientation != null) {
      startTransform.set(orientation);
    }
    startTransform.origin.set(position);
    // using motionstate is recommended, it provides
    // interpolation capabilities, and only synchronizes
    // 'active' objects
    DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
    RigidBodyConstructionInfo rbInfo =
        new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia);

    RigidBody rb = new RigidBody(rbInfo);
    rb.setFriction(0.4f);
    // rb.setDamping(0.7f, 0.7f);
    if (initialVelocity != 0f && orientation != null) {
      synchronized (initialVelocityVector) {
        initialVelocityVector.set(0f, 0f, initialVelocity);
        orientation.transform(initialVelocityVector);
        rb.setLinearVelocity(initialVelocityVector);
      }
    }
    return rb;
  }