diff --git a/src/sig/Cube.java b/src/sig/Cube.java index c3d1431..29cf7f1 100644 --- a/src/sig/Cube.java +++ b/src/sig/Cube.java @@ -9,16 +9,22 @@ public class Cube extends Mesh{ 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(0).dir=triangles.get(1).dir=BlockType.FRONT; triangles.get(2).tex=type.getTexture(BlockType.RIGHT); triangles.get(3).tex=type.getTexture(BlockType.RIGHT); + triangles.get(2).dir=triangles.get(3).dir=BlockType.RIGHT; triangles.get(4).tex=type.getTexture(BlockType.BACK); triangles.get(5).tex=type.getTexture(BlockType.BACK); + triangles.get(4).dir=triangles.get(5).dir=BlockType.BACK; triangles.get(6).tex=type.getTexture(BlockType.LEFT); triangles.get(7).tex=type.getTexture(BlockType.LEFT); + triangles.get(6).dir=triangles.get(7).dir=BlockType.LEFT; triangles.get(8).tex=type.getTexture(BlockType.TOP); triangles.get(9).tex=type.getTexture(BlockType.TOP); + triangles.get(8).dir=triangles.get(9).dir=BlockType.TOP; triangles.get(10).tex=type.getTexture(BlockType.BOTTOM); triangles.get(11).tex=type.getTexture(BlockType.BOTTOM); + triangles.get(10).dir=triangles.get(11).dir=BlockType.BOTTOM; } } diff --git a/src/sig/MouseHandler.java b/src/sig/MouseHandler.java index 634c584..4d87937 100644 --- a/src/sig/MouseHandler.java +++ b/src/sig/MouseHandler.java @@ -4,9 +4,9 @@ import java.awt.event.MouseEvent; public class MouseHandler { public MouseEvent e; - public Block b; - public MouseHandler(MouseEvent e,Block b) { + public Triangle t; + public MouseHandler(MouseEvent e,Triangle t) { this.e=e; - this.b=b; + this.t=t; } } diff --git a/src/sig/Panel.java b/src/sig/Panel.java index e7a81d9..fc5b9ee 100644 --- a/src/sig/Panel.java +++ b/src/sig/Panel.java @@ -396,6 +396,7 @@ public class Panel extends JPanel implements Runnable { triTransformed.tex = t.tex; triTransformed.b=t.b; triTransformed.unmodifiedTri=t; + triTransformed.dir=t.dir; Vector normal=new Vector(),line1=new Vector(),line2=new Vector(); line1 = Vector.subtract(triTransformed.B,triTransformed.A); @@ -458,6 +459,7 @@ public class Panel extends JPanel implements Runnable { triProjected.V = (Vector2)clipped[i].V.clone(); triProjected.b=clipped[i].b; triProjected.unmodifiedTri=clipped[i].unmodifiedTri; + triProjected.dir=clipped[i].dir; triProjected.T.u = triProjected.T.u/triProjected.A.w; triProjected.U.u = triProjected.U.u/triProjected.B.w; diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index ed80075..0c3e44e 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -94,10 +94,29 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene } if (answer!=null) { if (answer.e.getButton()==MouseEvent.BUTTON1) { - addBlock(Vector.add(answer.b.pos,new Vector(0,1,0)),BlockType.PLANKS); + switch (answer.t.dir) { + case BlockType.FRONT:{ + addBlock(Vector.add(answer.t.b.pos,new Vector(0,0,-1)),BlockType.PLANKS); + }break; + case BlockType.BACK:{ + addBlock(Vector.add(answer.t.b.pos,new Vector(0,0,1)),BlockType.PLANKS); + }break; + case BlockType.LEFT:{ + addBlock(Vector.add(answer.t.b.pos,new Vector(-1,0,0)),BlockType.PLANKS); + }break; + case BlockType.RIGHT:{ + addBlock(Vector.add(answer.t.b.pos,new Vector(1,0,0)),BlockType.PLANKS); + }break; + case BlockType.TOP:{ + addBlock(Vector.add(answer.t.b.pos,new Vector(0,1,0)),BlockType.PLANKS); + }break; + case BlockType.BOTTOM:{ + addBlock(Vector.add(answer.t.b.pos,new Vector(0,-1,0)),BlockType.PLANKS); + }break; + } } else if (answer.e.getButton()==MouseEvent.BUTTON3) { - removeBlock(answer.b.pos); + removeBlock(answer.t.b.pos); } answer=null; } diff --git a/src/sig/Triangle.java b/src/sig/Triangle.java index cb95c9b..8e12efd 100644 --- a/src/sig/Triangle.java +++ b/src/sig/Triangle.java @@ -10,6 +10,7 @@ public class Triangle { public long nextRenderTime = -1l; public long nextRenderTime2 = -1l; public Triangle unmodifiedTri; + public int dir = -1; public Triangle() { this(new Vector(),new Vector(),new Vector()); } @@ -32,6 +33,7 @@ public class Triangle { targetTriangle.tex=this.tex; targetTriangle.b=this.b; targetTriangle.unmodifiedTri=this.unmodifiedTri; + targetTriangle.dir=this.dir; } @Override protected Object clone(){ @@ -40,12 +42,12 @@ public class Triangle { t.tex=tex; t.b=b; t.unmodifiedTri=unmodifiedTri; + t.dir=dir; return t; } @Override public String toString() { - return "Triangle [A=" + A + ", B=" + B + ", C=" + C + ", T=" + T + ", U=" + U + ", V=" + V + ", col=" + col - + "]"; + return "Triangle [A=" + A + ", B=" + B + ", C=" + C + ", T=" + T + ", U=" + U + ", V=" + V + ", col=" + col + ", dir=" + dir + "]"; } public int getColor() { return col; @@ -106,6 +108,7 @@ public class Triangle { out_tri[0].tex = in.tex; out_tri[0].b=in.b; out_tri[0].unmodifiedTri=in.unmodifiedTri; + out_tri[0].dir=in.dir; out_tri[0].A = inside_points[0]; out_tri[0].T = inside_tex[0]; out_tri[0].B = Vector.IntersectPlane(plane_p, plane_n, inside_points[0], outside_points[0],t); @@ -123,6 +126,7 @@ public class Triangle { out_tri[0].col=out_tri[1].col=in.col; out_tri[0].tex=out_tri[1].tex=in.tex; out_tri[0].b=out_tri[1].b=in.b; + out_tri[0].dir=out_tri[1].dir=in.dir; out_tri[0].unmodifiedTri=out_tri[1].unmodifiedTri=in.unmodifiedTri; out_tri[0].A = inside_points[0]; out_tri[0].B = inside_points[1]; diff --git a/src/sig/utils/DrawUtils.java b/src/sig/utils/DrawUtils.java index 0570b04..ae9fa95 100644 --- a/src/sig/utils/DrawUtils.java +++ b/src/sig/utils/DrawUtils.java @@ -96,7 +96,7 @@ public class DrawUtils { if (tex_w>SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]) { SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]=tex_w; if (j==SigRenderer.temp_request.getX()&&i==SigRenderer.temp_request.getY()) { - SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref.b); + SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref); } } } @@ -172,7 +172,7 @@ public class DrawUtils { if (tex_w>SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]) { SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]=tex_w; if (j==SigRenderer.temp_request.getX()&&i==SigRenderer.temp_request.getY()) { - SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref.b); + SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref); } } }