Exemple #1
0
  /** Raytrace one frame. */
  private void raytrace() {

    double aspect = width / (double) height;

    Ray ray = new Ray();

    camPos.set(0, -distance, 0);
    transform.transform(camPos);
    camPos.add(.5, .5, .5);

    for (int x = 0; x < width; ++x) {

      double rayx = fovTan * aspect * (.5 - ((double) x) / width);

      for (int y = 0; y < height; ++y) {

        ray.setDefault();
        ray.d.set(rayx, 1, fovTan * (.5 - ((double) y) / height));
        ray.d.normalize();
        transform.transform(ray.d);

        ray.o.set(camPos);
        raytrace(ray);

        ray.color.x = QuickMath.min(1, FastMath.sqrt(ray.color.x));
        ray.color.y = QuickMath.min(1, FastMath.sqrt(ray.color.y));
        ray.color.z = QuickMath.min(1, FastMath.sqrt(ray.color.z));
        backBuffer.setRGB(x, y, Color.getRGB(ray.color));
      }
    }
  }
Exemple #2
0
  /**
   * Render the minimap
   *
   * @param world
   * @param renderBuffer
   * @param selection
   */
  public void renderMinimap(
      World world, RenderBuffer renderBuffer, ChunkSelectionTracker selection) {

    ChunkView view = renderBuffer.getView();
    int width = view.width;
    int height = view.height;
    Graphics g = renderBuffer.getGraphics();

    if (world.isEmptyWorld()) {
      renderEmpty(g, width, height);
      return;
    }

    g.setColor(Color.white);
    g.fillRect(0, 0, width, height);

    float[] selectionColor = new float[4];
    float[] color = new float[4];
    se.llbit.math.Color.getRGBAComponents(Layer.selectionColor, selectionColor);
    for (int y = 0; y < height; y++) {
      int cz = y + view.iz0;
      for (int x = 0; x < width; x++) {
        int cx = x + view.ix0;
        ChunkPosition pos = ChunkPosition.get(cx, cz);
        Chunk chunk = world.getChunk(pos);
        if (!chunk.isEmpty()) {
          if (selection.isSelected(pos)) {
            se.llbit.math.Color.getRGBComponents(chunk.avgColor(), color);
            color[0] = color[0] * (1 - selectionColor[3]) + selectionColor[0] * selectionColor[3];
            color[1] = color[1] * (1 - selectionColor[3]) + selectionColor[1] * selectionColor[3];
            color[2] = color[2] * (1 - selectionColor[3]) + selectionColor[2] * selectionColor[3];
            color[3] = 1;
            renderBuffer.setRGB(x, y, se.llbit.math.Color.getRGB(color));
          } else {
            renderBuffer.setRGB(x, y, chunk.avgColor());
          }
        }
      }
    }

    if (world.havePlayerPos()) renderPlayer(world, g, view, true);

    if (world.haveSpawnPos()) renderSpawn(world, g, view, true);
  }