Prepare for graphical transformations.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 3 years ago
parent 331097648e
commit bbce363a26
  1. 9
      src/sig/Panel.java
  2. 57
      src/sig/RenderKernel.java
  3. 1
      src/sig/SigKeeper.java

@ -21,7 +21,8 @@ public class Panel extends JPanel implements Runnable {
public int height=SigKeeper.SCREEN_HEIGHT;
private Image imageBuffer;
private MemoryImageSource mImageProducer;
public int[] pixel;
public static int[] pixel;
public static float[] depthBuffer;
public static float[] triPoints;
RenderKernel renderer;
@ -39,7 +40,7 @@ public class Panel extends JPanel implements Runnable {
}
public void init(){
triPoints = new float[21*1];
triPoints = new float[21*SigKeeper.MAX_TRIANGLE_COUNT];
cm = getCompatibleColorModel();
width = getWidth();
height = getHeight();
@ -48,11 +49,12 @@ public class Panel extends JPanel implements Runnable {
int screenSize = width * height;
if(pixel == null || pixel.length < screenSize){
pixel = new int[screenSize];
depthBuffer = new float[screenSize];
}
mImageProducer = new MemoryImageSource(width, height, cm, pixel,0, width);
mImageProducer.setAnimated(true);
mImageProducer.setFullBufferUpdates(true);
renderer = new RenderKernel(pixel,triPoints,SigKeeper.texData,SigKeeper.SCREEN_WIDTH,SigKeeper.SCREEN_HEIGHT,256,256);
renderer = new RenderKernel(pixel,triPoints,SigKeeper.texData,SigKeeper.SCREEN_WIDTH,SigKeeper.SCREEN_HEIGHT,256,256,depthBuffer);
renderer.setExplicit(true);
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
if(thread.isInterrupted() || !thread.isAlive()){
@ -67,6 +69,7 @@ public class Panel extends JPanel implements Runnable {
for (int x=0;x<SigKeeper.SCREEN_WIDTH;x++) {
for (int y=0;y<SigKeeper.SCREEN_HEIGHT;y++) {
pixel[y*SigKeeper.SCREEN_WIDTH+x]=0;
depthBuffer[y*SigKeeper.SCREEN_WIDTH+x]=0;
}
}
//a=h/w

@ -6,11 +6,13 @@ public class RenderKernel extends Kernel{
int[] pixels;
float[] tris;
float[] transformedTris;
float[] depthBuffer;
int[] tex;
int width,tex_width;
int height,tex_height;
RenderKernel(int[] pixels,float[] tris,int[] tex,int width,int height,int tex_width,int tex_height) {
RenderKernel(int[] pixels,float[] tris,int[] tex,int width,int height,int tex_width,int tex_height,float[] depthBuffer) {
this.pixels=pixels;
this.tris=tris;
this.width=width;
@ -18,36 +20,41 @@ public class RenderKernel extends Kernel{
this.tex=tex;
this.tex_width=tex_width;
this.tex_height=tex_height;
this.depthBuffer=depthBuffer;
this.transformedTris = new float[this.tris.length];
}
@Override
public void run() {
for (int i=0;i<tris.length;i++) {
transformedTris[i]=tris[i];
}
int id = getGlobalId();
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];
float x1=transformedTris[id*21+0];
float y1=transformedTris[id*21+1];
float z1=transformedTris[id*21+2];
float w1=transformedTris[id*21+3];
float x2=transformedTris[id*21+4];
float y2=transformedTris[id*21+5];
float z2=transformedTris[id*21+6];
float w2=transformedTris[id*21+7];
float x3=transformedTris[id*21+8];
float y3=transformedTris[id*21+9];
float z3=transformedTris[id*21+10];
float w3=transformedTris[id*21+11];
float Tu=transformedTris[id*21+12];
float Tv=transformedTris[id*21+13];
float Tw=transformedTris[id*21+14];
float Uu=transformedTris[id*21+15];
float Uv=transformedTris[id*21+16];
float Uw=transformedTris[id*21+17];
float Vu=transformedTris[id*21+18];
float Vv=transformedTris[id*21+19];
float Vw=transformedTris[id*21+20];
TexturedTriangle(
(int)x1,(int)y1,0f,0f,1f,
(int)x2,(int)y2,1f,0f,1f,
(int)x3,(int)y3,1f,1f,1f,
(int)x1,(int)y1,Tu,Tv,Tw,
(int)x2,(int)y2,Uu,Uv,Uw,
(int)x3,(int)y3,Vu,Vv,Vw,
getGlobalId()%256,1f);
}

@ -33,6 +33,7 @@ public class SigKeeper implements WindowFocusListener,KeyListener,MouseListener,
public final static long TIMEPERTICK = 16666667l;
public static float DRAWTIME=0;
public static float DRAWLOOPTIME=0;
public static int MAX_TRIANGLE_COUNT=100;
public static Cursor invisibleCursor;

Loading…
Cancel
Save