Make sure untextured surfaces still read properly.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
origin
sigonasr2, Sig, Sigo 3 years ago
parent fb007ad472
commit 16e2b942bb
  1. 27
      src/sig/Panel.java
  2. 4
      src/sig/SigRenderer.java
  3. 21
      src/sig/utils/OBJReader.java

@ -106,7 +106,9 @@ public class Panel extends JPanel implements Runnable {
for (Triangle t : SigRenderer.triRender) {
Triangle triProjected = new Triangle(),triTransformed=new Triangle(),triViewed=new Triangle();
matWorld = Matrix.MakeTranslation(t.b.pos.x,t.b.pos.y,t.b.pos.z);
if (t.b!=null) {
matWorld = Matrix.MakeTranslation(t.b.pos.x,t.b.pos.y,t.b.pos.z);
}
triTransformed.A = Matrix.MultiplyVector(matWorld,t.A);
triTransformed.B = Matrix.MultiplyVector(matWorld,t.B);
@ -127,25 +129,32 @@ public class Panel extends JPanel implements Runnable {
Vector cameraRay = Vector.subtract(triTransformed.A,SigRenderer.vCamera);
if (Vector.dotProduct(normal,cameraRay)<0) {
/*Vector lightDir = Vector.multiply(SigRenderer.vLookDir, -1);
lightDir = Vector.normalize(lightDir);*/
Vector lightDir = Vector.multiply(SigRenderer.vLookDir, -1);
lightDir = Vector.normalize(lightDir);
//System.out.println(-Vector.dotProduct(normal,Vector.normalize(cameraRay)));
//float dp = Math.max(0.1f,Math.min(1,-1/Vector.dotProduct(normal,cameraRay)));
float dp = 0.1f;
if (t.b!=null) {
dp = Math.max(0.1f,Math.min(1,(1f/((triTransformed.b.pos.x-SigRenderer.vCamera.x)*(triTransformed.b.pos.x-SigRenderer.vCamera.x)+
(triTransformed.b.pos.y-SigRenderer.vCamera.y)*(triTransformed.b.pos.y-SigRenderer.vCamera.y)+
(triTransformed.b.pos.z-SigRenderer.vCamera.z)*(triTransformed.b.pos.z-SigRenderer.vCamera.z))*4)));
} else {
dp = Math.max(0.1f,Vector.dotProduct(lightDir,normal));
}
/*Vector center = Vector.divide(Vector.add(triTransformed.A,Vector.add(triTransformed.B,triTransformed.C)),3);
Vector cameraRay2 = Vector.subtract(center,SigRenderer.vCamera);
float dp = Math.max(0.1f,Math.min(1,(1f/((cameraRay2.x-center.x)*(cameraRay2.x-center.x)+
(cameraRay2.y-center.y)*(cameraRay2.y-center.y)+
(cameraRay2.z-center.z)*(cameraRay2.z-center.z))*4)));*/
float dp = Math.max(0.1f,Math.min(1,(1f/((triTransformed.b.pos.x-SigRenderer.vCamera.x)*(triTransformed.b.pos.x-SigRenderer.vCamera.x)+
/*float dp = Math.max(0.1f,Math.min(1,(1f/((triTransformed.b.pos.x-SigRenderer.vCamera.x)*(triTransformed.b.pos.x-SigRenderer.vCamera.x)+
(triTransformed.b.pos.y-SigRenderer.vCamera.y)*(triTransformed.b.pos.y-SigRenderer.vCamera.y)+
(triTransformed.b.pos.z-SigRenderer.vCamera.z)*(triTransformed.b.pos.z-SigRenderer.vCamera.z))*4)));
(triTransformed.b.pos.z-SigRenderer.vCamera.z)*(triTransformed.b.pos.z-SigRenderer.vCamera.z))*4)));*/
triViewed.A = Matrix.MultiplyVector(matView,triTransformed.A);
triViewed.B = Matrix.MultiplyVector(matView,triTransformed.B);
triViewed.C = Matrix.MultiplyVector(matView,triTransformed.C);
triTransformed.copyExtraDataTo(triViewed);
triViewed.setColor(new Color(dp,dp,dp));
triViewed.setColor(new Color(dp,0,0));
int clippedTriangles = 0;
Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()};
@ -203,14 +212,14 @@ public class Panel extends JPanel implements Runnable {
}
}
/*Collections.sort(accumulatedTris, new Comparator<Triangle>() {
Collections.sort(accumulatedTris, new Comparator<Triangle>() {
@Override
public int compare(Triangle t1, Triangle t2) {
float z1=(t1.A.z+t1.B.z+t1.C.z)/3f;
float z2=(t2.A.z+t2.B.z+t2.C.z)/3f;
return (z1<z2)?1:(z1==z2)?0:-1;
}
});*/
});
for (Triangle t : accumulatedTris) {
Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()};

@ -112,7 +112,9 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
//cube = new Mesh(OBJReader.ReadOBJFile("teapot.obj",false));
for (int x=0;x<16;x++) {
for (int z=0;z<16;z++) {
addBlock(new Vector(x,0,z),DIRT_CUBE);
for (int y=0;y<16;y++) {
addBlock(new Vector(x,y,z),DIRT_CUBE);
}
}
}

@ -52,19 +52,22 @@ public class OBJReader {
texs.get(Integer.parseInt(spl3[1])-1)[1]));
tris.add(tri);
} else {
String[] spl1=split[1].split(Pattern.quote("/"));
String[] spl2=split[2].split(Pattern.quote("/"));
String[] spl3=split[3].split(Pattern.quote("/"));
Triangle tri = new Triangle(
new Vector(
vertices.get(Integer.parseInt(split[1])-1)[0],
vertices.get(Integer.parseInt(split[1])-1)[1],
vertices.get(Integer.parseInt(split[1])-1)[2]),
vertices.get(Integer.parseInt(spl1[0])-1)[0],
vertices.get(Integer.parseInt(spl1[0])-1)[1],
vertices.get(Integer.parseInt(spl1[0])-1)[2]),
new Vector(
vertices.get(Integer.parseInt(split[2])-1)[0],
vertices.get(Integer.parseInt(split[2])-1)[1],
vertices.get(Integer.parseInt(split[2])-1)[2]),
vertices.get(Integer.parseInt(spl2[0])-1)[0],
vertices.get(Integer.parseInt(spl2[0])-1)[1],
vertices.get(Integer.parseInt(spl2[0])-1)[2]),
new Vector(
vertices.get(Integer.parseInt(split[3])-1)[0],
vertices.get(Integer.parseInt(split[3])-1)[1],
vertices.get(Integer.parseInt(split[3])-1)[2]));
vertices.get(Integer.parseInt(spl3[0])-1)[0],
vertices.get(Integer.parseInt(spl3[0])-1)[1],
vertices.get(Integer.parseInt(spl3[0])-1)[2]));
tris.add(tri);
}
}

Loading…
Cancel
Save