-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderThread.java
More file actions
61 lines (51 loc) · 1.93 KB
/
RenderThread.java
File metadata and controls
61 lines (51 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.gmail.x544647.bettermc;
import java.awt.Color;
public class RenderThread extends Thread{
private Program program;
private int offset, length;
RenderThread(Program program, int offset, int length){
this.offset = offset;
this.length = length;
this.program = program;
}
public void run() {
double radPerPixX = Math.toRadians(program.fovX / Program.imageX);
double radPerPixY = Math.toRadians(program.fovY / Program.imageY);
double imgYHalf = Program.imageY/2;
double imgXHalf = Program.imageX/2;
int pYe = offset + length;
for(int pY=offset; pY<pYe; pY++) {
double ayc = Math.cos(radPerPixY * (pY - imgYHalf) + program.CamRot.Z);
double ays = Math.sin(radPerPixY * (pY - imgYHalf) + program.CamRot.Z);
double ya = ays * program.stepLen;
for(int pX=0; pX<Program.imageX; pX++) {
double distance = 0;
double axc = Math.cos(radPerPixX * (pX - imgXHalf) + program.CamRot.Y) * ayc;
double axs = Math.sin(radPerPixX * (pX - imgXHalf) + program.CamRot.Y) * ayc;
double xa = axc * program.stepLen;
double za = axs * program.stepLen;
double currX = program.CamPos.X;
double currY = program.CamPos.Y;
double currZ = program.CamPos.Z;
while(distance < program.ViewDistInBlocks) {
distance += program.stepLen;
currX += xa;
currY += ya;
currZ += za;
if(currY < 0) {
program.pixels[(Program.imageY - pY - 1) * Program.imageX + pX] = new Color(100, 100, 100).getRGB();
break;
}
else if(currY > 0.5) {
program.pixels[(Program.imageY - pY - 1) * Program.imageX + pX] = new Color(50, 50, 255).getRGB();
break;
}
else if(program.Map[(int) currX][(int) currZ].HasRayHit(currX - (int) currX, currZ - (int) currZ)) {
program.pixels[(Program.imageY - pY - 1) * Program.imageX + pX] = new Color(200, 75, 75).getRGB();
break;
}
}
}
}
}
}