@Override
 public boolean pinch(
     Vector2 initialFirstPointer,
     Vector2 initialSecondPointer,
     Vector2 firstPointer,
     Vector2 secondPointer) {
   if (!(initialFirstPointer.equals(oldInitialFirstPointer)
       && initialSecondPointer.equals(oldInitialSecondPointer))) {
     oldInitialFirstPointer = initialFirstPointer.cpy();
     oldInitialSecondPointer = initialSecondPointer.cpy();
     oldScale = gameScreen.getCameraZoom();
   }
   Vector3 center =
       new Vector3(
           (firstPointer.x + initialSecondPointer.x) / 2,
           (firstPointer.y + initialSecondPointer.y) / 2,
           0);
   gameScreen.zoomCamera(
       center,
       oldScale * initialFirstPointer.dst(initialSecondPointer) / firstPointer.dst(secondPointer));
   return true;
 }
Esempio n. 2
0
  /**
   * Update position & velocity vectors given acceleration and deltaTime
   *
   * @param deltaTime
   */
  private void updatePosition(float deltaTime) {
    if (accel.len() > 0) {
      accel.scl(deltaTime); // dv = a * dt
      velocity.add(accel.x, accel.y); // vf = vi + dv

      // Limit velocity to max
      if (velocity.len() > MAX_VELOCITY) {
        velocity.nor().scl(MAX_VELOCITY);
      }
    }
    Vector2 deltaPos = new Vector2(velocity.x * deltaTime, velocity.y * deltaTime);

    Vector2 newDelta = Collision.tryMove(this, bounds, deltaPos);
    if (!newDelta.equals(deltaPos)) { // We hit something
      stopMoving();
    }
    position.add(newDelta); // d = d*dt
  }