Cleanup
This commit is contained in:
@@ -12,17 +12,24 @@ import mindustry.maps.planet.*;
|
|||||||
public class PlanetMesh{
|
public class PlanetMesh{
|
||||||
private float[] floats = new float[3 + 3 + 1];
|
private float[] floats = new float[3 + 3 + 1];
|
||||||
private Vec3 center = new Vec3(0, 0, 0);
|
private Vec3 center = new Vec3(0, 0, 0);
|
||||||
|
private Vec3 vec = new Vec3();
|
||||||
private Mesh mesh;
|
private Mesh mesh;
|
||||||
private PlanetGrid grid;
|
private PlanetGrid grid;
|
||||||
|
|
||||||
private boolean lines = false;
|
private boolean lines;
|
||||||
private float radius = 1f, intensity = 0.2f;
|
private float radius, intensity = 0.2f;
|
||||||
|
|
||||||
private final PlanetGenerator gen;
|
private final PlanetGenerator gen;
|
||||||
|
|
||||||
public PlanetMesh(int divisions, PlanetGenerator gen){
|
public PlanetMesh(int divisions, PlanetGenerator gen){
|
||||||
|
this(divisions, gen, 1f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlanetMesh(int divisions, PlanetGenerator gen, float radius, boolean lines){
|
||||||
this.gen = gen;
|
this.gen = gen;
|
||||||
|
this.radius = radius;
|
||||||
this.grid = PlanetGrid.newGrid(divisions);
|
this.grid = PlanetGrid.newGrid(divisions);
|
||||||
|
this.lines = lines;
|
||||||
|
|
||||||
int vertices = grid.tiles.length * 12 * (3 + 3 + 1);
|
int vertices = grid.tiles.length * 12 * (3 + 3 + 1);
|
||||||
|
|
||||||
@@ -44,6 +51,24 @@ public class PlanetMesh{
|
|||||||
Shaders.planet.end();
|
Shaders.planet.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void projectTile(Ptile tile){
|
||||||
|
Tmp.v33.setZero();
|
||||||
|
for(Corner c : tile.corners){
|
||||||
|
Tmp.v33.add(c.v);
|
||||||
|
}
|
||||||
|
//v33 is now the center of this shape
|
||||||
|
Tmp.v33.scl(1f / tile.corners.length);
|
||||||
|
//radius of circle
|
||||||
|
float radius = Tmp.v33.dst(tile.corners[0].v);
|
||||||
|
|
||||||
|
//target 'up' vector
|
||||||
|
Vec3 target = Tmp.v33.cpy().add(0f, 1f, 0f);
|
||||||
|
|
||||||
|
//get plane that these points are on
|
||||||
|
Plane plane = new Plane();
|
||||||
|
plane.set(tile.corners[0].v, tile.corners[2].v, tile.corners[4].v);
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable Ptile getTile(Ray ray){
|
public @Nullable Ptile getTile(Ray ray){
|
||||||
Vec3 vec = intersect(ray);
|
Vec3 vec = intersect(ray);
|
||||||
if(vec == null) return null;
|
if(vec == null) return null;
|
||||||
@@ -66,7 +91,7 @@ public class PlanetMesh{
|
|||||||
Corner[] c = tile.corners;
|
Corner[] c = tile.corners;
|
||||||
|
|
||||||
for(Corner corner : c){
|
for(Corner corner : c){
|
||||||
corner.bv.set(corner.v).setLength(radius);;
|
corner.bv.set(corner.v).setLength(radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Corner corner : c){
|
for(Corner corner : c){
|
||||||
@@ -112,11 +137,11 @@ public class PlanetMesh{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private float elevation(Vec3 v){
|
private float elevation(Vec3 v){
|
||||||
return gen.getHeight(v);
|
return gen.getHeight(vec.set(v).scl(1f / radius));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color color(Vec3 v){
|
private Color color(Vec3 v){
|
||||||
return gen.getColor(v);
|
return gen.getColor(vec.set(v).scl(1f / radius));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verts(Vec3 a, Vec3 b, Vec3 c, Vec3 normal, Color color){
|
private void verts(Vec3 a, Vec3 b, Vec3 c, Vec3 normal, Color color){
|
||||||
|
|||||||
@@ -7,15 +7,19 @@ import arc.graphics.g3d.*;
|
|||||||
import arc.input.*;
|
import arc.input.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import mindustry.graphics.PlanetGrid.*;
|
||||||
|
import mindustry.maps.planet.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
|
|
||||||
public class PlanetRenderer{
|
public class PlanetRenderer implements PlanetGenerator{
|
||||||
private Camera3D cam = new Camera3D();
|
private final Color outlineColor = Pal.accent.cpy().a(0.7f);
|
||||||
private float lastX, lastY, camLength = 4f;
|
private final float camLength = 4f, outlineRad = 1.2f;
|
||||||
|
|
||||||
//private PlanetMesh planet = new PlanetMesh(6, 1f, false, Color.royal);
|
private final PlanetMesh[] outlines = new PlanetMesh[10];
|
||||||
//private PlanetMesh outline = new PlanetMesh(3, 1.3f, true, Pal.accent);
|
private final Camera3D cam = new Camera3D();
|
||||||
private VertexBatch3D batch = new VertexBatch3D(false, true, 0);
|
private final VertexBatch3D batch = new VertexBatch3D(false, true, 0);
|
||||||
|
|
||||||
|
private float lastX, lastY;
|
||||||
|
|
||||||
public PlanetRenderer(){
|
public PlanetRenderer(){
|
||||||
Tmp.v1.trns(0, camLength);
|
Tmp.v1.trns(0, camLength);
|
||||||
@@ -34,24 +38,31 @@ public class PlanetRenderer{
|
|||||||
cam.lookAt(0, 0, 0);
|
cam.lookAt(0, 0, 0);
|
||||||
cam.update();
|
cam.update();
|
||||||
|
|
||||||
|
PlanetMesh outline = outline(planet.size);
|
||||||
|
|
||||||
planet.mesh.render(cam.combined());
|
planet.mesh.render(cam.combined());
|
||||||
//outline.render(cam.combined());
|
outline.render(cam.combined());
|
||||||
|
|
||||||
//TODO
|
|
||||||
/*
|
|
||||||
Ptile tile = outline.getTile(cam.getPickRay(Core.input.mouseX(), Core.input.mouseY()));
|
Ptile tile = outline.getTile(cam.getPickRay(Core.input.mouseX(), Core.input.mouseY()));
|
||||||
if(tile != null){
|
if(tile != null){
|
||||||
for(int i = 0; i < tile.corners.length; i++){
|
for(int i = 0; i < tile.corners.length; i++){
|
||||||
batch.color(1f, 1f, 1f, 0.5f);
|
batch.color(outlineColor);
|
||||||
batch.vertex(tile.corners[i].v);
|
batch.vertex(tile.corners[i].v);
|
||||||
}
|
}
|
||||||
batch.flush(cam.combined(), Gl.triangleFan);
|
batch.flush(cam.combined(), Gl.triangleFan);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
Gl.disable(Gl.depthTest);
|
Gl.disable(Gl.depthTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void input(){
|
private PlanetMesh outline(int size){
|
||||||
|
if(outlines[size] == null){
|
||||||
|
outlines[size] = new PlanetMesh(size, this, outlineRad, true);
|
||||||
|
}
|
||||||
|
return outlines[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
private void input(){
|
||||||
Vec3 v = Tmp.v33.set(Core.input.mouseX(), Core.input.mouseY(), 0);
|
Vec3 v = Tmp.v33.set(Core.input.mouseX(), Core.input.mouseY(), 0);
|
||||||
|
|
||||||
if(Core.input.keyDown(KeyCode.MOUSE_LEFT)){
|
if(Core.input.keyDown(KeyCode.MOUSE_LEFT)){
|
||||||
@@ -60,4 +71,14 @@ public class PlanetRenderer{
|
|||||||
lastX = v.x;
|
lastX = v.x;
|
||||||
lastY = v.y;
|
lastY = v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getHeight(Vec3 position){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Color getColor(Vec3 position){
|
||||||
|
return outlineColor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ import arc.math.geom.*;
|
|||||||
public interface PlanetGenerator{
|
public interface PlanetGenerator{
|
||||||
float getHeight(Vec3 position);
|
float getHeight(Vec3 position);
|
||||||
Color getColor(Vec3 position);
|
Color getColor(Vec3 position);
|
||||||
|
//void generate(Vec3 position, Tile tile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class Planet extends UnlockableContent{
|
|||||||
public @NonNull PlanetGrid grid;
|
public @NonNull PlanetGrid grid;
|
||||||
/** Generator that will make the planet. */
|
/** Generator that will make the planet. */
|
||||||
public @NonNull PlanetGenerator generator;
|
public @NonNull PlanetGenerator generator;
|
||||||
/** Detail in divisions. Must be between 1 and 10. 6 is a good number.*/
|
/** Detail in divisions. Must be between 1 and 10. 6 is a good number for this.*/
|
||||||
public int detail = 3;
|
public int detail = 3;
|
||||||
/** Size in terms of divisions. This only controls the amount of sectors on the planet, not the visuals. */
|
/** Size in terms of divisions. This only controls the amount of sectors on the planet, not the visuals. */
|
||||||
public int size = 3;
|
public int size = 3;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=ec97ef07c9e241dbc26ef5b5a83ff87a2e40b11a
|
archash=43de3406deffdbeca22a2ff320362cd0129e2da6
|
||||||
|
|||||||
Reference in New Issue
Block a user