diff --git a/cube.obj b/cube.obj index 12dbf6e..cde9df7 100644 --- a/cube.obj +++ b/cube.obj @@ -12,15 +12,15 @@ vt 0 1 #2 vt 1 0 #3 vt 1 1 #4 -f 1/2 3/1 7/3 +f 1/2 3/1 7/3 #South f 1/2 7/3 5/4 -f 5/2 7/1 8/3 +f 5/2 7/1 8/3 #East f 5/2 8/3 6/4 -f 6/2 8/1 4/3 +f 6/2 8/1 4/3 #North f 6/2 4/3 2/4 -f 2/2 4/1 3/3 +f 2/2 4/1 3/3 #West f 2/2 3/3 1/4 -f 3/2 4/1 8/3 +f 3/2 4/1 8/3 #Top f 3/2 8/3 7/4 -f 6/2 2/1 1/3 +f 6/2 2/1 1/3 #Bottom f 6/2 1/3 5/4 \ No newline at end of file diff --git a/src/sig/BlockType.java b/src/sig/BlockType.java index e1eed97..562c639 100644 --- a/src/sig/BlockType.java +++ b/src/sig/BlockType.java @@ -222,4 +222,8 @@ public enum BlockType { sides[RIGHT]=sideRight; sides[LEFT]=sideLeft; } + + public Texture getTexture(int side) { + return SigRenderer.blockTextures.get(sides[side]); + } } diff --git a/src/sig/Cube.java b/src/sig/Cube.java new file mode 100644 index 0000000..c3d1431 --- /dev/null +++ b/src/sig/Cube.java @@ -0,0 +1,24 @@ +package sig; + +import sig.utils.OBJReader; + +public class Cube extends Mesh{ + + Cube(BlockType type) { + super(type); + this.triangles=OBJReader.ReadOBJFile("cube.obj",true); + triangles.get(0).tex=type.getTexture(BlockType.FRONT); + triangles.get(1).tex=type.getTexture(BlockType.FRONT); + triangles.get(2).tex=type.getTexture(BlockType.RIGHT); + triangles.get(3).tex=type.getTexture(BlockType.RIGHT); + triangles.get(4).tex=type.getTexture(BlockType.BACK); + triangles.get(5).tex=type.getTexture(BlockType.BACK); + triangles.get(6).tex=type.getTexture(BlockType.LEFT); + triangles.get(7).tex=type.getTexture(BlockType.LEFT); + triangles.get(8).tex=type.getTexture(BlockType.TOP); + triangles.get(9).tex=type.getTexture(BlockType.TOP); + triangles.get(10).tex=type.getTexture(BlockType.BOTTOM); + triangles.get(11).tex=type.getTexture(BlockType.BOTTOM); + } + +} diff --git a/src/sig/Mesh.java b/src/sig/Mesh.java index d733cbf..f6115ef 100644 --- a/src/sig/Mesh.java +++ b/src/sig/Mesh.java @@ -21,4 +21,6 @@ public class Mesh { t.tex=te; } } + Mesh(BlockType type) {; + } } diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index 6bb1172..fbaab4b 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -7,7 +7,10 @@ import sig.utils.OBJReader; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.awt.image.BufferedImage; +import java.awt.image.WritableRaster; import java.io.File; +import java.io.IOException; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.ArrayList; @@ -48,11 +51,11 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene public static float roll = 0; final float MOVESPEED = 0.2f; - final float TURNSPEED = 0.2f; + final float TURNSPEED = 0.05f; public static float[] depthBuffer; - public static Mesh DIRT_CUBE=new Mesh("cube.obj","dirt.png"); + public static HashMap blockTextures = new HashMap(); boolean upHeld=false,downHeld=false,leftHeld=false,rightHeld=false, aHeld=false,sHeld=false,dHeld=false,wHeld=false; @@ -63,10 +66,10 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene public void runGameLoop() { if (upHeld) { - pitch+=MOVESPEED; + pitch+=TURNSPEED; } if (downHeld) { - pitch-=MOVESPEED; + pitch-=TURNSPEED; } if (rightHeld) { roll-=MOVESPEED; @@ -95,8 +98,8 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene } } - public static void addBlock(Vector pos,Mesh type) { - Block b = new Block(pos,type); + public static void addBlock(Vector pos,BlockType type) { + Block b = new Block(pos,new Cube(type)); blockGrid.put(pos.x+"_"+pos.y+"_"+pos.z,b); b.updateFaces(); updateRenderGrid(); @@ -120,8 +123,10 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene Random r = new Random(438107); for (int x=0;x<32;x++) { for (int z=0;z<32;z++) { - for (int y=0;y