Handle clicking through transparent blocks.

origin
Joshua Sigona 3 years ago
parent 91d94cc249
commit e5e42d4f88
  1. 3
      src/sig/Panel.java
  2. 2
      src/sig/SigRenderer.java
  3. 22
      src/sig/utils/DrawUtils.java

@ -80,6 +80,7 @@ public class Panel extends JPanel implements Runnable {
SigRenderer.depthBuffer = new float[width*height]; SigRenderer.depthBuffer = new float[width*height];
SigRenderer.depthBuffer_tri = new Triangle[width*height]; SigRenderer.depthBuffer_tri = new Triangle[width*height];
SigRenderer.translucencyBuffer = new boolean[width*height]; SigRenderer.translucencyBuffer = new boolean[width*height];
SigRenderer.depthBuffer_noTransparency = new float[width*height];
} }
/** /**
* Do your draws in here !! * Do your draws in here !!
@ -101,6 +102,7 @@ public class Panel extends JPanel implements Runnable {
SigRenderer.depthBuffer[x+y*width]=0; SigRenderer.depthBuffer[x+y*width]=0;
SigRenderer.depthBuffer_tri[x+y*width]=null; SigRenderer.depthBuffer_tri[x+y*width]=null;
SigRenderer.translucencyBuffer[x+y*width]=false; SigRenderer.translucencyBuffer[x+y*width]=false;
SigRenderer.depthBuffer_noTransparency[x+y*width]=0;
} }
} }
@ -223,6 +225,7 @@ public class Panel extends JPanel implements Runnable {
} else { } else {
tt.unmodifiedTri.nextRenderTime2=System.currentTimeMillis()+200; tt.unmodifiedTri.nextRenderTime2=System.currentTimeMillis()+200;
} }
SigRenderer.temp_request=SigRenderer.request;
DrawUtils.TexturedTriangle(p, DrawUtils.TexturedTriangle(p,
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w, (int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w,
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w, (int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w,

@ -51,6 +51,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
public static float[] depthBuffer; public static float[] depthBuffer;
public static Triangle[] depthBuffer_tri; public static Triangle[] depthBuffer_tri;
public static float[] depthBuffer_noTransparency;
public static boolean[] translucencyBuffer; public static boolean[] translucencyBuffer;
public static HashMap<TextureType,Texture> blockTextures = new HashMap<TextureType,Texture>(); public static HashMap<TextureType,Texture> blockTextures = new HashMap<TextureType,Texture>();
@ -59,6 +60,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
aHeld=false,sHeld=false,dHeld=false,wHeld=false; aHeld=false,sHeld=false,dHeld=false,wHeld=false;
public static MouseEvent request; public static MouseEvent request;
public static MouseEvent temp_request;
public static MouseHandler answer; public static MouseHandler answer;
public static MouseHandler tempAnswer = null; public static MouseHandler tempAnswer = null;

@ -92,10 +92,15 @@ public class DrawUtils {
tex_u=(1.0f-t)*tex_su+t*tex_eu; tex_u=(1.0f-t)*tex_su+t*tex_eu;
tex_v=(1.0f-t)*tex_sv+t*tex_ev; tex_v=(1.0f-t)*tex_sv+t*tex_ev;
tex_w=(1.0f-t)*tex_sw+t*tex_ew; tex_w=(1.0f-t)*tex_sw+t*tex_ew;
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) { if (SigRenderer.temp_request!=null) {
if (SigRenderer.request!=null&&j==SigRenderer.request.getX()&&i==SigRenderer.request.getY()) { if (tex_w>SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]) {
SigRenderer.tempAnswer=new MouseHandler(SigRenderer.request,ref.b); 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);
}
} }
}
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) {
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f); int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
if (((col&0xFF000000)>>>24)!=0) { if (((col&0xFF000000)>>>24)!=0) {
if (((col&0xFF000000)>>>24)!=255) { if (((col&0xFF000000)>>>24)!=255) {
@ -163,10 +168,15 @@ public class DrawUtils {
tex_u=(1.0f-t)*tex_su+t*tex_eu; tex_u=(1.0f-t)*tex_su+t*tex_eu;
tex_v=(1.0f-t)*tex_sv+t*tex_ev; tex_v=(1.0f-t)*tex_sv+t*tex_ev;
tex_w=(1.0f-t)*tex_sw+t*tex_ew; tex_w=(1.0f-t)*tex_sw+t*tex_ew;
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) { if (SigRenderer.temp_request!=null) {
if (SigRenderer.request!=null&&j==SigRenderer.request.getX()&&i==SigRenderer.request.getY()) { if (tex_w>SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]) {
SigRenderer.tempAnswer=new MouseHandler(SigRenderer.request,ref.b); 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);
}
} }
}
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) {
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f); int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
if (((col&0xFF000000)>>>24)!=0) { if (((col&0xFF000000)>>>24)!=0) {
if (((col&0xFF000000)>>>24)!=255) { if (((col&0xFF000000)>>>24)!=255) {

Loading…
Cancel
Save