Added prototype planet sector land system
This commit is contained in:
@@ -55,21 +55,26 @@ public class PlanetMesh{
|
||||
|
||||
/** 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){
|
||||
public SectorRect projectTile(Ptile base){
|
||||
Vec3[] corners = new Vec3[base.corners.length];
|
||||
for(int i = 0; i < corners.length; i++){
|
||||
corners[i] = base.corners[i].v.cpy().setLength(radius);
|
||||
}
|
||||
|
||||
Tmp.v33.setZero();
|
||||
for(Corner c : tile.corners){
|
||||
Tmp.v33.add(c.v);
|
||||
for(Vec3 c : corners){
|
||||
Tmp.v33.add(c);
|
||||
}
|
||||
//v33 is now the center of this shape
|
||||
Vec3 center = Tmp.v33.scl(1f / tile.corners.length).cpy(vec);
|
||||
Vec3 center = Tmp.v33.scl(1f / corners.length).cpy(vec);
|
||||
//radius of circle
|
||||
float radius = Tmp.v33.dst(tile.corners[0].v) * 0.9f;
|
||||
float radius = Tmp.v33.dst(corners[0]) * 0.9f;
|
||||
|
||||
//get plane that these points are on
|
||||
plane.set(tile.corners[0].v, tile.corners[2].v, tile.corners[4].v);
|
||||
plane.set(corners[0], corners[2], corners[4]);
|
||||
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -7,10 +7,18 @@ import arc.graphics.g3d.*;
|
||||
import arc.input.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.graphics.PlanetGrid.*;
|
||||
import mindustry.graphics.PlanetMesh.*;
|
||||
import mindustry.maps.generators.*;
|
||||
import mindustry.maps.planet.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class PlanetRenderer implements PlanetGenerator{
|
||||
private final Color outlineColor = Pal.accent.cpy().a(0.7f);
|
||||
@@ -54,7 +62,10 @@ public class PlanetRenderer implements PlanetGenerator{
|
||||
batch.flush(cam.combined(), Gl.triangleFan);
|
||||
|
||||
if(drawnRect){
|
||||
SectorRect rect = outline.projectTile(tile);
|
||||
SectorRect rect = planet.mesh.projectTile(tile);
|
||||
rect.center.scl(outlineRad);
|
||||
rect.right.scl(outlineRad);
|
||||
rect.top.scl(outlineRad);
|
||||
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(0, 0));
|
||||
@@ -65,6 +76,30 @@ public class PlanetRenderer implements PlanetGenerator{
|
||||
batch.color(Pal.place);
|
||||
batch.vertex(rect.project(0, 1));
|
||||
batch.flush(cam.combined(), Gl.lineLoop);
|
||||
|
||||
SectorRect coords = planet.mesh.projectTile(tile);
|
||||
|
||||
if(Core.input.keyTap(KeyCode.SPACE)){
|
||||
logic.reset();
|
||||
Vars.world.loadGenerator(new Generator(250, 250){
|
||||
@Override
|
||||
public void generate(Tiles tiles){
|
||||
TileGen gen = new TileGen();
|
||||
tiles.each((x, y) -> {
|
||||
gen.reset();
|
||||
Vec3 position = coords.project(x / (float)width, y / (float)height);
|
||||
|
||||
planet.generator.generate(position, gen);
|
||||
tiles.set(x, y, new Tile(x, y, gen.floor, gen.overlay, gen.block));
|
||||
});
|
||||
|
||||
tiles.get(width/2, height/2).setBlock(Blocks.coreShard, Team.sharded);
|
||||
}
|
||||
});
|
||||
state.set(State.playing);
|
||||
logic.play();
|
||||
ui.planet.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,4 +132,9 @@ public class PlanetRenderer implements PlanetGenerator{
|
||||
public Color getColor(Vec3 position){
|
||||
return outlineColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Vec3 position, TileGen tile){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user