Implement translucent/transparent rendering neighbor checking.

origin
Joshua Sigona 3 years ago
parent 52ccce0610
commit d5c15f7ee3
  1. 50
      src/sig/Block.java
  2. 1
      src/sig/Cube.java
  3. 10
      src/sig/SigRenderer.java

@ -99,16 +99,16 @@ public class Block {
Block b = SigRenderer.blockGrid.get(key);
if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase) {
neighbors.UP=true;
neighbors.UP=block.triangles.get(Texture.TOP).tex.hasTransparency==b.block.triangles.get(Texture.BOTTOM).tex.hasTransparency&&block.triangles.get(Texture.TOP).tex.hasTranslucency==b.block.triangles.get(Texture.BOTTOM).tex.hasTranslucency;
b.neighbors.DOWN=false;
} else
if ((b.block instanceof Cube && block instanceof Staircase)||(b.block instanceof Staircase && block instanceof Cube)) {
Block staircase = (b.block instanceof Staircase)?b:this;
if (b.equals(staircase)) {
neighbors.UP=b.neighbors.DOWN=true;
neighbors.UP=b.neighbors.DOWN=block.triangles.get(Texture.TOP).tex.hasTransparency==b.block.triangles.get(Texture.BOTTOM).tex.hasTransparency&&block.triangles.get(Texture.TOP).tex.hasTranslucency==b.block.triangles.get(Texture.BOTTOM).tex.hasTranslucency;
} else {
neighbors.UP=true;
neighbors.UP=block.triangles.get(Texture.TOP).tex.hasTransparency==b.block.triangles.get(Texture.BOTTOM).tex.hasTransparency&&block.triangles.get(Texture.TOP).tex.hasTranslucency==b.block.triangles.get(Texture.BOTTOM).tex.hasTranslucency;
b.neighbors.DOWN=false;
}
} else {
@ -120,7 +120,7 @@ public class Block {
if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase) {
neighbors.DOWN=false;
b.neighbors.UP=true;
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
if ((b.block instanceof Cube && block instanceof Staircase)||(b.block instanceof Staircase && block instanceof Cube)) {
Block staircase = (b.block instanceof Staircase)?b:this;
@ -129,7 +129,7 @@ public class Block {
neighbors.DOWN=b.neighbors.UP=false;
} else {
neighbors.DOWN=false;
b.neighbors.UP=true;
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 {
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;
@ -140,17 +140,19 @@ public class Block {
if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase) {
neighbors.LEFT=b.neighbors.RIGHT=
FacingDirection.isFacingAwayFromEachOther(this,b)||
(FacingDirection.isFacingAwayFromEachOther(this,b)||
(FacingDirection.isFacingEachOther(this,b)||
(b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==0));
(b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==0)))&&
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
if ((b.block instanceof Cube && block instanceof Staircase)||(b.block instanceof Staircase && block instanceof Cube)) {
Block cubeBlock = (b.block instanceof Cube)?b:this;
Block staircase = (b.block instanceof Staircase)?b:this;
neighbors.LEFT=b.neighbors.RIGHT=
(b.equals(staircase)&&staircase.getFacingDirection()==FacingDirection.EAST)||
(b.equals(cubeBlock)&&staircase.getFacingDirection()==FacingDirection.WEST);
((b.equals(staircase)&&staircase.getFacingDirection()==FacingDirection.EAST)||
(b.equals(cubeBlock)&&staircase.getFacingDirection()==FacingDirection.WEST))&&
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 {
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;
}
@ -160,17 +162,19 @@ public class Block {
if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase) {
neighbors.RIGHT=b.neighbors.LEFT=
FacingDirection.isFacingAwayFromEachOther(this,b)||
(FacingDirection.isFacingAwayFromEachOther(this,b)||
(FacingDirection.isFacingEachOther(this,b)||
(b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==0));
(b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==0)))&&
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
if ((b.block instanceof Cube && block instanceof Staircase)||(b.block instanceof Staircase && block instanceof Cube)) {
Block cubeBlock = (b.block instanceof Cube)?b:this;
Block staircase = (b.block instanceof Staircase)?b:this;
neighbors.RIGHT=b.neighbors.LEFT=
(b.equals(staircase)&&staircase.getFacingDirection()==FacingDirection.WEST)||
(b.equals(cubeBlock)&&staircase.getFacingDirection()==FacingDirection.EAST);
((b.equals(staircase)&&staircase.getFacingDirection()==FacingDirection.WEST)||
(b.equals(cubeBlock)&&staircase.getFacingDirection()==FacingDirection.EAST))&&
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 {
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;
}
@ -180,17 +184,19 @@ public class Block {
if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase) {
neighbors.FORWARD=b.neighbors.BACKWARD=
FacingDirection.isFacingAwayFromEachOther(this,b)||
(FacingDirection.isFacingAwayFromEachOther(this,b)||
(FacingDirection.isFacingEachOther(this,b)||
(b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==1));
(b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==1)))&&
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
if ((b.block instanceof Cube && block instanceof Staircase)||(b.block instanceof Staircase && block instanceof Cube)) {
Block cubeBlock = (b.block instanceof Cube)?b:this;
Block staircase = (b.block instanceof Staircase)?b:this;
neighbors.FORWARD=b.neighbors.BACKWARD=
(b.equals(staircase)&&staircase.getFacingDirection()==FacingDirection.NORTH)||
(b.equals(cubeBlock)&&staircase.getFacingDirection()==FacingDirection.SOUTH);
((b.equals(staircase)&&staircase.getFacingDirection()==FacingDirection.NORTH)||
(b.equals(cubeBlock)&&staircase.getFacingDirection()==FacingDirection.SOUTH))&&
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 {
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;
}
@ -200,17 +206,19 @@ public class Block {
if (SigRenderer.blockGrid.containsKey(key)) {
if (b.block instanceof Staircase && block instanceof Staircase) {
neighbors.BACKWARD=b.neighbors.FORWARD=
FacingDirection.isFacingAwayFromEachOther(this,b)||
(FacingDirection.isFacingAwayFromEachOther(this,b)||
(FacingDirection.isFacingEachOther(this,b)||
(b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==1));
(b.getFacingDirection()==getFacingDirection()&&b.getFacingDirection().ordinal()%2==1)))&&
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;
} else
if ((b.block instanceof Cube && block instanceof Staircase)||(b.block instanceof Staircase && block instanceof Cube)) {
Block cubeBlock = (b.block instanceof Cube)?b:this;
Block staircase = (b.block instanceof Staircase)?b:this;
neighbors.BACKWARD=b.neighbors.FORWARD=
(b.equals(staircase)&&staircase.getFacingDirection()==FacingDirection.SOUTH)||
(b.equals(cubeBlock)&&staircase.getFacingDirection()==FacingDirection.NORTH);
((b.equals(staircase)&&staircase.getFacingDirection()==FacingDirection.SOUTH)||
(b.equals(cubeBlock)&&staircase.getFacingDirection()==FacingDirection.NORTH))&&
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;
} else {
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;
}

@ -52,7 +52,6 @@ public class Cube extends Mesh{
if (!b.neighbors.FORWARD) {
tris.add(b.block.triangles.get(4));
tris.add(b.block.triangles.get(5));
System.out.println("No forward neighbor.");
}
if (!b.neighbors.BACKWARD) {
tris.add(b.block.triangles.get(0));

@ -33,7 +33,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
public static boolean WIREFRAME = false;
public static boolean PROFILING = false;
public static boolean FLYING_MODE = true;
public static boolean FLYING_MODE = false;
public static int SCREEN_WIDTH=1280;
public static int SCREEN_HEIGHT=720;
public final static long TIMEPERTICK = 16666667l;
@ -315,7 +315,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
BlockDefinition bl = null;
switch (selectedMode) {
case 1:{
bl = new BlockDefinition(Staircase.class,BlockType.PLANKS);
bl = new BlockDefinition(Staircase.class,BlockType.ICE);
}break;
default:{
bl = new BlockDefinition(Cube.class,BlockType.DIRT);
@ -391,8 +391,8 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
SigRenderer(JFrame f) {
//cube = new Mesh(OBJReader.ReadOBJFile("teapot.obj",false));
Random r = new Random(438107);
for (int x=0;x<1;x++) {
for (int z=0;z<1;z++) {
for (int x=0;x<64;x++) {
for (int z=0;z<64;z++) {
addBlock(new Vector(x,0,z),Cube.class,BlockType.GRASS,FacingDirection.SOUTH);
//addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH);
//addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH);
@ -420,7 +420,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
}*/
}
}
addBlock(new Vector(31,1,31),Staircase.class,BlockType.PLANKS,FacingDirection.NORTH);
addBlock(new Vector(31,1,31),Staircase.class,BlockType.ICE,FacingDirection.NORTH);
/*addBlock(new Vector(31,2,32),Staircase.class,BlockType.PLANKS,FacingDirection.EAST);
addBlock(new Vector(31,3,33),Staircase.class,BlockType.PLANKS,FacingDirection.WEST);
addBlock(new Vector(31,4,34),Staircase.class,BlockType.PLANKS,FacingDirection.SOUTH);

Loading…
Cancel
Save