View difference between Paste ID: HucgjRtx and rW3vMNZ8
SHOW: | | - or go back to the newest paste.
1
package raytrace;
2
3
import processing.core.PApplet;
4
5
6
public class Raytrace extends PApplet {
7
	public static void main(String[] args) {
8
	}
9
10
	double yaw = Math.PI*-0.25;
11
	double pitch = Math.PI*-0.1875;
12
	double x;
13
	double y;
14
	double z;
15
	double d;
16
	int screenX;
17
	int screenY;
18
	int shade;
19
	int cont = 0;
20
	double distance;
21
	double xv;
22
	double yv;
23
	double zv;
24
	int frames = 0;
25
	double trueYaw = Math.PI*0.1;
26
	double truePitch = Math.PI*0.5;
27-
	double collisionAccuracy = 1;
27+
	double collisionAccuracy = 0.1;
28
	int oldY;
29
	//boolean isTouching;
30
	int r;
31
	int g;
32
	int b;
33
	double plus = 0;
34
	int shadowY;
35
36
	public boolean check(double X, double Y, double Z) {
37
		//isTouching = false;
38
		r= 0;
39
		g = 0;
40
		b = 0;
41
		//System.out.println(Y);
42
		if (Z > 20 && Z < 30 && X > -5 && X < 5 && Y > -5 && Y < 5) {
43
			//System.out.println("blue");
44
			r = 0;
45
			g = 0;
46
			b = 1;
47
			//System.out.println("true");
48
			return true;
49
		}
50
		//System.out.println(Y);
51
		if (Y < -50) {
52
			//System.out.println("red");
53
			r = 1;
54
			g = 0;
55
			b = 0;
56
			return true;
57
		}
58
		return false;
59
		/* if ((Math.sqrt(Math.sin(yaw)*Math.sin(yaw)+Math.sin(pitch)*Math.sin(pitch)+Math.cos(yaw)-20*Math.cos(yaw+Math.sin(pitch)-20*Math.cos(yaw+Math.sin(pitch))))) < 5) {
60
			//System.out.println("green");
61
			r = 0;
62
			g = 1;
63
			b = 0;
64
			isTouching = true;
65
		 */
66
	}
67
68
69
	public void cast(double YAW, double PITCH) {
70
		//yaw = 0;
71
		//pitch = 0;
72
		//speed = speed + 1;
73
		//System.out.println(speed);
74
		cont = 0;
75
		x = -5;
76
		y = 15;
77
		z = 25;
78
		//System.out.println(Math.sqrt(Math.sin(yaw)*Math.sin(yaw)+Math.sin(pitch)*Math.sin(pitch)+Math.cos(yaw)*Math.cos(yaw+Math.sin(pitch)*Math.cos(yaw+Math.sin(pitch)))));
79
		/*
80
		xv = (Math.sin(YAW)*collisionAccuracy);
81
		yv = (Math.sin(PITCH)*collisionAccuracy*(Math.cos(YAW-Math.PI*trueYaw)));
82
		zv = (Math.cos(YAW)*collisionAccuracy);
83
		 */
84
85
		xv = (Math.sin(YAW)*collisionAccuracy)*Math.cos(PITCH);
86
		yv = (Math.sin(PITCH)*collisionAccuracy);
87
		zv = (Math.cos(YAW)*collisionAccuracy)*Math.cos(PITCH);
88
		distance = 0;
89
		do {
90
			x = x + xv;
91
			y = y + yv;
92
			z = z + zv;
93
			distance = distance + collisionAccuracy;
94
			//System.out.println("x " + x + "y " + y + "z " + z);
95
			;
96
			if (check(x, y, z)) {
97
				oldY = (int)y;
98
				cont = 1;
99
				shadowY = 500;
100
				do {
101
					shadowY = shadowY - 1;
102
				} while (!check(x, shadowY, z));
103
				if ((oldY-1) < shadowY && (oldY+1) > shadowY ) {
104
					fill (r*255,g*255,b*255);
105
				}else{
106
					fill (r*100,g*100,b*100);
107
				}
108
109
				//cont = 1;
110
				//System.out.println("DETECTED CUBE");
111
			}
112
			if (distance > 200 && cont == 0) { 
113
				fill (0, 0, 0);
114
				cont = 1;
115
116
			}
117
		} while (cont == 0);
118
119
	}	
120
121
122
123
	public void setup() {
124
		size(1200,900);
125
		screenX = 0;
126
		screenY = 0;
127
	}
128
	public void draw() {
129
		background(255);
130
		noStroke();
131
		screenX = 0;
132
		screenY = 900;
133
		pitch = Math.PI*-0.1875+Math.PI*truePitch;
134
		yaw = Math.PI*-0.25+Math.PI*trueYaw;
135
		//plus = plus + 0.1;
136
		//yaw = yaw + plus;
137
		do {
138
			do {
139
				yaw = yaw + ((Math.PI*0.5)/1200);
140
				//System.out.println("screenX" + screenX);
141
				screenX = screenX + 1;
142
				cast(yaw, pitch);
143
				rect(screenX,screenY,1,1);
144
			} while(screenX < 1200);
145
			//System.out.println("screenY" + screenY);
146
			screenY = screenY - 1;
147
			pitch = pitch + ((Math.PI*0.375)/900);
148
			yaw = Math.PI*-0.25+Math.PI*trueYaw + plus;
149
			screenX = 0;
150
			cast(yaw, pitch);
151
			rect(screenX,screenY,1,1);
152
		} while(screenY > 0);
153
		frames = frames + 1;
154
		System.out.println(frames);
155
	}
156
}
157
158
159
160
161
//Math.PI*0.25 Math.PI*0.1875