Fix texel code.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
9bba62bd7a
commit
14012b09d3
@ -266,10 +266,10 @@ public class Panel extends JPanel implements Runnable {
|
||||
}
|
||||
SigRenderer.temp_request=SigRenderer.request;
|
||||
DrawUtils.TexturedTriangle(p,
|
||||
tt.A.x,tt.A.y,tt.T.u,tt.T.v,tt.T.w,
|
||||
tt.B.x,tt.B.y,tt.U.u,tt.U.v,tt.U.w,
|
||||
tt.C.x,tt.C.y,tt.V.u,tt.V.v,tt.V.w,
|
||||
tt.tex,(tt.col&0xFF0000)>>16,tt,1);
|
||||
(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.C.x,(int)tt.C.y,tt.V.u,tt.V.v,tt.V.w,
|
||||
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());
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class DrawUtils {
|
||||
Draw(canvas,i,ny,col);
|
||||
}
|
||||
}
|
||||
public static void TexturedTriangle(int[] canvas,
|
||||
/* public static void TexturedTriangle(int[] canvas,
|
||||
float x1, float y1, float u1,float v1,float w1,
|
||||
float x2, float y2, float u2,float v2,float w2,
|
||||
float x3, float y3, float u3,float v3,float w3,
|
||||
@ -209,7 +209,7 @@ public class DrawUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
private static boolean CheckAllTexels(float tex_w, float[] buffer, int pixelIndex, int texelSize) {
|
||||
for (int x=0;x<texelSize;x++) {
|
||||
for (int y=0;y<texelSize;y++) {
|
||||
@ -241,6 +241,197 @@ public class DrawUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void TexturedTriangle(int[] canvas,
|
||||
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,Triangle ref) {
|
||||
TexturedTriangle(canvas,x1,y1,u1,v1,w1,x2,y2,u2,v2,w2,x3,y3,u3,v3,w3,texture,colorMult,ref,NORMAL_RENDERING,1);
|
||||
}
|
||||
public static void TexturedTriangle(int[] canvas,
|
||||
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,Triangle ref,int texelSize) {
|
||||
TexturedTriangle(canvas,x1,y1,u1,v1,w1,x2,y2,u2,v2,w2,x3,y3,u3,v3,w3,texture,colorMult,ref,NORMAL_RENDERING,texelSize);
|
||||
}
|
||||
public static void TexturedTriangle(int[] canvas,
|
||||
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,Triangle ref,
|
||||
int rendering_state,int texelSize) {
|
||||
if (y2<y1) {int t=y1;y1=y2;y2=t;t=x1;x1=x2;x2=t;float u=u1;u1=u2;u2=u;float v=v1;v1=v2;v2=v;float w=w1;w1=w2;w2=w;}
|
||||
if (y3<y1) {int t=y1;y1=y3;y3=t;t=x1;x1=x3;x3=t;float u=u1;u1=u3;u3=u;float v=v1;v1=v3;v3=v;float w=w1;w1=w3;w3=w;}
|
||||
if (y3<y2) {int t=y2;y2=y3;y3=t;t=x2;x2=x3;x3=t;float u=u2;u2=u3;u3=u;float v=v2;v2=v3;v3=v;float w=w2;w2=w3;w3=w;}
|
||||
|
||||
int dy1=y2-y1;
|
||||
int dx1=x2-x1;
|
||||
float dv1=v2-v1;
|
||||
float du1=u2-u1;
|
||||
float dw1=w2-w1;
|
||||
int dy2=y3-y1;
|
||||
int dx2=x3-x1;
|
||||
float dv2=v3-v1;
|
||||
float du2=u3-u1;
|
||||
float dw2=w3-w1;
|
||||
float tex_u,tex_v,tex_w;
|
||||
|
||||
float dax_step=0,dbx_step=0,
|
||||
du1_step=0,dv1_step=0,dw1_step=0,
|
||||
du2_step=0,dv2_step=0,dw2_step=0;
|
||||
|
||||
if (dy1!=0) {dax_step=dx1/((float)Math.abs(dy1));}
|
||||
if (dy2!=0) {dbx_step=dx2/((float)Math.abs(dy2));}
|
||||
|
||||
if (dy1!=0) {du1_step=du1/((float)Math.abs(dy1));}
|
||||
if (dy1!=0) {dv1_step=dv1/((float)Math.abs(dy1));}
|
||||
if (dy1!=0) {dw1_step=dw1/((float)Math.abs(dy1));}
|
||||
if (dy2!=0) {du2_step=du2/((float)Math.abs(dy2));}
|
||||
if (dy2!=0) {dv2_step=dv2/((float)Math.abs(dy2));}
|
||||
if (dy2!=0) {dw2_step=dw2/((float)Math.abs(dy2));}
|
||||
|
||||
if (dy1!=0) {
|
||||
for (int i=y1;i<=y2-texelSize+1;i+=texelSize) {
|
||||
int ax=(int)(x1+((float)(i-y1))*dax_step);
|
||||
int bx=(int)(x1+((float)(i-y1))*dbx_step);
|
||||
|
||||
float tex_su=u1+((float)(i-y1))*du1_step;
|
||||
float tex_sv=v1+((float)(i-y1))*dv1_step;
|
||||
float tex_sw=w1+((float)(i-y1))*dw1_step;
|
||||
float tex_eu=u1+((float)(i-y1))*du2_step;
|
||||
float tex_ev=v1+((float)(i-y1))*dv2_step;
|
||||
float tex_ew=w1+((float)(i-y1))*dw2_step;
|
||||
|
||||
if (ax>bx) {
|
||||
int t=ax;ax=bx;bx=t;
|
||||
float u=tex_su;tex_su=tex_eu;tex_eu=u;
|
||||
float v=tex_sv;tex_sv=tex_ev;tex_ev=v;
|
||||
float w=tex_sw;tex_sw=tex_ew;tex_ew=w;
|
||||
}
|
||||
|
||||
tex_u=tex_su;
|
||||
tex_v=tex_sv;
|
||||
tex_w=tex_sw;
|
||||
|
||||
float tstep = 1.0f/(float)(bx-ax);
|
||||
float t=0.0f;
|
||||
|
||||
for (int j=ax;j<=bx-texelSize+1;j+=texelSize) {
|
||||
tex_u=(1.0f-t)*tex_su+t*tex_eu;
|
||||
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
|
||||
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
|
||||
int pixelIndex = (int)(i*SigRenderer.SCREEN_WIDTH+j);
|
||||
if (SigRenderer.temp_request!=null) {
|
||||
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer_noTransparency,pixelIndex,texelSize)) {
|
||||
setArrayTexels(SigRenderer.depthBuffer_noTransparency,pixelIndex,tex_w,texelSize);
|
||||
if (j==SigRenderer.temp_request.getX()&&i==SigRenderer.temp_request.getY()) {
|
||||
SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer,pixelIndex,texelSize)) {
|
||||
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
|
||||
if (((col&0xFF000000)>>>24)!=0) {
|
||||
if (((col&0xFF000000)>>>24)!=255) {
|
||||
if (rendering_state==TRANSLUCENT_ONLY_RENDERING||
|
||||
rendering_state==NORMAL_RENDERING) {
|
||||
Draw(canvas,pixelIndex,col);
|
||||
setArrayTexels(SigRenderer.depthBuffer,pixelIndex,tex_w,texelSize);
|
||||
setArrayTexels(SigRenderer.depthBuffer_tri,pixelIndex,ref.unmodifiedTri,texelSize);
|
||||
setArrayTexels(SigRenderer.translucencyBuffer,pixelIndex,true,texelSize);
|
||||
}
|
||||
} else {
|
||||
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
|
||||
Draw(canvas,pixelIndex,col);
|
||||
setArrayTexels(SigRenderer.depthBuffer,pixelIndex,tex_w,texelSize);
|
||||
setArrayTexels(SigRenderer.depthBuffer_tri,pixelIndex,ref.unmodifiedTri,texelSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
t+=tstep*texelSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dy1=y3-y2;
|
||||
dx1=x3-x2;
|
||||
dv1=v3-v2;
|
||||
du1=u3-u2;
|
||||
dw1=w3-w2;
|
||||
if (dy1!=0) {dax_step=dx1/((float)Math.abs(dy1));}
|
||||
if (dy2!=0) {dbx_step=dx2/((float)Math.abs(dy2));}
|
||||
du1_step=0f;
|
||||
dv1_step=0f;
|
||||
if (dy1!=0) {du1_step=du1/((float)Math.abs(dy1));}
|
||||
if (dy1!=0) {dv1_step=dv1/((float)Math.abs(dy1));}
|
||||
if (dy1!=0) {dw1_step=dw1/((float)Math.abs(dy1));}
|
||||
|
||||
if (dy1!=0) {
|
||||
for (int i=y2;i<=y3-texelSize+1;i+=texelSize) {
|
||||
int ax=(int)(x2+((float)(i-y2))*dax_step);
|
||||
int bx=(int)(x1+((float)(i-y1))*dbx_step);
|
||||
|
||||
float tex_su=u2+((float)(i-y2))*du1_step;
|
||||
float tex_sv=v2+((float)(i-y2))*dv1_step;
|
||||
float tex_sw=w2+((float)(i-y2))*dw1_step;
|
||||
float tex_eu=u1+((float)(i-y1))*du2_step;
|
||||
float tex_ev=v1+((float)(i-y1))*dv2_step;
|
||||
float tex_ew=w1+((float)(i-y1))*dw2_step;
|
||||
|
||||
if (ax>bx) {
|
||||
int t=ax;ax=bx;bx=t;
|
||||
float u=tex_su;tex_su=tex_eu;tex_eu=u;
|
||||
float v=tex_sv;tex_sv=tex_ev;tex_ev=v;
|
||||
float w=tex_sw;tex_sw=tex_ew;tex_ew=w;
|
||||
}
|
||||
|
||||
tex_u=tex_su;
|
||||
tex_v=tex_sv;
|
||||
tex_w=tex_sw;
|
||||
|
||||
float tstep = 1.0f/(float)(bx-ax);
|
||||
float t=0.0f;
|
||||
|
||||
for (int j=ax;j<=bx-texelSize+1;j+=texelSize) {
|
||||
tex_u=(1.0f-t)*tex_su+t*tex_eu;
|
||||
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
|
||||
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
|
||||
int pixelIndex = (int)(i*SigRenderer.SCREEN_WIDTH+j);
|
||||
if (SigRenderer.temp_request!=null) {
|
||||
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer_noTransparency,pixelIndex,texelSize)) {
|
||||
setArrayTexels(SigRenderer.depthBuffer_noTransparency,pixelIndex,tex_w,texelSize);
|
||||
if (j==SigRenderer.temp_request.getX()&&i==SigRenderer.temp_request.getY()) {
|
||||
SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer,pixelIndex,texelSize)) {
|
||||
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
|
||||
if (((col&0xFF000000)>>>24)!=0) {
|
||||
if (((col&0xFF000000)>>>24)!=255) {
|
||||
if (rendering_state==TRANSLUCENT_ONLY_RENDERING||
|
||||
rendering_state==NORMAL_RENDERING) {
|
||||
Draw(canvas,pixelIndex,col);
|
||||
setArrayTexels(SigRenderer.depthBuffer,pixelIndex,tex_w,texelSize);
|
||||
setArrayTexels(SigRenderer.depthBuffer_tri,pixelIndex,ref.unmodifiedTri,texelSize);
|
||||
setArrayTexels(SigRenderer.translucencyBuffer,pixelIndex,true,texelSize);
|
||||
}
|
||||
} else {
|
||||
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
|
||||
Draw(canvas,pixelIndex,col);
|
||||
setArrayTexels(SigRenderer.depthBuffer,pixelIndex,tex_w,texelSize);
|
||||
setArrayTexels(SigRenderer.depthBuffer_tri,pixelIndex,ref.unmodifiedTri,texelSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
t+=tstep*texelSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void FillTriangle(int[] canvas,int x1, int y1, int x2, int y2, int x3, int y3, int col)
|
||||
{
|
||||
int t1x=0, t2x=0, y=0, minx=0, maxx=0, t1xp=0, t2xp=0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user