Planet cleanup

This commit is contained in:
Anuken
2020-01-18 17:03:03 -05:00
parent 47695f1f8c
commit b2f9b2ef77
6 changed files with 59 additions and 40 deletions

View File

@@ -1,37 +1,9 @@
package mindustry.maps.planet;
import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.noise.*;
public class PlanetGenerator{
Pixmap pix = new Pixmap("planets/colors.png");
Simplex noise = new Simplex();
int waterLevel = 5;
float water = waterLevel / (float)(pix.getHeight());
float scl = 5f;
public float getHeight(Vec3 position){
position = Tmp.v33.set(position).scl(scl);
float height = Mathf.pow((float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y, position.z), 2.4f);
if(height <= water){
return water;
}
return height;
}
public Color getColor(Vec3 position, float height){
position = Tmp.v33.set(position).scl(scl);
float rad = scl;
float temp = Mathf.clamp(Math.abs(position.y * 2f) / (rad));
float tnoise = (float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y + 999f, position.z);
temp = Mathf.lerp(temp, tnoise, 0.5f);
height *= 1.2f;
height = Mathf.clamp(height);
return Tmp.c1.set(pix.getPixel((int)(temp * (pix.getWidth()-1)), (int)((1f-height) * (pix.getHeight()-1))));
}
public interface PlanetGenerator{
float getHeight(Vec3 position);
Color getColor(Vec3 position);
}

View File

@@ -0,0 +1,40 @@
package mindustry.maps.planet;
import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.noise.*;
public class TestPlanetGenerator implements PlanetGenerator{
Pixmap pix = new Pixmap("planets/colors.png");
Simplex noise = new Simplex();
int waterLevel = 5;
float water = waterLevel / (float)(pix.getHeight());
float scl = 5f;
@Override
public float getHeight(Vec3 position){
position = Tmp.v33.set(position).scl(scl);
float height = Mathf.pow((float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y, position.z), 2.4f);
if(height <= water){
return water;
}
return height;
}
@Override
public Color getColor(Vec3 position){
float height = getHeight(position);
position = Tmp.v33.set(position).scl(scl);
float rad = scl;
float temp = Mathf.clamp(Math.abs(position.y * 2f) / (rad));
float tnoise = (float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y + 999f, position.z);
temp = Mathf.lerp(temp, tnoise, 0.5f);
height *= 1.2f;
height = Mathf.clamp(height);
return Tmp.c1.set(pix.getPixel((int)(temp * (pix.getWidth()-1)), (int)((1f-height) * (pix.getHeight()-1))));
}
}