Пример #1
0
  public static Renderer constructNewBatch(int renderMode) {
    List<Renderer> list = POOL.get(renderMode);
    if (list == null) {
      // If we're using a POOL, it should already be intialized
      throw new IllegalStateException("Pool uninitialized!");
    }
    if (!list.isEmpty()) {
      Renderer batch = list.remove(0);
      ((BatchVertexRenderer) batch).used++;
      return batch;
    }

    Client client = (Client) Spout.getEngine();

    switch (client.getRenderMode()) {
      case GL20:
        return new GL20BatchVertexRenderer(renderMode);
      case GL30:
        return new GL30BatchVertexRenderer(renderMode);
      case GL40:
        return new GL30BatchVertexRenderer(renderMode);
      case GLES20:
        return new GLES20BatchVertexRenderer(renderMode);
      default:
        throw new IllegalArgumentException("GL Mode:" + client.getRenderMode() + " Not recognized");
    }
  }
Пример #2
0
  public static void initPool(int renderMode, int number) {
    List<Renderer> list = POOL.get(renderMode);

    if (list == null) {
      list = new LinkedList<>();
      POOL.put(renderMode, list);
    }

    Client client = (Client) Spout.getEngine();

    switch (client.getRenderMode()) {
      case GL20:
        for (int i = 0; i < number; i++) {
          list.add(new GL20BatchVertexRenderer(renderMode));
        }
        return;
      case GL30:
        for (int i = 0; i < number; i++) {
          list.add(new GL30BatchVertexRenderer(renderMode));
        }
        return;
      case GL40:
        for (int i = 0; i < number; i++) {
          list.add(new GL30BatchVertexRenderer(renderMode));
        }
        return;
      case GLES20:
        for (int i = 0; i < number; i++) {
          list.add(new GLES20BatchVertexRenderer(renderMode));
        }
        return;
      default:
        throw new IllegalArgumentException("GL Mode:" + client.getRenderMode() + " Not recognized");
    }
  }
  @Override
  public void onTick(float dt) {
    final Client client = (Client) Spout.getEngine();
    final Transform playerTransform = client.getPlayer().getPhysics().getTransform();
    final PlayerInputState state = client.getPlayer().input();
    final float speed = 50f;
    Vector3f motion = Vector3f.ZERO;
    if (state.getForward()) {
      motion = motion.add(playerTransform.forwardVector().mul(speed * -dt));
    }
    if (state.getBackward()) {
      motion = motion.add(playerTransform.forwardVector().mul(speed * dt));
    }
    if (state.getLeft()) {
      motion = motion.add(playerTransform.rightVector().mul(speed * -dt)); // TODO getLeftVector
    }
    if (state.getRight()) {
      motion = motion.add(playerTransform.rightVector().mul(speed * dt));
    }
    if (state.getJump()) {
      motion = motion.add(playerTransform.upVector().mul(speed * dt));
    }
    if (state.getCrouch()) {
      motion = motion.add(playerTransform.upVector().mul(speed * -dt));
    }

    client
        .getPlayer()
        .getPhysics()
        .setRotation(
            Quaternionf.fromAxesAnglesDeg(
                state.pitch(),
                state.yaw(),
                playerTransform.getRotation().getAxesAngleDeg().getZ()));

    if (!motion.equals(Vector3f.ZERO)) {
      client.getPlayer().getPhysics().translate(motion);
    }
  }