minor changes (format + move class in stl package )
This commit is contained in:
@@ -10,14 +10,15 @@ a is 'H' or '.' or ' '
|
||||
bcd is 'H' or ' '
|
||||
|
||||
*/
|
||||
public class Brick {
|
||||
public class Brick
|
||||
{
|
||||
|
||||
public final static short LEFT=1;
|
||||
public final static short DOWN=2;
|
||||
public final static short RIGHT=4;
|
||||
public final static short UP=8;
|
||||
public final static short ENTRY=16;
|
||||
public final static short GOAL=32;
|
||||
public final static short LEFT = 1;
|
||||
public final static short DOWN = 2;
|
||||
public final static short RIGHT = 4;
|
||||
public final static short UP = 8;
|
||||
public final static short ENTRY = 16;
|
||||
public final static short GOAL = 32;
|
||||
|
||||
char a;
|
||||
char b;
|
||||
@@ -25,98 +26,88 @@ public class Brick {
|
||||
char d;
|
||||
short walls; // according to LabyModel.getWalls();
|
||||
|
||||
public Brick(char center, char right, char down, char downright,short walls)
|
||||
public Brick(char center, char right, char down, char downright, short walls)
|
||||
{
|
||||
a=center;
|
||||
b=right;
|
||||
c=down;
|
||||
d=downright;
|
||||
this.walls=walls;
|
||||
a = center;
|
||||
b = right;
|
||||
c = down;
|
||||
d = downright;
|
||||
this.walls = walls;
|
||||
}
|
||||
|
||||
public Brick(String up, String low, short walls)
|
||||
{
|
||||
a = up.charAt(0);
|
||||
b = up.charAt(1);
|
||||
c = low.charAt(0);
|
||||
d = low.charAt(1);
|
||||
this.walls=walls;
|
||||
a = up.charAt(0);
|
||||
b = up.charAt(1);
|
||||
c = low.charAt(0);
|
||||
d = low.charAt(1);
|
||||
this.walls = walls;
|
||||
}
|
||||
|
||||
private boolean check()
|
||||
{
|
||||
// Not Yet Implemented
|
||||
return false;
|
||||
// Not Yet Implemented
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getUpString()
|
||||
{
|
||||
return "" + a + b;
|
||||
return "" + a + b;
|
||||
}
|
||||
|
||||
public String getLowString()
|
||||
{
|
||||
return "" + c + d;
|
||||
return "" + c + d;
|
||||
}
|
||||
|
||||
public static String getDirLine()
|
||||
{
|
||||
char dir[] = new char[16];
|
||||
String s="";
|
||||
|
||||
/*
|
||||
dir[LEFT | DOWN | RIGHT | UP]='O';
|
||||
dir[LEFT | DOWN | RIGHT]='U';
|
||||
dir[LEFT | UP | RIGHT]='M';
|
||||
dir[LEFT | UP | DOWN]='[';
|
||||
dir[RIGHT | UP | DOWN]=']';
|
||||
dir[UP | DOWN]='=';
|
||||
dir[LEFT | RIGHT]='|';
|
||||
dir[RIGHT | DOWN]='J';
|
||||
dir[LEFT | DOWN]='L';
|
||||
dir [LEFT | UP]='T';
|
||||
dir[UP | RIGHT]='7';
|
||||
dir[LEFT] = '!';
|
||||
dir[RIGHT] ='|';
|
||||
dir[DOWN]= '_';
|
||||
dir[UP]= '¨';
|
||||
dir[0]=' ';
|
||||
*/
|
||||
char dir[] = new char[16];
|
||||
String s = "";
|
||||
|
||||
dir[LEFT | DOWN | RIGHT | UP]='O';
|
||||
dir[LEFT | DOWN | RIGHT]='U';
|
||||
dir[LEFT | UP | RIGHT]='M';
|
||||
dir[LEFT | UP | DOWN]='[';
|
||||
dir[RIGHT | UP | DOWN]=']';
|
||||
dir[UP | DOWN]='=';
|
||||
dir[LEFT | RIGHT]=226;
|
||||
dir[RIGHT | DOWN]='J';
|
||||
dir[LEFT | DOWN]='L';
|
||||
dir [LEFT | UP]=169;
|
||||
dir[UP | RIGHT]=170;
|
||||
dir[LEFT] = 173;
|
||||
dir[RIGHT] ='|';
|
||||
dir[DOWN]= '_';
|
||||
dir[UP]= '¨';
|
||||
dir[0]=' ';
|
||||
|
||||
for (int i=0;i< 16; i++)
|
||||
{
|
||||
s=s+dir[i];
|
||||
}
|
||||
/*
|
||||
* dir[LEFT | DOWN | RIGHT | UP]='O'; dir[LEFT | DOWN | RIGHT]='U';
|
||||
* dir[LEFT | UP | RIGHT]='M'; dir[LEFT | UP | DOWN]='['; dir[RIGHT | UP
|
||||
* | DOWN]=']'; dir[UP | DOWN]='='; dir[LEFT | RIGHT]='|'; dir[RIGHT |
|
||||
* DOWN]='J'; dir[LEFT | DOWN]='L'; dir [LEFT | UP]='T'; dir[UP |
|
||||
* RIGHT]='7'; dir[LEFT] = '!'; dir[RIGHT] ='|'; dir[DOWN]= '_';
|
||||
* dir[UP]= '¨'; dir[0]=' ';
|
||||
*/
|
||||
|
||||
return s;
|
||||
dir[LEFT | DOWN | RIGHT | UP] = 'O';
|
||||
dir[LEFT | DOWN | RIGHT] = 'U';
|
||||
dir[LEFT | UP | RIGHT] = 'M';
|
||||
dir[LEFT | UP | DOWN] = '[';
|
||||
dir[RIGHT | UP | DOWN] = ']';
|
||||
dir[UP | DOWN] = '=';
|
||||
dir[LEFT | RIGHT] = 226;
|
||||
dir[RIGHT | DOWN] = 'J';
|
||||
dir[LEFT | DOWN] = 'L';
|
||||
dir[LEFT | UP] = 169;
|
||||
dir[UP | RIGHT] = 170;
|
||||
dir[LEFT] = 173;
|
||||
dir[RIGHT] = '|';
|
||||
dir[DOWN] = '_';
|
||||
dir[UP] = '¨';
|
||||
dir[0] = ' ';
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
s = s + dir[i];
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
public char getChar()
|
||||
{
|
||||
// return getDirLine().charAt(walls & 0xFFF0);
|
||||
return getDirLine().charAt(walls);
|
||||
// return getDirLine().charAt(walls & 0xFFF0);
|
||||
return getDirLine().charAt(walls);
|
||||
}
|
||||
|
||||
public short getWalls()
|
||||
{
|
||||
return walls;
|
||||
return walls;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import javax.swing.KeyStroke;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.artisanlogiciel.games.stl.Wall3d;
|
||||
|
||||
/**
|
||||
* Display
|
||||
**/
|
||||
|
||||
@@ -2,105 +2,116 @@ package org.artisanlogiciel.games;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
class LabyMap
|
||||
implements WallsProvider
|
||||
class LabyMap implements WallsProvider
|
||||
{
|
||||
|
||||
Brick[][] tileMap;
|
||||
LinkedList<Position> exits = new LinkedList<Position>();
|
||||
LinkedList<Position> exits = new LinkedList<Position>();
|
||||
|
||||
public LabyMap(Brick[][] tileMap, LinkedList<Position> exits)
|
||||
{
|
||||
this.tileMap = tileMap;
|
||||
this.exits = exits;
|
||||
this.tileMap = tileMap;
|
||||
this.exits = exits;
|
||||
}
|
||||
|
||||
Brick getAt(int x, int y)
|
||||
{
|
||||
return tileMap[x][y];
|
||||
return tileMap[x][y];
|
||||
}
|
||||
|
||||
public short getWalls(int x, int y)
|
||||
{
|
||||
return getAt(x,y).getWalls();
|
||||
return getAt(x, y).getWalls();
|
||||
}
|
||||
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return tileMap[0].length;
|
||||
return tileMap[0].length;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return tileMap.length;
|
||||
return tileMap.length;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
int entryX = -1;
|
||||
int entryY = -1;
|
||||
for ( Position exit: exits )
|
||||
{
|
||||
if ( exit.getX() == -1 )
|
||||
{
|
||||
entryY = exit.getY();
|
||||
}
|
||||
if ( exit.getY() == -1 )
|
||||
{
|
||||
entryX= exit.getX();
|
||||
}
|
||||
}
|
||||
String laby="H";
|
||||
for ( int x=0; x < tileMap.length; x ++) {
|
||||
if ( entryX == x ) { laby += " H" ; }
|
||||
else { laby+="HH";}
|
||||
}
|
||||
laby+="\n";
|
||||
for ( int y=0; y < tileMap[0].length; y++)
|
||||
{
|
||||
if ( entryY == y ) { laby += ">";}
|
||||
else { laby += "H"; }
|
||||
for ( int x=0; x < tileMap.length; x ++)
|
||||
{
|
||||
laby+= tileMap[x][y].getUpString();
|
||||
}
|
||||
laby+="\n";
|
||||
laby += "H";
|
||||
for ( int x=0; x < tileMap.length; x ++)
|
||||
{
|
||||
laby+= tileMap[x][y].getLowString();
|
||||
}
|
||||
laby+="\n";
|
||||
}
|
||||
return laby;
|
||||
int entryX = -1;
|
||||
int entryY = -1;
|
||||
for (Position exit : exits)
|
||||
{
|
||||
if (exit.getX() == -1)
|
||||
{
|
||||
entryY = exit.getY();
|
||||
}
|
||||
if (exit.getY() == -1)
|
||||
{
|
||||
entryX = exit.getX();
|
||||
}
|
||||
}
|
||||
String laby = "H";
|
||||
for (int x = 0; x < tileMap.length; x++)
|
||||
{
|
||||
if (entryX == x)
|
||||
{
|
||||
laby += " H";
|
||||
}
|
||||
else
|
||||
{
|
||||
laby += "HH";
|
||||
}
|
||||
}
|
||||
laby += "\n";
|
||||
for (int y = 0; y < tileMap[0].length; y++)
|
||||
{
|
||||
if (entryY == y)
|
||||
{
|
||||
laby += ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
laby += "H";
|
||||
}
|
||||
for (int x = 0; x < tileMap.length; x++)
|
||||
{
|
||||
laby += tileMap[x][y].getUpString();
|
||||
}
|
||||
laby += "\n";
|
||||
laby += "H";
|
||||
for (int x = 0; x < tileMap.length; x++)
|
||||
{
|
||||
laby += tileMap[x][y].getLowString();
|
||||
}
|
||||
laby += "\n";
|
||||
}
|
||||
return laby;
|
||||
}
|
||||
|
||||
|
||||
public String toShortString()
|
||||
{
|
||||
int entryX = -1;
|
||||
int entryY = -1;
|
||||
for ( Position exit: exits )
|
||||
{
|
||||
if ( exit.getX() == -1 )
|
||||
{
|
||||
entryY = exit.getY();
|
||||
}
|
||||
if ( exit.getY() == -1 )
|
||||
{
|
||||
entryX= exit.getX();
|
||||
}
|
||||
}
|
||||
String laby="";
|
||||
for ( int y=0; y < tileMap[0].length; y++)
|
||||
{
|
||||
for ( int x=0; x < tileMap.length; x ++)
|
||||
{
|
||||
laby+= "" + tileMap[x][y].getChar();
|
||||
}
|
||||
laby+="\n";
|
||||
}
|
||||
return laby;
|
||||
int entryX = -1;
|
||||
int entryY = -1;
|
||||
for (Position exit : exits)
|
||||
{
|
||||
if (exit.getX() == -1)
|
||||
{
|
||||
entryY = exit.getY();
|
||||
}
|
||||
if (exit.getY() == -1)
|
||||
{
|
||||
entryX = exit.getX();
|
||||
}
|
||||
}
|
||||
String laby = "";
|
||||
for (int y = 0; y < tileMap[0].length; y++)
|
||||
{
|
||||
for (int x = 0; x < tileMap.length; x++)
|
||||
{
|
||||
laby += "" + tileMap[x][y].getChar();
|
||||
}
|
||||
laby += "\n";
|
||||
}
|
||||
return laby;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,50 +6,50 @@ import java.util.LinkedList;
|
||||
public class Main
|
||||
{
|
||||
|
||||
public WallsProvider generate(int width,int height, int maxdepth, MazeResolutionListener listener)
|
||||
public WallsProvider generate(int width, int height, int maxdepth, MazeResolutionListener listener)
|
||||
{
|
||||
LabyModel model = new LabyModel(width, height,maxdepth, new java.util.Random());
|
||||
model.generateWithEntry(0, 0);
|
||||
LinkedList<Position> exits = new LinkedList<Position>();
|
||||
model.addEntryOrExit(-1,0);
|
||||
model.addEntryOrExit(width,height -1);
|
||||
if ( ! model.check() )
|
||||
{
|
||||
System.out.println("Check failed");
|
||||
}
|
||||
model.resolve(width-1,height-1,listener);
|
||||
return model;
|
||||
LabyModel model = new LabyModel(width, height, maxdepth, new java.util.Random());
|
||||
model.generateWithEntry(0, 0);
|
||||
LinkedList<Position> exits = new LinkedList<Position>();
|
||||
model.addEntryOrExit(-1, 0);
|
||||
model.addEntryOrExit(width, height - 1);
|
||||
if (!model.check())
|
||||
{
|
||||
System.out.println("Check failed");
|
||||
}
|
||||
model.resolve(width - 1, height - 1, listener);
|
||||
return model;
|
||||
}
|
||||
|
||||
public LabyMap generate2(int width,int height, int maxdepth)
|
||||
public LabyMap generate2(int width, int height, int maxdepth)
|
||||
{
|
||||
LabyModel model = new LabyModel(width, height,maxdepth, new java.util.Random( 1024L));
|
||||
model.generateWithEntry(0, 0);
|
||||
LinkedList<Position> exits = new LinkedList<Position>();
|
||||
model.addEntryOrExit(-1,0);
|
||||
model.addEntryOrExit(width,height -1);
|
||||
System.out.println(model.toLabyMap().toString());
|
||||
if ( ! model.check() )
|
||||
{
|
||||
System.out.println("Check failed");
|
||||
}
|
||||
model.debugOut();
|
||||
model.resolve(width-1,height-1,null);
|
||||
LabyMap labyMap =model.toLabyMap();
|
||||
return labyMap;
|
||||
LabyModel model = new LabyModel(width, height, maxdepth, new java.util.Random(1024L));
|
||||
model.generateWithEntry(0, 0);
|
||||
LinkedList<Position> exits = new LinkedList<Position>();
|
||||
model.addEntryOrExit(-1, 0);
|
||||
model.addEntryOrExit(width, height - 1);
|
||||
System.out.println(model.toLabyMap().toString());
|
||||
if (!model.check())
|
||||
{
|
||||
System.out.println("Check failed");
|
||||
}
|
||||
model.debugOut();
|
||||
model.resolve(width - 1, height - 1, null);
|
||||
LabyMap labyMap = model.toLabyMap();
|
||||
return labyMap;
|
||||
}
|
||||
|
||||
public static void main(String pArgs[])
|
||||
{
|
||||
System.out.println("enter width height and maxdepth");
|
||||
Scanner console = new Scanner(System.in);
|
||||
int width = console.nextInt();
|
||||
int height = console.nextInt();
|
||||
int maxdepth = console.nextInt();
|
||||
Main m= new Main();
|
||||
LabyMap map = m.generate2(width,height,maxdepth);
|
||||
System.out.println(map.toShortString());
|
||||
System.out.println(map.toString());
|
||||
System.out.println(Brick.getDirLine());
|
||||
System.out.println("enter width height and maxdepth");
|
||||
Scanner console = new Scanner(System.in);
|
||||
int width = console.nextInt();
|
||||
int height = console.nextInt();
|
||||
int maxdepth = console.nextInt();
|
||||
Main m = new Main();
|
||||
LabyMap map = m.generate2(width, height, maxdepth);
|
||||
System.out.println(map.toShortString());
|
||||
System.out.println(map.toString());
|
||||
System.out.println(Brick.getDirLine());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.artisanlogiciel.games;
|
||||
|
||||
/**
|
||||
MazeCreationListener
|
||||
* MazeCreationListener
|
||||
**/
|
||||
interface MazeCreationListener
|
||||
{
|
||||
|
||||
@@ -3,22 +3,24 @@ package org.artisanlogiciel.games;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
MazeParams was autogenerated by ./generate_newclass.sh
|
||||
* MazeParams was autogenerated by ./generate_newclass.sh
|
||||
**/
|
||||
public interface MazeParams
|
||||
{
|
||||
public int getWidth();
|
||||
|
||||
public int getHeight();
|
||||
|
||||
public int getMaxDepth();
|
||||
|
||||
/**
|
||||
@return name of Maze, used for creating filename at saving time
|
||||
* @return name of Maze, used for creating filename at saving time
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
@return directory owning where to save a maze
|
||||
* @return directory owning where to save a maze
|
||||
*/
|
||||
public File getSaveDir();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ package org.artisanlogiciel.games;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
MazeResolutionListener used as interface between resolver and (mostly) GUI
|
||||
* MazeResolutionListener used as interface between resolver and (mostly) GUI
|
||||
**/
|
||||
public interface MazeResolutionListener
|
||||
{
|
||||
|
||||
public boolean notifySearch(Position pPosition);
|
||||
|
||||
|
||||
public void notifySearchError(String error);
|
||||
|
||||
public void notifyCompletion(LinkedList<Position> solvedPath);
|
||||
|
||||
@@ -1,38 +1,41 @@
|
||||
package org.artisanlogiciel.games;
|
||||
|
||||
public class Position {
|
||||
public class Position
|
||||
{
|
||||
private int x, y;
|
||||
private int depth;
|
||||
|
||||
public Position(int x, int y,int depth){
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.depth=depth;
|
||||
public Position(int x, int y, int depth)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public Position(int x, int y){
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.depth=0;
|
||||
public Position(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.depth = 0;
|
||||
}
|
||||
|
||||
public int getX()
|
||||
{
|
||||
return this.x;
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY()
|
||||
{
|
||||
return this.y;
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getDepth()
|
||||
{
|
||||
return depth;
|
||||
return depth;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "(" + x + "," + y + ")" + "/" + depth ;
|
||||
return "(" + x + "," + y + ")" + "/" + depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
package org.artisanlogiciel.games;
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
Wall3d to create walls in 3d
|
||||
South, West North East...
|
||||
**/
|
||||
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 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}};
|
||||
|
||||
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);
|
||||
public final static Wall3d North = new Wall3d(10,1,10,0,10,0);
|
||||
public final static Wall3d East = new Wall3d(1,10,10,10,0,0);
|
||||
|
||||
int triangle[][][] = null;
|
||||
|
||||
public Wall3d(int t[][][])
|
||||
{
|
||||
triangle = t;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
// point in a triangle
|
||||
for (int p=0; p<3; p++)
|
||||
{
|
||||
short uaxis=0;
|
||||
for (int axis=0; axis <2; axis++)
|
||||
{
|
||||
short caxis = AXIS[i/2][axis];
|
||||
if ( caxis >0 )
|
||||
{
|
||||
f=1;
|
||||
}
|
||||
else
|
||||
if ( caxis <0 )
|
||||
{
|
||||
f=-1;
|
||||
caxis=(short) -caxis;
|
||||
}
|
||||
uaxis|=caxis;
|
||||
if ( caxis == X )
|
||||
{
|
||||
caxis=0;
|
||||
}
|
||||
else if ( caxis == Y)
|
||||
{
|
||||
caxis=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
caxis=2;
|
||||
}
|
||||
// if ( f == 0 )
|
||||
// {
|
||||
// System.out.println("ERROR");
|
||||
// }
|
||||
//System.out.println("i " + i + " p " + p + " a " + caxis + " , " + BASE[i%4][p][axis] );
|
||||
triangle[i][p][caxis]=translate[caxis] + BASE[i%4][p][axis]*f*factor[caxis];
|
||||
}
|
||||
if ( (uaxis & X) == 0 )
|
||||
{
|
||||
uaxis=0;
|
||||
}
|
||||
else if ( (uaxis & Y) == 0)
|
||||
{
|
||||
uaxis=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
uaxis=2;
|
||||
}
|
||||
triangle[i][p][uaxis]=translate[uaxis] + AXIS[i/2][2]*factor[uaxis];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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++)
|
||||
{
|
||||
// point in a triangle
|
||||
for (int p=0; p<3; p++)
|
||||
{
|
||||
for (int axis=0; axis <3; axis++)
|
||||
{
|
||||
t[i][p][axis]=translate[axis] + triangle[i][p][axis];
|
||||
}
|
||||
}
|
||||
}
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String s = "";
|
||||
for (int t=0; t<12; t++)
|
||||
{
|
||||
s+="facet normal 0 0 0\nouter loop\n";
|
||||
for (int p=0; p<3; p++)
|
||||
{
|
||||
s+="vertex";
|
||||
for (int a=0; a<3; a++)
|
||||
{
|
||||
// s+=" t "+ t + " p " + p + " a " + a + "=" + triangle[t][p][a];
|
||||
s+= " " + triangle[t][p][a];
|
||||
}
|
||||
s+="\n";
|
||||
}
|
||||
s=s+"endloop\nendfacet\n";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
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, WallsProvider provider, OutputStream stream)
|
||||
throws IOException
|
||||
{
|
||||
int width = provider.getWidth();
|
||||
int height = provider.getHeight();
|
||||
int xl = 10;
|
||||
int yl = 10;
|
||||
int zl = 10;
|
||||
|
||||
// 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++)
|
||||
{
|
||||
short walls = provider.getWalls(x,0);
|
||||
if ( (walls & Brick.UP) != 0 )
|
||||
{
|
||||
stream.write(new Wall3d(South,x*xl,0,0).toString().getBytes());
|
||||
}
|
||||
if ( (walls & Brick.LEFT) != 0 )
|
||||
{
|
||||
stream.write(new Wall3d(West,x*xl,0,0).toString().getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
for (int y=0; y<height; y++)
|
||||
{
|
||||
short walls = provider.getWalls(0,y);
|
||||
if ( (walls & Brick.LEFT) != 0 )
|
||||
{
|
||||
stream.write(new Wall3d(West,0,y*yl,0).toString().getBytes());
|
||||
}
|
||||
for (int x=0; x<width; x++)
|
||||
{
|
||||
// south and east
|
||||
walls = provider.getWalls(x,y);
|
||||
if ( (walls & Brick.DOWN) != 0 )
|
||||
{
|
||||
stream.write(new Wall3d(North,x*xl,y*yl,0).toString().getBytes());
|
||||
}
|
||||
if ( (walls & Brick.RIGHT) != 0)
|
||||
{
|
||||
stream.write(new Wall3d(East,x*xl,y*yl,0).toString().getBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.write("endsolid wall\n\n".getBytes());
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
Scanner console = new Scanner(System.in);
|
||||
int xl = console.nextInt();
|
||||
int yl = console.nextInt();
|
||||
int zl = console.nextInt();
|
||||
|
||||
int dx = console.nextInt();
|
||||
int dy = console.nextInt();
|
||||
int dz = console.nextInt();
|
||||
|
||||
String s="solid wall\n";
|
||||
|
||||
Wall3d instance=new Wall3d(xl,yl,zl, dx,dy,dz);
|
||||
|
||||
prepare();
|
||||
|
||||
s+="endsolid wall\n\n";
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.artisanlogiciel.games;
|
||||
|
||||
/**
|
||||
WallsProvider provide a Walls representation
|
||||
* WallsProvider provide a Walls representation
|
||||
**/
|
||||
public interface WallsProvider
|
||||
{
|
||||
@@ -11,17 +11,10 @@ public interface WallsProvider
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
See Brick
|
||||
|
||||
Will set bits :
|
||||
3 2 1 0
|
||||
(8)(4)(2)(1)
|
||||
^ > v <
|
||||
U R D L
|
||||
p i o e
|
||||
g w f
|
||||
h n t
|
||||
t
|
||||
* See Brick
|
||||
*
|
||||
* Will set bits : 3 2 1 0 (8)(4)(2)(1) ^ > v < U R D L p i o e g w f h n t
|
||||
* t
|
||||
**/
|
||||
public short getWalls(int x, int y);
|
||||
}
|
||||
|
||||
225
java/org/artisanlogiciel/games/stl/Wall3d.java
Normal file
225
java/org/artisanlogiciel/games/stl/Wall3d.java
Normal file
@@ -0,0 +1,225 @@
|
||||
package org.artisanlogiciel.games.stl;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.artisanlogiciel.games.Brick;
|
||||
import org.artisanlogiciel.games.WallsProvider;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Wall3d to create walls in 3d for stl conversion South, West North East...
|
||||
**/
|
||||
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 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 } };
|
||||
|
||||
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);
|
||||
public final static Wall3d North = new Wall3d(10, 1, 10, 0, 10, 0);
|
||||
public final static Wall3d East = new Wall3d(1, 10, 10, 10, 0, 0);
|
||||
|
||||
int triangle[][][] = null;
|
||||
|
||||
public Wall3d(int t[][][])
|
||||
{
|
||||
triangle = t;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
// point in a triangle
|
||||
for (int p = 0; p < 3; p++)
|
||||
{
|
||||
short uaxis = 0;
|
||||
for (int axis = 0; axis < 2; axis++)
|
||||
{
|
||||
short caxis = AXIS[i / 2][axis];
|
||||
if (caxis > 0)
|
||||
{
|
||||
f = 1;
|
||||
}
|
||||
else if (caxis < 0)
|
||||
{
|
||||
f = -1;
|
||||
caxis = (short) -caxis;
|
||||
}
|
||||
uaxis |= caxis;
|
||||
if (caxis == X)
|
||||
{
|
||||
caxis = 0;
|
||||
}
|
||||
else if (caxis == Y)
|
||||
{
|
||||
caxis = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
caxis = 2;
|
||||
}
|
||||
// if ( f == 0 )
|
||||
// {
|
||||
// System.out.println("ERROR");
|
||||
// }
|
||||
// System.out.println("i " + i + " p " + p + " a " + caxis +
|
||||
// " , " + BASE[i%4][p][axis] );
|
||||
triangle[i][p][caxis] = translate[caxis] + BASE[i % 4][p][axis] * f * factor[caxis];
|
||||
}
|
||||
if ((uaxis & X) == 0)
|
||||
{
|
||||
uaxis = 0;
|
||||
}
|
||||
else if ((uaxis & Y) == 0)
|
||||
{
|
||||
uaxis = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
uaxis = 2;
|
||||
}
|
||||
triangle[i][p][uaxis] = translate[uaxis] + AXIS[i / 2][2] * factor[uaxis];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
// point in a triangle
|
||||
for (int p = 0; p < 3; p++)
|
||||
{
|
||||
for (int axis = 0; axis < 3; axis++)
|
||||
{
|
||||
t[i][p][axis] = translate[axis] + triangle[i][p][axis];
|
||||
}
|
||||
}
|
||||
}
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String s = "";
|
||||
for (int t = 0; t < 12; t++)
|
||||
{
|
||||
s += "facet normal 0 0 0\nouter loop\n";
|
||||
for (int p = 0; p < 3; p++)
|
||||
{
|
||||
s += "vertex";
|
||||
for (int a = 0; a < 3; a++)
|
||||
{
|
||||
// s+=" t "+ t + " p " + p + " a " + a + "=" +
|
||||
// triangle[t][p][a];
|
||||
s += " " + triangle[t][p][a];
|
||||
}
|
||||
s += "\n";
|
||||
}
|
||||
s = s + "endloop\nendfacet\n";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
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, WallsProvider provider, OutputStream stream) throws IOException
|
||||
{
|
||||
int width = provider.getWidth();
|
||||
int height = provider.getHeight();
|
||||
int xl = 10;
|
||||
int yl = 10;
|
||||
int zl = 10;
|
||||
|
||||
// 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++)
|
||||
{
|
||||
short walls = provider.getWalls(x, 0);
|
||||
if ((walls & Brick.UP) != 0)
|
||||
{
|
||||
stream.write(new Wall3d(South, x * xl, 0, 0).toString().getBytes());
|
||||
}
|
||||
if ((walls & Brick.LEFT) != 0)
|
||||
{
|
||||
stream.write(new Wall3d(West, x * xl, 0, 0).toString().getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
short walls = provider.getWalls(0, y);
|
||||
if ((walls & Brick.LEFT) != 0)
|
||||
{
|
||||
stream.write(new Wall3d(West, 0, y * yl, 0).toString().getBytes());
|
||||
}
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
// south and east
|
||||
walls = provider.getWalls(x, y);
|
||||
if ((walls & Brick.DOWN) != 0)
|
||||
{
|
||||
stream.write(new Wall3d(North, x * xl, y * yl, 0).toString().getBytes());
|
||||
}
|
||||
if ((walls & Brick.RIGHT) != 0)
|
||||
{
|
||||
stream.write(new Wall3d(East, x * xl, y * yl, 0).toString().getBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.write("endsolid wall\n\n".getBytes());
|
||||
}
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
|
||||
Scanner console = new Scanner(System.in);
|
||||
int xl = console.nextInt();
|
||||
int yl = console.nextInt();
|
||||
int zl = console.nextInt();
|
||||
|
||||
int dx = console.nextInt();
|
||||
int dy = console.nextInt();
|
||||
int dz = console.nextInt();
|
||||
|
||||
String s = "solid wall\n";
|
||||
|
||||
Wall3d instance = new Wall3d(xl, yl, zl, dx, dy, dz);
|
||||
|
||||
prepare();
|
||||
|
||||
s += "endsolid wall\n\n";
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user