mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-05 16:37:38 +07:00
Added preview projection
This commit is contained in:
parent
b9dd6cc4b5
commit
01e7397df5
@ -3,6 +3,7 @@ package mindustry.graphics;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.VertexAttributes.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.graphics.g3d.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
@ -13,6 +14,7 @@ public class PlanetMesh{
|
||||
private float[] floats = new float[3 + 3 + 1];
|
||||
private Vec3 center = new Vec3(0, 0, 0);
|
||||
private Vec3 vec = new Vec3();
|
||||
private Plane plane = new Plane();
|
||||
private Mesh mesh;
|
||||
private PlanetGrid grid;
|
||||
|
||||
@ -51,22 +53,25 @@ public class PlanetMesh{
|
||||
Shaders.planet.end();
|
||||
}
|
||||
|
||||
public void projectTile(Ptile tile){
|
||||
/** Projects a tile onto a 4-corner square for use in map gen.
|
||||
* Allocates a new object. Do not call in the main loop. */
|
||||
public SectorRect 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);
|
||||
Vec3 center = Tmp.v33.scl(1f / tile.corners.length).cpy(vec);
|
||||
//radius of circle
|
||||
float radius = Tmp.v33.dst(tile.corners[0].v);
|
||||
|
||||
//target 'up' vector
|
||||
Vec3 target = Tmp.v33.cpy().add(0f, 1f, 0f);
|
||||
float radius = Tmp.v33.dst(tile.corners[0].v) * 0.9f;
|
||||
|
||||
//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);
|
||||
|
||||
Vec3 planeTop = plane.project(center.cpy().add(0f, 1f, 0f)).sub(center).setLength(radius).add(center);
|
||||
Vec3 planeRight = plane.project(center.cpy().rotate(Vec3.Y, 4f)).sub(center).setLength(radius).add(center);
|
||||
|
||||
return new SectorRect(center, planeTop.sub(center), planeRight.sub(center));
|
||||
}
|
||||
|
||||
public @Nullable Ptile getTile(Ray ray){
|
||||
@ -162,4 +167,22 @@ public class PlanetMesh{
|
||||
floats[6] = color.toFloatBits();
|
||||
mesh.getVerticesBuffer().put(floats);
|
||||
}
|
||||
|
||||
public static class SectorRect{
|
||||
public final Vec3 center, top, right;
|
||||
public final Vec3 result = new Vec3();
|
||||
|
||||
public SectorRect(Vec3 center, Vec3 top, Vec3 right){
|
||||
this.center = center;
|
||||
this.top = top;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
/** Project a coordinate into 3D space.
|
||||
* Both coordinates should be normalized to floats of the value 0..1 */
|
||||
public Vec3 project(float x, float y){
|
||||
float nx = (x - 0.5f) * 2f, ny = (y - 0.5f) * 2f;
|
||||
return result.set(center).add(right, nx).add(top, ny);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,14 @@ import arc.input.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.graphics.PlanetGrid.*;
|
||||
import mindustry.graphics.PlanetMesh.*;
|
||||
import mindustry.maps.planet.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public class PlanetRenderer implements PlanetGenerator{
|
||||
private final Color outlineColor = Pal.accent.cpy().a(0.7f);
|
||||
private final float camLength = 4f, outlineRad = 1.2f;
|
||||
private final boolean drawnRect = true;
|
||||
|
||||
private final PlanetMesh[] outlines = new PlanetMesh[10];
|
||||
private final Camera3D cam = new Camera3D();
|
||||
@ -50,6 +52,20 @@ public class PlanetRenderer implements PlanetGenerator{
|
||||
batch.vertex(tile.corners[i].v);
|
||||
}
|
||||
batch.flush(cam.combined(), Gl.triangleFan);
|
||||
|
||||
if(drawnRect){
|
||||
SectorRect rect = outline.projectTile(tile);
|
||||
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(0, 0));
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(1, 0));
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(1, 1));
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(0, 1));
|
||||
batch.flush(cam.combined(), Gl.lineLoop);
|
||||
}
|
||||
}
|
||||
|
||||
Gl.disable(Gl.depthTest);
|
||||
|
Loading…
Reference in New Issue
Block a user