Использование шума Perlin для создания 2D -плитки картыJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Использование шума Perlin для создания 2D -плитки карты

Сообщение Anonymous »

Я посмотрел по всему Интернету и исследовал «Перлин», однако я все еще запутался. < /p>

Я использую Java и libgdx < /strong>. У меня есть класс Перлина для работы и создавать шум, но я не уверен, что значения его дают правильными. Как я могу проверить его на самом деле, выводит шум в Perlin? Как я бы сопоставлял «Шум Перлина» на плитки? В настоящее время у меня есть 4 базовые плитки; Вода, песок, камень и трава. < /p>

package com.bracco.thrive.world;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
public class WorldGeneration {

Perlin noise = new Perlin();
private SpriteBatch spriteBatch;
//private boolean debug = false;
private TextureRegion[] regions = new TextureRegion[4];
private Texture texture;

float x = 110;
float y = 120;
float originX = 0;
float originY = 16;
float width = 16;
float height = 16;
float scaleX = 1;
float scaleY = 1;
float rotation = 1;

@SuppressWarnings("static-access")
public void createWorld(){
spriteBatch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("assets/data/textures/basictextures.png"));

regions[0] = new TextureRegion(texture,0,0,16,16); //grass
regions[1] = new TextureRegion(texture,16,0,16,16); //water
regions[2] = new TextureRegion(texture,0,17,16,16); //sand
regions[3] = new TextureRegion(texture,17,17,16,16); //rock
float[][] seed = noise.GenerateWhiteNoise(50, 50);
for (int i = 0;i < seed.length; i++){
for ( int j = 0; j < seed.length; j++){
System.out.println(seed[j] + " ");
}
}
float[][] seedE = noise.GenerateSmoothNoise( seed, 6);
for (int i = 0;i < seedE.length; i++){
for ( int j = 0; j < seedE.length; j++){
System.out.println(seedE[j] + " ");
}

}
float[][] perlinNoise = noise.GeneratePerlinNoise(seedE, 8);
for (int i = 0;i < perlinNoise.length; i++){
for ( int j = 0; j < perlinNoise.length; j++){
System.out.println(perlinNoise[j] + " ");
}
}
}

public void render(){
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
spriteBatch.begin();
//spriteBatch.draw(texture, 0, 0, 16, 16);
for (int i = 0; i < regions.length; i++){
spriteBatch.draw(regions,75 * (i + 1),100);
}
spriteBatch.end();
}

}
< /code>

< /p>

package com.bracco.thrive.world;

import java.util.Random;

public class Perlin {

public static float[][] GenerateWhiteNoise(int width,int height){

Random random = new Random((long) (Math.round(Math.random() * 100 * Math.random() * 10))); //Seed to 0 for testing
float[][] noise = new float[width][height];

for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++){
noise[j] = (float)(Math.random() % 1);
}
}

return noise;
}

float[][] GenerateSmoothNoise(float[][] baseNoise, int octave)
{
int width = baseNoise.length;
int height = baseNoise.length;

float[][] smoothNoise = new float[width][height];

int samplePeriod = 1 = 0; octave--)
{
amplitude *= persistance;
totalAmplitude += amplitude;

for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
perlinNoise[j] += smoothNoise[octave][j] * amplitude;
}
}
}

//normalisation
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
perlinNoise[i][j] /= totalAmplitude;
}
}

return perlinNoise;
}
}


Подробнее здесь: https://stackoverflow.com/questions/174 ... d-tile-map
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»