예제 #1
0
  protected void doGroundMovement() {
    if (!isOnGround) return;

    // ground movement is as follows, the arrow key dictate the target velocity, and accelleration
    // is
    // added to achieve that. If opposing keys are held the target velocity is set to zero.

    // This is the velocity in the normal plane in the player space
    Vector3f targetVelocity = new Vector3f();
    if (forward) targetVelocity.z += 1;
    if (backward) targetVelocity.z -= 1;
    if (left) targetVelocity.x -= 1;
    if (right) targetVelocity.x += 1;

    if (forward != backward || left != right) {
      targetVelocity.normalize();
      targetVelocity.scale(MAX_SPEED);
    }

    forward = false;
    backward = false;
    left = false;
    right = false;

    Vector3f forward = new Vector3f(0, 0, 1);
    QuaternionUtil.quatRotate(owner.getOrientation(), forward, forward);

    // right = normal x forward
    // forward = right x normal
    Vector3f right = new Vector3f();
    right.cross(surfaceNormal, forward);
    forward.cross(right, surfaceNormal);
    right.normalize();
    forward.normalize();

    Matrix3f transform = new Matrix3f();
    transform.setColumn(0, right);
    transform.setColumn(1, surfaceNormal);
    transform.setColumn(2, forward);

    transform.transform(targetVelocity);

    Vector3f delta = new Vector3f();
    owner.getRigidBody().getLinearVelocity(delta);
    delta.sub(targetVelocity, delta);

    // feet can't pull and don't need to push for now
    // Ds = D - N(N.D)
    Vector3f parComp = new Vector3f(surfaceNormal);
    parComp.scale(surfaceNormal.dot(delta));
    delta.sub(delta, parComp);

    owner.getRigidBody().applyCentralForce(scaleForce(delta));
  }
예제 #2
0
 public void setTransform(
     float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) {
   if (matrixRotate != null || !doSetOrientation) return;
   matrixRotate = new Matrix3f();
   Vector3f v = new Vector3f();
   // rows in Sygress/CAChe and Spartan become columns here
   v.set(x1, y1, z1);
   v.normalize();
   matrixRotate.setColumn(0, v);
   v.set(x2, y2, z2);
   v.normalize();
   matrixRotate.setColumn(1, v);
   v.set(x3, y3, z3);
   v.normalize();
   matrixRotate.setColumn(2, v);
   atomSetCollection.setAtomSetCollectionAuxiliaryInfo(
       "defaultOrientationMatrix", new Matrix3f(matrixRotate));
   // first two matrix column vectors define quaternion X and XY plane
   Quaternion q = new Quaternion(matrixRotate);
   atomSetCollection.setAtomSetCollectionAuxiliaryInfo("defaultOrientationQuaternion", q);
   Logger.info("defaultOrientationMatrix = " + matrixRotate);
 }