Proper staircase triangle neighbor calculations.

origin
Joshua Sigona 3 years ago
parent ef9d56cdca
commit 3644040528
  1. 53
      src/sig/Block.java
  2. 24
      src/sig/FacingDirection.java
  3. 4
      src/sig/SigRenderer.java

@ -57,7 +57,7 @@ public class Block {
} }
if (!(block instanceof Cube)) { if (!(block instanceof Cube)) {
updateFaces(); updateFaces();
for (int x=-1;x<=1;x++) { /*for (int x=-1;x<=1;x++) {
for (int y=-1;y<=1;y++) { for (int y=-1;y<=1;y++) {
for (int z=-1;z<=1;z++) { for (int z=-1;z<=1;z++) {
if (Math.abs(x)+Math.abs(y)+Math.abs(z)==1) { if (Math.abs(x)+Math.abs(y)+Math.abs(z)==1) {
@ -69,7 +69,7 @@ public class Block {
} }
} }
} }
} }*/
} }
} }
public void setFacingDirection(FacingDirection direction) { public void setFacingDirection(FacingDirection direction) {
@ -101,9 +101,6 @@ public class Block {
if (b.block instanceof Staircase && block instanceof Staircase) { if (b.block instanceof Staircase && block instanceof Staircase) {
neighbors.DOWN=false; neighbors.DOWN=false;
b.neighbors.UP=true; b.neighbors.UP=true;
} else
if (b.block instanceof Staircase && block instanceof Cube) {
b.neighbors.UP=block.triangles.get(Texture.BOTTOM).tex.hasTransparency==b.block.triangles.get(Texture.TOP).tex.hasTransparency&&block.triangles.get(Texture.BOTTOM).tex.hasTranslucency==b.block.triangles.get(Texture.TOP).tex.hasTranslucency;
} else { } else {
neighbors.DOWN=b.neighbors.UP=block.triangles.get(Texture.BOTTOM).tex.hasTransparency==b.block.triangles.get(Texture.TOP).tex.hasTransparency&&block.triangles.get(Texture.BOTTOM).tex.hasTranslucency==b.block.triangles.get(Texture.TOP).tex.hasTranslucency; neighbors.DOWN=b.neighbors.UP=block.triangles.get(Texture.BOTTOM).tex.hasTransparency==b.block.triangles.get(Texture.TOP).tex.hasTransparency&&block.triangles.get(Texture.BOTTOM).tex.hasTranslucency==b.block.triangles.get(Texture.TOP).tex.hasTranslucency;
} }
@ -111,12 +108,11 @@ public class Block {
key=(pos.x-1)+"_"+(pos.y)+"_"+pos.z; key=(pos.x-1)+"_"+(pos.y)+"_"+pos.z;
b = SigRenderer.blockGrid.get(key); b = SigRenderer.blockGrid.get(key);
if (SigRenderer.blockGrid.containsKey(key)) { if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase && if (b.block instanceof Staircase && block instanceof Staircase) {
b.getFacingDirection()!=getFacingDirection()) { neighbors.LEFT=b.neighbors.RIGHT=
neighbors.LEFT=b.neighbors.RIGHT=false; FacingDirection.isFacingAwayFromEachOther(this,b)||
} else (FacingDirection.isFacingEachOther(this,b)||
if (b.block instanceof Staircase && block instanceof Cube) { (b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==0));
b.neighbors.RIGHT=block.triangles.get(Texture.WEST).tex.hasTransparency==b.block.triangles.get(Texture.EAST).tex.hasTransparency&&block.triangles.get(Texture.WEST).tex.hasTranslucency==b.block.triangles.get(Texture.EAST).tex.hasTranslucency;
} else { } else {
neighbors.LEFT=b.neighbors.RIGHT=block.triangles.get(Texture.WEST).tex.hasTransparency==b.block.triangles.get(Texture.EAST).tex.hasTransparency&&block.triangles.get(Texture.WEST).tex.hasTranslucency==b.block.triangles.get(Texture.EAST).tex.hasTranslucency; neighbors.LEFT=b.neighbors.RIGHT=block.triangles.get(Texture.WEST).tex.hasTransparency==b.block.triangles.get(Texture.EAST).tex.hasTransparency&&block.triangles.get(Texture.WEST).tex.hasTranslucency==b.block.triangles.get(Texture.EAST).tex.hasTranslucency;
} }
@ -124,12 +120,11 @@ public class Block {
key=(pos.x+1)+"_"+(pos.y)+"_"+pos.z; key=(pos.x+1)+"_"+(pos.y)+"_"+pos.z;
b = SigRenderer.blockGrid.get(key); b = SigRenderer.blockGrid.get(key);
if (SigRenderer.blockGrid.containsKey(key)) { if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase && if (b.block instanceof Staircase && block instanceof Staircase) {
b.getFacingDirection()!=getFacingDirection()) { neighbors.RIGHT=b.neighbors.LEFT=
neighbors.RIGHT=b.neighbors.LEFT=false; FacingDirection.isFacingAwayFromEachOther(this,b)||
} else (FacingDirection.isFacingEachOther(this,b)||
if (b.block instanceof Staircase && block instanceof Cube) { (b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==0));
b.neighbors.LEFT=block.triangles.get(Texture.EAST).tex.hasTransparency==b.block.triangles.get(Texture.WEST).tex.hasTransparency&&block.triangles.get(Texture.EAST).tex.hasTranslucency==b.block.triangles.get(Texture.WEST).tex.hasTranslucency;
} else { } else {
neighbors.RIGHT=b.neighbors.LEFT=block.triangles.get(Texture.EAST).tex.hasTransparency==b.block.triangles.get(Texture.WEST).tex.hasTransparency&&block.triangles.get(Texture.EAST).tex.hasTranslucency==b.block.triangles.get(Texture.WEST).tex.hasTranslucency; neighbors.RIGHT=b.neighbors.LEFT=block.triangles.get(Texture.EAST).tex.hasTransparency==b.block.triangles.get(Texture.WEST).tex.hasTransparency&&block.triangles.get(Texture.EAST).tex.hasTranslucency==b.block.triangles.get(Texture.WEST).tex.hasTranslucency;
} }
@ -137,12 +132,11 @@ public class Block {
key=pos.x+"_"+(pos.y)+"_"+(pos.z+1); key=pos.x+"_"+(pos.y)+"_"+(pos.z+1);
b = SigRenderer.blockGrid.get(key); b = SigRenderer.blockGrid.get(key);
if (SigRenderer.blockGrid.containsKey(key)) { if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase && if (b.block instanceof Staircase && block instanceof Staircase) {
!b.getFacingDirection().isOpposite(getFacingDirection())) { neighbors.FORWARD=b.neighbors.BACKWARD=
neighbors.FORWARD=b.neighbors.BACKWARD=false; FacingDirection.isFacingAwayFromEachOther(this,b)||
} else (FacingDirection.isFacingEachOther(this,b)||
if (b.block instanceof Staircase && block instanceof Cube) { (b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==1));
b.neighbors.BACKWARD=block.triangles.get(Texture.SOUTH).tex.hasTransparency==b.block.triangles.get(Texture.NORTH).tex.hasTransparency&&block.triangles.get(Texture.SOUTH).tex.hasTranslucency==b.block.triangles.get(Texture.NORTH).tex.hasTranslucency;
} else { } else {
neighbors.FORWARD=b.neighbors.BACKWARD=block.triangles.get(Texture.SOUTH).tex.hasTransparency==b.block.triangles.get(Texture.NORTH).tex.hasTransparency&&block.triangles.get(Texture.SOUTH).tex.hasTranslucency==b.block.triangles.get(Texture.NORTH).tex.hasTranslucency; neighbors.FORWARD=b.neighbors.BACKWARD=block.triangles.get(Texture.SOUTH).tex.hasTransparency==b.block.triangles.get(Texture.NORTH).tex.hasTransparency&&block.triangles.get(Texture.SOUTH).tex.hasTranslucency==b.block.triangles.get(Texture.NORTH).tex.hasTranslucency;
} }
@ -150,14 +144,13 @@ public class Block {
key=pos.x+"_"+(pos.y)+"_"+(pos.z-1); key=pos.x+"_"+(pos.y)+"_"+(pos.z-1);
b = SigRenderer.blockGrid.get(key); b = SigRenderer.blockGrid.get(key);
if (SigRenderer.blockGrid.containsKey(key)) { if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase && if (b.block instanceof Staircase && block instanceof Staircase) {
!b.getFacingDirection().isOpposite(getFacingDirection())) { neighbors.BACKWARD=b.neighbors.FORWARD=
neighbors.BACKWARD=b.neighbors.FORWARD=false; FacingDirection.isFacingAwayFromEachOther(this,b)||
} else (FacingDirection.isFacingEachOther(this,b)||
if (b.block instanceof Staircase && block instanceof Cube) { (b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==1));
SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).neighbors.FORWARD=block.triangles.get(Texture.NORTH).tex.hasTransparency==SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).block.triangles.get(Texture.SOUTH).tex.hasTransparency&&block.triangles.get(Texture.NORTH).tex.hasTranslucency==SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).block.triangles.get(Texture.SOUTH).tex.hasTranslucency;
} else { } else {
neighbors.BACKWARD=SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).neighbors.FORWARD=block.triangles.get(Texture.NORTH).tex.hasTransparency==SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).block.triangles.get(Texture.SOUTH).tex.hasTransparency&&block.triangles.get(Texture.NORTH).tex.hasTranslucency==SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).block.triangles.get(Texture.SOUTH).tex.hasTranslucency; neighbors.BACKWARD=b.neighbors.FORWARD=block.triangles.get(Texture.NORTH).tex.hasTransparency==b.block.triangles.get(Texture.SOUTH).tex.hasTransparency&&block.triangles.get(Texture.NORTH).tex.hasTranslucency==b.block.triangles.get(Texture.SOUTH).tex.hasTranslucency;
} }
} }
} }

@ -16,4 +16,28 @@ public enum FacingDirection {
boolean isOpposite(FacingDirection dir) { boolean isOpposite(FacingDirection dir) {
return this.ordinal()!=dir.ordinal()&&this.ordinal()%2==dir.ordinal()%2; return this.ordinal()!=dir.ordinal()&&this.ordinal()%2==dir.ordinal()%2;
} }
public static boolean isFacingEachOther(Block b1, Block b2) {
float xDiff=b1.pos.x-b2.pos.x;
float zDiff=b1.pos.z-b2.pos.z;
if (Math.abs(xDiff)+Math.abs(zDiff)==1) {
return (xDiff==-1&&b1.getFacingDirection()==WEST&&b2.getFacingDirection()==EAST)||
(xDiff==1&&b1.getFacingDirection()==EAST&&b2.getFacingDirection()==WEST)||
(zDiff==-1&&b1.getFacingDirection()==NORTH&&b2.getFacingDirection()==SOUTH)||
(zDiff==1&&b1.getFacingDirection()==SOUTH&&b2.getFacingDirection()==NORTH);
} else {
return false;
}
}
public static boolean isFacingAwayFromEachOther(Block b1, Block b2) {
float xDiff=b1.pos.x-b2.pos.x;
float zDiff=b1.pos.z-b2.pos.z;
if (Math.abs(xDiff)+Math.abs(zDiff)==1) {
return (xDiff==-1&&b1.getFacingDirection()==EAST&&b2.getFacingDirection()==WEST)||
(xDiff==1&&b1.getFacingDirection()==WEST&&b2.getFacingDirection()==EAST)||
(zDiff==-1&&b1.getFacingDirection()==SOUTH&&b2.getFacingDirection()==NORTH)||
(zDiff==1&&b1.getFacingDirection()==NORTH&&b2.getFacingDirection()==SOUTH);
} else {
return false;
}
}
} }

@ -370,8 +370,8 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
for (int x=0;x<64;x++) { for (int x=0;x<64;x++) {
for (int z=0;z<64;z++) { for (int z=0;z<64;z++) {
addBlock(new Vector(x,0,z),Cube.class,BlockType.GRASS,FacingDirection.SOUTH); addBlock(new Vector(x,0,z),Cube.class,BlockType.GRASS,FacingDirection.SOUTH);
//addBlock(new Vector(x,1,z),BlockType.JUNGLE_PLANK,FacingDirection.SOUTH); //addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH);
//addBlock(new Vector(x,2,z),BlockType.SPRUCE_PLANK,FacingDirection.SOUTH); //addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH);
/*for (int y=1;y<r.nextInt(5);y++) { /*for (int y=1;y<r.nextInt(5);y++) {
addBlock(new Vector(x,y,z),BlockType.PLANKS,FacingDirection.SOUTH); addBlock(new Vector(x,y,z),BlockType.PLANKS,FacingDirection.SOUTH);
}*/ }*/

Loading…
Cancel
Save