Я посмотрел по всему Интернету и исследовал «Перлин», однако я все еще запутался. < /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
Использование шума Perlin для создания 2D -плитки карты ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1758316590
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[i].length; j++){
System.out.println(seed[i][j] + " ");
}
}
float[][] seedE = noise.GenerateSmoothNoise( seed, 6);
for (int i = 0;i < seedE.length; i++){
for ( int j = 0; j < seedE[i].length; j++){
System.out.println(seedE[i][j] + " ");
}
}
float[][] perlinNoise = noise.GeneratePerlinNoise(seedE, 8);
for (int i = 0;i < perlinNoise.length; i++){
for ( int j = 0; j < perlinNoise[i].length; j++){
System.out.println(perlinNoise[i][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[i],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[i][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[i][j] += smoothNoise[octave][i][j] * amplitude;
}
}
}
//normalisation
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
perlinNoise[i][j] /= totalAmplitude;
}
}
return perlinNoise;
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/17440865/using-perlin-noise-to-generate-a-2d-tile-map[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия