diff --git a/src/sig/Block.java b/src/sig/Block.java index da5130d..cd47902 100644 --- a/src/sig/Block.java +++ b/src/sig/Block.java @@ -44,4 +44,8 @@ public class Block { SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).neighbors.FORWARD=true; } } + @Override + public String toString() { + return "Block [pos=" + pos + ", neighbors=" + neighbors + "]"; + } } diff --git a/src/sig/Panel.java b/src/sig/Panel.java index 65cc6da..86154d6 100644 --- a/src/sig/Panel.java +++ b/src/sig/Panel.java @@ -218,6 +218,7 @@ public class Panel extends JPanel implements Runnable { return (z1>16); + tt.tex,(tt.col&0xFF0000)>>16,tt); } else { DrawUtils.FillTriangle(p,(int)tt.A.x,(int)tt.A.y,(int)tt.B.x,(int)tt.B.y,(int)tt.C.x,(int)tt.C.y,tt.getColor()); } @@ -258,6 +259,8 @@ public class Panel extends JPanel implements Runnable { } } } + SigRenderer.request=null; + SigRenderer.answer=SigRenderer.tempAnswer; } public void repaint() { diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index 239fb5d..6bb1172 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -50,8 +50,6 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene final float MOVESPEED = 0.2f; final float TURNSPEED = 0.2f; - public static Texture dirtTex; - public static float[] depthBuffer; public static Mesh DIRT_CUBE=new Mesh("cube.obj","dirt.png"); @@ -59,7 +57,9 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene boolean upHeld=false,downHeld=false,leftHeld=false,rightHeld=false, aHeld=false,sHeld=false,dHeld=false,wHeld=false; - public static MouseEvent storedMouseEvent; + public static MouseEvent request; + public static Block answer; + public static Block tempAnswer = null; public void runGameLoop() { if (upHeld) { @@ -89,6 +89,10 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene if (dHeld) { yaw+=TURNSPEED; } + if (answer!=null) { + System.out.println(answer); + answer=null; + } } public static void addBlock(Vector pos,Mesh type) { @@ -167,11 +171,12 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene @Override public void mouseClicked(MouseEvent e) { - storedMouseEvent=e; } @Override public void mousePressed(MouseEvent e) { + request=e; + answer=null; } @Override diff --git a/src/sig/Triangle.java b/src/sig/Triangle.java index 71a4e5e..a3ad649 100644 --- a/src/sig/Triangle.java +++ b/src/sig/Triangle.java @@ -5,7 +5,7 @@ public class Triangle { Vector A,B,C; Vector2 T,U,V; int col = Color.WHITE.getRGB(); - Block b = null; + public Block b = null; public Texture tex = null; public Triangle() { this(new Vector(),new Vector(),new Vector()); diff --git a/src/sig/utils/DrawUtils.java b/src/sig/utils/DrawUtils.java index c8108d6..f644414 100644 --- a/src/sig/utils/DrawUtils.java +++ b/src/sig/utils/DrawUtils.java @@ -6,6 +6,7 @@ import java.awt.image.BufferedImage; import sig.SigRenderer; import sig.Texture; +import sig.Triangle; public class DrawUtils { static void drawLine(int[] canvas,int sx,int ex,int ny,int col) { @@ -17,7 +18,7 @@ public class DrawUtils { int x1, int y1, float u1,float v1,float w1, int x2, int y2, float u2,float v2,float w2, int x3, int y3, float u3,float v3,float w3, - Texture texture, int colorMult + Texture texture, int colorMult,Triangle ref ) { if (y2SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) { + if (SigRenderer.request!=null&&j==SigRenderer.request.getX()&&i==SigRenderer.request.getY()) { + SigRenderer.tempAnswer=ref.b; + } Draw(canvas,j,i,texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f)); SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; } @@ -132,6 +136,9 @@ public class DrawUtils { tex_v=(1.0f-t)*tex_sv+t*tex_ev; tex_w=(1.0f-t)*tex_sw+t*tex_ew; if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) { + if (SigRenderer.request!=null&&j==SigRenderer.request.getX()&&i==SigRenderer.request.getY()) { + SigRenderer.tempAnswer=ref.b; + } Draw(canvas,j,i,texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f)); SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; }