Advertisement
Guest User

Untitled

a guest
Apr 9th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package com.warlox;
  2. import com.badlogic.gdx.files.FileHandle;
  3. import com.badlogic.gdx.graphics.Color;
  4. import com.badlogic.gdx.graphics.Pixmap;
  5. public class Heightmap {
  6.     public final int width;
  7.     public final int height;
  8.     public final float[] elevations;
  9.     public Heightmap (FileHandle file) {
  10.         Pixmap pixmap = new Pixmap(file);
  11.         width = pixmap.getWidth();
  12.         height = pixmap.getHeight();
  13.         elevations = new float[width * height];
  14.         Color color = new Color();
  15.         int i = 0;
  16.         for (int y = 0; y < width; y++) {
  17.             for (int x = 0; x < height; x++) {
  18.                 int pixel = pixmap.getPixel(x, y);
  19.                 Color.rgba8888ToColor(color, pixel);
  20.                 elevations[i] = color.r;
  21.                 i++;
  22.             }
  23.         }
  24.     }
  25.     public int index(int x, int y) {
  26.         y = height - 1 - y;
  27.         return y * width + x;
  28.     }
  29.     public float elevation(int x, int y) {
  30.         return elevations[index(x, y)];
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement