Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.warlox;
- import com.badlogic.gdx.files.FileHandle;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.Pixmap;
- public class Heightmap {
- public final int width;
- public final int height;
- public final float[] elevations;
- public Heightmap (FileHandle file) {
- Pixmap pixmap = new Pixmap(file);
- width = pixmap.getWidth();
- height = pixmap.getHeight();
- elevations = new float[width * height];
- Color color = new Color();
- int i = 0;
- for (int y = 0; y < width; y++) {
- for (int x = 0; x < height; x++) {
- int pixel = pixmap.getPixel(x, y);
- Color.rgba8888ToColor(color, pixel);
- elevations[i] = color.r;
- i++;
- }
- }
- }
- public int index(int x, int y) {
- y = height - 1 - y;
- return y * width + x;
- }
- public float elevation(int x, int y) {
- return elevations[index(x, y)];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement