move Display in gui package

- and some code indentation
This commit is contained in:
philippe lhardy
2020-10-11 15:30:28 +02:00
parent 9ec3cf0d01
commit 0f1a15916c
8 changed files with 93 additions and 158 deletions

View File

@@ -12,18 +12,17 @@ import java.io.IOException;
/**
* Wall3d to create walls in 3d for stl conversion South, West North East...
**/
public class Wall3d
{
public class Wall3d {
// 4 triangles in 2 dim space reused 3 times
final static int BASE[][][] = { { { 0, 0 }, { 1, 0 }, { 0, 1 } }, { { 1, 0 }, { 1, 1 }, { 0, 1 } },
{ { 0, 0 }, { 1, 0 }, { 1, 1 } }, { { 0, 0 }, { 1, 1 }, { 0, 1 } } };
final static int BASE[][][] = {{{0, 0}, {1, 0}, {0, 1}}, {{1, 0}, {1, 1}, {0, 1}},
{{0, 0}, {1, 0}, {1, 1}}, {{0, 0}, {1, 1}, {0, 1}}};
final static short X = 1;
final static short Y = 2;
final static short Z = 4;
// final static short AXIS[][]= {{X,Y},{-Z,Y},{X,Y},{Z,Y},{X,-Z},{X,-Z}};
final static short AXIS[][] = { { X, Y, 0 }, { Z, Y, 0 }, { X, Y, 1 }, { Z, Y, 1 }, { X, Z, 0 }, { X, Z, 1 } };
final static short AXIS[][] = {{X, Y, 0}, {Z, Y, 0}, {X, Y, 1}, {Z, Y, 1}, {X, Z, 0}, {X, Z, 1}};
public final static Wall3d South = new Wall3d(10, 1, 10, 0, 0, 0);
public final static Wall3d West = new Wall3d(1, 10, 10, 0, 0, 0);
@@ -34,51 +33,37 @@ public class Wall3d
int triangle[][][] = null;
public Wall3d(int t[][][])
{
public Wall3d(int t[][][]) {
triangle = t;
}
public Wall3d(Wall3d origin, int dx, int dy, int dz)
{
public Wall3d(Wall3d origin, int dx, int dy, int dz) {
triangle = origin.translate(dx, dy, dz);
}
Wall3d(int xl, int yl, int zl, int dx, int dy, int dz)
{
Wall3d(int xl, int yl, int zl, int dx, int dy, int dz) {
int f = 0;
triangle = new int[12][3][3];
int[] factor = { xl, yl, zl };
int[] translate = { dx, dy, dz };
for (int i = 0; i < 12; i++)
{
int[] factor = {xl, yl, zl};
int[] translate = {dx, dy, dz};
for (int i = 0; i < 12; i++) {
// point in a triangle
for (int p = 0; p < 3; p++)
{
for (int p = 0; p < 3; p++) {
short uaxis = 0;
for (int axis = 0; axis < 2; axis++)
{
for (int axis = 0; axis < 2; axis++) {
short caxis = AXIS[i / 2][axis];
if (caxis > 0)
{
if (caxis > 0) {
f = 1;
}
else if (caxis < 0)
{
} else if (caxis < 0) {
f = -1;
caxis = (short) -caxis;
}
uaxis |= caxis;
if (caxis == X)
{
if (caxis == X) {
caxis = 0;
}
else if (caxis == Y)
{
} else if (caxis == Y) {
caxis = 1;
}
else
{
} else {
caxis = 2;
}
// if ( f == 0 )
@@ -89,16 +74,11 @@ public class Wall3d
// " , " + BASE[i%4][p][axis] );
triangle[i][p][caxis] = translate[caxis] + BASE[i % 4][p][axis] * f * factor[caxis];
}
if ((uaxis & X) == 0)
{
if ((uaxis & X) == 0) {
uaxis = 0;
}
else if ((uaxis & Y) == 0)
{
} else if ((uaxis & Y) == 0) {
uaxis = 1;
}
else
{
} else {
uaxis = 2;
}
triangle[i][p][uaxis] = translate[uaxis] + AXIS[i / 2][2] * factor[uaxis];
@@ -106,18 +86,14 @@ public class Wall3d
}
}
public int[][][] translate(int dx, int dy, int dz)
{
int[] translate = { dx, dy, dz };
public int[][][] translate(int dx, int dy, int dz) {
int[] translate = {dx, dy, dz};
int t[][][] = new int[12][3][3];
for (int i = 0; i < 12; i++)
{
for (int i = 0; i < 12; i++) {
// point in a triangle
for (int p = 0; p < 3; p++)
{
for (int axis = 0; axis < 3; axis++)
{
for (int p = 0; p < 3; p++) {
for (int axis = 0; axis < 3; axis++) {
t[i][p][axis] = translate[axis] + triangle[i][p][axis];
}
}
@@ -127,19 +103,15 @@ public class Wall3d
}
/**
write triangles as stl text
* write triangles as stl text
**/
public String toString()
{
public String toString() {
String s = "";
for (int t = 0; t < 12; t++)
{
for (int t = 0; t < 12; t++) {
s += "facet normal 0 0 0\nouter loop\n";
for (int p = 0; p < 3; p++)
{
for (int p = 0; p < 3; p++) {
s += "vertex";
for (int a = 0; a < 3; a++)
{
for (int a = 0; a < 3; a++) {
// s+=" t "+ t + " p " + p + " a " + a + "=" +
// triangle[t][p][a];
s += " " + triangle[t][p][a];
@@ -151,16 +123,14 @@ public class Wall3d
return s;
}
public static void prepare()
{
public static void prepare() {
System.out.println(South.toString());
System.out.println(East.toString());
System.out.println(North.toString());
System.out.println(West.toString());
}
public static void streamWallsOut(String name, LabyModel provider, OutputStream stream) throws IOException
{
public static void streamWallsOut(String name, LabyModel provider, OutputStream stream) throws IOException {
int width = provider.getWidth();
int height = provider.getHeight();
int xl = 10;
@@ -170,58 +140,47 @@ public class Wall3d
// WARNING DOWN - UP reversed ( in 2D Y is oriented to lower, in 3D it
// is to upper ).
stream.write(("solid " + name + "\n").getBytes());
for (int x = 0; x < width; x++)
{
for (int x = 0; x < width; x++) {
short walls = provider.getWalls(x, 0);
if ((walls & Brick.UP) != 0)
{
if ((walls & Brick.UP) != 0) {
stream.write(new Wall3d(South, x * xl, 0, 0).toString().getBytes());
}
if ((walls & Brick.LEFT) != 0)
{
if ((walls & Brick.LEFT) != 0) {
stream.write(new Wall3d(West, x * xl, 0, 0).toString().getBytes());
}
}
for (int y = 0; y < height; y++)
{
for (int y = 0; y < height; y++) {
short walls = provider.getWalls(0, y);
if ((walls & Brick.LEFT) != 0)
{
if ((walls & Brick.LEFT) != 0) {
stream.write(new Wall3d(West, 0, y * yl, 0).toString().getBytes());
}
for (int x = 0; x < width; x++)
{
for (int x = 0; x < width; x++) {
// south and east
walls = provider.getWalls(x, y);
if ((walls & Brick.DOWN) != 0)
{
if ((walls & Brick.DOWN) != 0) {
stream.write(new Wall3d(North, x * xl, y * yl, 0).toString().getBytes());
}
if ((walls & Brick.RIGHT) != 0)
{
if ((walls & Brick.RIGHT) != 0) {
stream.write(new Wall3d(East, x * xl, y * yl, 0).toString().getBytes());
}
short path = provider.getPath(x,y);
if ( ( path & LabyModel.SOLVED ) == LabyModel.SOLVED )
// if ( (walls & ( Brick.GOAL | Brick.ENTRY ) ) == 0 )
{
// if ( ( (x+y) % 2) == 0 )
short path = provider.getPath(x, y);
if ((path & LabyModel.SOLVED) == LabyModel.SOLVED)
// if ( (walls & ( Brick.GOAL | Brick.ENTRY ) ) == 0 )
{
// if ( ( (x+y) % 2) == 0 )
stream.write(new Wall3d(LowGround, x * xl, y * yl, 0).toString().getBytes());
}
else
{
stream.write(new Wall3d(HighGround, x * xl, y * yl, 0).toString().getBytes());
}
stream.write(new Wall3d(LowGround, x * xl, y * yl, 0).toString().getBytes());
} else {
stream.write(new Wall3d(HighGround, x * xl, y * yl, 0).toString().getBytes());
}
}
}
stream.write("endsolid wall\n\n".getBytes());
}
public static void main(String args[])
{
public static void main(String args[]) {
Scanner console = new Scanner(System.in);
int xl = console.nextInt();