Added plane batch
This commit is contained in:
@@ -12,6 +12,7 @@ import mindustry.world.*;
|
||||
/** A small section of a planet. */
|
||||
public class Sector{
|
||||
public final SectorRect rect;
|
||||
public final Plane plane;
|
||||
public final Planet planet;
|
||||
public final Ptile tile;
|
||||
public final int id;
|
||||
@@ -23,6 +24,7 @@ public class Sector{
|
||||
public Sector(Planet planet, Ptile tile, SectorData data){
|
||||
this.planet = planet;
|
||||
this.tile = tile;
|
||||
this.plane = new Plane();
|
||||
this.rect = makeRect();
|
||||
this.id = tile.id;
|
||||
this.data = data;
|
||||
@@ -56,7 +58,6 @@ public class Sector{
|
||||
float radius = Tmp.v33.dst(corners[0]) * 0.98f;
|
||||
|
||||
//get plane that these points are on
|
||||
Plane plane = new Plane();
|
||||
plane.set(corners[0], corners[2], corners[4]);
|
||||
|
||||
//relative vectors
|
||||
|
||||
@@ -7,13 +7,14 @@ import arc.graphics.g3d.*;
|
||||
import arc.input.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.event.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.PlanetGrid.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.type.Sector.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
@@ -26,9 +27,12 @@ public class PlanetDialog extends FloatingDialog{
|
||||
private final PlanetMesh[] outlines = new PlanetMesh[10];
|
||||
private final Camera3D cam = new Camera3D();
|
||||
private final VertexBatch3D batch = new VertexBatch3D(false, true, 0);
|
||||
private final PlaneBatch3D projector = new PlaneBatch3D();
|
||||
|
||||
private Planet planet = Planets.starter;
|
||||
private float lastX, lastY;
|
||||
private Sector selected;
|
||||
private Sector selected, hovered;
|
||||
private Table selectTable;
|
||||
|
||||
public PlanetDialog(){
|
||||
super("", Styles.fullDialog);
|
||||
@@ -38,8 +42,11 @@ public class PlanetDialog extends FloatingDialog{
|
||||
|
||||
Tmp.v1.trns(0, camLength);
|
||||
cam.position.set(Tmp.v1.x, 0f, Tmp.v1.y);
|
||||
projector.setScaling(1f / 300f);
|
||||
|
||||
update(() -> {
|
||||
Ptile tile = outline(planet.size).getTile(cam.getPickRay(Core.input.mouseX(), Core.input.mouseY()));
|
||||
hovered = tile == null ? null : planet.getSector(tile);
|
||||
|
||||
Vec3 v = Tmp.v33.set(Core.input.mouseX(), Core.input.mouseY(), 0);
|
||||
|
||||
@@ -64,6 +71,23 @@ public class PlanetDialog extends FloatingDialog{
|
||||
lastY = v.y;
|
||||
});
|
||||
|
||||
addListener(new ElementGestureListener(){
|
||||
@Override
|
||||
public void tap(InputEvent event, float x, float y, int count, KeyCode button){
|
||||
selected = hovered;
|
||||
}
|
||||
});
|
||||
|
||||
selectTable = new Table(t -> {
|
||||
t.background(Tex.button);
|
||||
t.margin(12f);
|
||||
t.add("this is some arbitrary text.");
|
||||
});
|
||||
|
||||
selectTable.act(1f);
|
||||
selectTable.pack();
|
||||
selectTable.setPosition(0, 0, Align.center);
|
||||
|
||||
shown(this::setup);
|
||||
}
|
||||
|
||||
@@ -72,11 +96,11 @@ public class PlanetDialog extends FloatingDialog{
|
||||
titleTable.remove();
|
||||
|
||||
cont.addRect((x, y, w, h) -> {
|
||||
render(Planets.starter);
|
||||
render();
|
||||
}).grow();
|
||||
}
|
||||
|
||||
private void render(Planet planet){
|
||||
private void render(){
|
||||
Draw.flush();
|
||||
Gl.clear(Gl.depthBufferBit);
|
||||
Gl.enable(Gl.depthTest);
|
||||
@@ -85,68 +109,71 @@ public class PlanetDialog extends FloatingDialog{
|
||||
cam.up.set(Vec3.Y);
|
||||
|
||||
cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||
cam.update();
|
||||
cam.lookAt(0, 0, 0);
|
||||
cam.update();
|
||||
|
||||
batch.proj(cam.combined());
|
||||
|
||||
PlanetMesh outline = outline(planet.size);
|
||||
|
||||
planet.mesh.render(cam.combined());
|
||||
outline.render(cam.combined());
|
||||
|
||||
//dftactgrp sqlrpgle
|
||||
Ptile tile = outline.getTile(cam.getPickRay(Core.input.mouseX(), Core.input.mouseY()));
|
||||
if(tile != null){
|
||||
float length = 0.1f;
|
||||
if(hovered != null){
|
||||
drawHover(hovered);
|
||||
|
||||
Sector sector = planet.getSector(tile);
|
||||
for(int i = 0; i < sector.tile.corners.length; i++){
|
||||
Corner next = sector.tile.corners[(i + 1) % sector.tile.corners.length];
|
||||
Corner curr = sector.tile.corners[i];
|
||||
sector.tile.v.scl(outlineRad);
|
||||
Tmp.v31.set(curr.v).sub(sector.tile.v).setLength(length).add(sector.tile.v);
|
||||
Tmp.v32.set(next.v).sub(sector.tile.v).setLength(length).add(sector.tile.v);
|
||||
sector.tile.v.scl(1f / outlineRad);
|
||||
//if(Core.input.keyTap(KeyCode.SPACE)){
|
||||
// control.playSector(hovered);
|
||||
// ui.planet.hide();
|
||||
//}
|
||||
}
|
||||
|
||||
batch.tri(curr.v, next.v, Tmp.v31, Pal.accent);
|
||||
batch.tri(Tmp.v31, Tmp.v32, next.v, Pal.accent);
|
||||
}
|
||||
batch.flush(cam.combined(), Gl.triangles);
|
||||
if(selected != null){
|
||||
drawSelection(selected);
|
||||
|
||||
if(drawRect){
|
||||
SectorRect rect = sector.rect;
|
||||
rect.center.scl(outlineRad);
|
||||
rect.right.scl(outlineRad);
|
||||
rect.top.scl(outlineRad);
|
||||
|
||||
batch.color(Color.red);
|
||||
batch.vertex(rect.center);
|
||||
batch.color(Color.red);
|
||||
batch.vertex(sector.tile.corners[0].v);
|
||||
|
||||
batch.color(Color.green);
|
||||
batch.vertex(rect.center);
|
||||
batch.color(Color.green);
|
||||
batch.vertex(rect.top.cpy().add(rect.center));
|
||||
batch.flush(cam.combined(), Gl.lines);
|
||||
|
||||
//Log.info((int)(sector.tile.corners[0].v.cpy().sub(rect.center).angle(rect.top)));
|
||||
|
||||
rect.center.scl(1f / outlineRad);
|
||||
rect.right.scl(1f / outlineRad);
|
||||
rect.top.scl(1f / outlineRad);
|
||||
}
|
||||
|
||||
if(Core.input.keyTap(KeyCode.SPACE)){
|
||||
control.playSector(sector);
|
||||
ui.planet.hide();
|
||||
}
|
||||
projector.proj(cam.combined());
|
||||
projector.setPlane(
|
||||
//origin on sector position
|
||||
Tmp.v33.set(selected.tile.v).setLength(outlineRad + 0.05f),
|
||||
//face up
|
||||
selected.plane.project(Tmp.v32.set(selected.tile.v).add(Vec3.Y)).sub(selected.tile.v).nor(),
|
||||
//right vector
|
||||
Tmp.v31.set(Tmp.v32).add(selected.tile.v).rotate(selected.tile.v, 90).sub(selected.tile.v).nor()
|
||||
);
|
||||
|
||||
Draw.batch(projector, () -> {
|
||||
selectTable.draw();
|
||||
});
|
||||
}
|
||||
|
||||
Gl.disable(Gl.depthTest);
|
||||
}
|
||||
|
||||
private void drawHover(Sector sector){
|
||||
for(Corner c : sector.tile.corners){
|
||||
batch.color(outlineColor);
|
||||
batch.vertex(c.v);
|
||||
}
|
||||
batch.flush(Gl.triangleFan);
|
||||
}
|
||||
|
||||
private void drawSelection(Sector sector){
|
||||
float length = 0.1f;
|
||||
|
||||
for(int i = 0; i < sector.tile.corners.length; i++){
|
||||
Corner next = sector.tile.corners[(i + 1) % sector.tile.corners.length];
|
||||
Corner curr = sector.tile.corners[i];
|
||||
sector.tile.v.scl(outlineRad);
|
||||
Tmp.v31.set(curr.v).sub(sector.tile.v).setLength(length).add(sector.tile.v);
|
||||
Tmp.v32.set(next.v).sub(sector.tile.v).setLength(length).add(sector.tile.v);
|
||||
sector.tile.v.scl(1f / outlineRad);
|
||||
|
||||
batch.tri(curr.v, next.v, Tmp.v31, Pal.accent);
|
||||
batch.tri(Tmp.v31, Tmp.v32, next.v, Pal.accent);
|
||||
}
|
||||
batch.flush(Gl.triangles);
|
||||
}
|
||||
|
||||
private PlanetMesh outline(int size){
|
||||
if(outlines[size] == null){
|
||||
outlines[size] = new PlanetMesh(size, new PlanetMesher(){
|
||||
|
||||
Reference in New Issue
Block a user