Setup kernel for full triangles.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 3 years ago
parent 498539a09e
commit 331097648e
  1. 4
      src/sig/Panel.java
  2. 33
      src/sig/RenderKernel.java
  3. 39
      src/sig/SigKeeper.java
  4. 17
      src/sig/Triangle.java
  5. 8
      src/sig/Vector.java
  6. 19
      src/sig/Vector2.java

@ -38,8 +38,8 @@ public class Panel extends JPanel implements Runnable {
return gfx_config.getColorModel();
}
public void init(){
triPoints = new float[12*5000];
public void init(){
triPoints = new float[21*1];
cm = getCompatibleColorModel();
width = getWidth();
height = getHeight();

@ -23,16 +23,31 @@ public class RenderKernel extends Kernel{
@Override
public void run() {
int id = getGlobalId();
int x1=(int)tris[id*12+0];
int y1=(int)tris[id*12+1];
int x2=(int)tris[id*12+4];
int y2=(int)tris[id*12+5];
int x3=(int)tris[id*12+8];
int y3=(int)tris[id*12+9];
float x1=tris[id*21+0];
float y1=tris[id*21+1];
float z1=tris[id*21+2];
float w1=tris[id*21+3];
float x2=tris[id*21+4];
float y2=tris[id*21+5];
float z2=tris[id*21+6];
float w2=tris[id*21+7];
float x3=tris[id*21+8];
float y3=tris[id*21+9];
float z3=tris[id*21+10];
float w3=tris[id*21+11];
float Tu1=tris[id*21+12];
float Tv1=tris[id*21+13];
float Tw1=tris[id*21+14];
float Uu2=tris[id*21+15];
float Uv2=tris[id*21+16];
float Uw2=tris[id*21+17];
float Vu3=tris[id*21+18];
float Vv3=tris[id*21+19];
float Vw3=tris[id*21+20];
TexturedTriangle(
x1,y1,0f,0f,1f,
x2,y2,1f,0f,1f,
x3,y3,1f,1f,1f,
(int)x1,(int)y1,0f,0f,1f,
(int)x2,(int)y2,1f,0f,1f,
(int)x3,(int)y3,1f,1f,1f,
getGlobalId()%256,1f);
}

@ -75,26 +75,35 @@ public class SigKeeper implements WindowFocusListener,KeyListener,MouseListener,
panel.init();
for (int i=0;i<Panel.triPoints.length/12;i++) {
tris.add(new Triangle(new Vertex((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100),
new Vertex((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100),
new Vertex((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100)));
tris.add(new Triangle(new Vector((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100),
new Vector((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100),
new Vector((float)Math.random()*SCREEN_WIDTH,(float)Math.random()*SCREEN_HEIGHT,(float)Math.random()*100)));
}
/*tris.add(new Triangle(new Vertex(50,300,100),new Vertex(300,300,100),new Vertex(50,100,100)));
tris.add(new Triangle(new Vertex(300,300,100),new Vertex(300,100,100),new Vertex(50,100,100)));*/
for (int i=0;i<SigKeeper.tris.size();i++) {
Triangle t = SigKeeper.tris.get(i);
Panel.triPoints[i*12+0]=t.A.x;
Panel.triPoints[i*12+1]=t.A.y;
Panel.triPoints[i*12+2]=t.A.z;
Panel.triPoints[i*12+3]=t.A.w;
Panel.triPoints[i*12+4]=t.B.x;
Panel.triPoints[i*12+5]=t.B.y;
Panel.triPoints[i*12+6]=t.B.z;
Panel.triPoints[i*12+7]=t.B.w;
Panel.triPoints[i*12+8]=t.C.x;
Panel.triPoints[i*12+9]=t.C.y;
Panel.triPoints[i*12+10]=t.C.z;
Panel.triPoints[i*12+11]=t.C.w;
Panel.triPoints[i*21+0]=t.A.x;
Panel.triPoints[i*21+1]=t.A.y;
Panel.triPoints[i*21+2]=t.A.z;
Panel.triPoints[i*21+3]=t.A.w;
Panel.triPoints[i*21+4]=t.B.x;
Panel.triPoints[i*21+5]=t.B.y;
Panel.triPoints[i*21+6]=t.B.z;
Panel.triPoints[i*21+7]=t.B.w;
Panel.triPoints[i*21+8]=t.C.x;
Panel.triPoints[i*21+9]=t.C.y;
Panel.triPoints[i*21+10]=t.C.z;
Panel.triPoints[i*21+11]=t.C.w;
Panel.triPoints[i*21+12]=t.T.u;
Panel.triPoints[i*21+13]=t.T.v;
Panel.triPoints[i*21+14]=t.T.w;
Panel.triPoints[i*21+15]=t.U.u;
Panel.triPoints[i*21+16]=t.U.v;
Panel.triPoints[i*21+17]=t.U.w;
Panel.triPoints[i*21+18]=t.V.u;
Panel.triPoints[i*21+19]=t.V.v;
Panel.triPoints[i*21+20]=t.V.w;
}
new Thread() {

@ -1,12 +1,21 @@
package sig;
public class Triangle {
Vertex A;
Vertex B;
Vertex C;
public Triangle(Vertex a, Vertex b, Vertex c) {
Vector A;
Vector B;
Vector C;
Vector2 T;
Vector2 U;
Vector2 V;
public Triangle(Vector a, Vector b, Vector c) {
this(a,b,c,new Vector2(),new Vector2(),new Vector2());
}
public Triangle(Vector a, Vector b, Vector c, Vector2 t, Vector2 u, Vector2 v) {
A = a;
B = b;
C = c;
T = t;
U = u;
V = v;
}
}

@ -1,17 +1,17 @@
package sig;
public class Vertex {
public class Vector {
float x,y,z,w;
public Vertex() {
public Vector() {
this(0,0,0,1);
}
public Vertex(float x, float y, float z) {
public Vector(float x, float y, float z) {
this(x,y,z,1);
}
public Vertex(float x, float y, float z,float w) {
public Vector(float x, float y, float z,float w) {
this.x = x;
this.y = y;
this.z = z;

@ -0,0 +1,19 @@
package sig;
public class Vector2 {
float u,v,w;
public Vector2() {
this(0,0,1);
}
public Vector2(float u, float v) {
this(u,v,1);
}
public Vector2(float y, float v, float w) {
this.u=u;
this.v=v;
this.w=w;
}
}
Loading…
Cancel
Save