Cube  Diff

Differences From Artifact [504811d94d]:

To Artifact [1dcc5bb2a7]:


31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	float apitch = (float)fabs(player1.pitch);
	float af = getvar(@"fov") / 2 + apitch / 1.5f + 3;
	float byaw = (player1.yaw - 90 + af) / 360 * PI2;
	float syaw = (player1.yaw - 90 - af) / 360 * PI2;

	for (int i = 0; i < NUMRAYS; i++) {
		float angle = i * PI2 / NUMRAYS;

		if ((apitch > 45 // must be bigger if fov>120
		        || (angle < byaw && angle > syaw) ||
		        (angle < byaw - PI2 && angle > syaw - PI2) ||
		        (angle < byaw + PI2 && angle > syaw + PI2)) &&
		    !OUTBORD(vx, vy) &&
		    !SOLID(S(fast_f2nat(vx),
		        fast_f2nat(vy)))) // try to avoid tracing ray if outside
		                          // of frustrum
		{
			float ray = i * 8 / (float)NUMRAYS;
			float dx, dy;
			if (ray > 1 && ray < 3) {
				dx = -(ray - 2);
				dy = 1;
			} else if (ray >= 3 && ray < 5) {
				dx = -1;







>
|
|


|
<
<
<
<







31
32
33
34
35
36
37
38
39
40
41
42
43




44
45
46
47
48
49
50
	float apitch = (float)fabs(player1.pitch);
	float af = getvar(@"fov") / 2 + apitch / 1.5f + 3;
	float byaw = (player1.yaw - 90 + af) / 360 * PI2;
	float syaw = (player1.yaw - 90 - af) / 360 * PI2;

	for (int i = 0; i < NUMRAYS; i++) {
		float angle = i * PI2 / NUMRAYS;
		// try to avoid tracing ray if outside of frustrum
		// apitch must be bigger if fov > 120
		if ((apitch > 45 || (angle < byaw && angle > syaw) ||
		        (angle < byaw - PI2 && angle > syaw - PI2) ||
		        (angle < byaw + PI2 && angle > syaw + PI2)) &&
		    !OUTBORD(vx, vy) && !SOLID(S((int)vx, (int)vy))) {




			float ray = i * 8 / (float)NUMRAYS;
			float dx, dy;
			if (ray > 1 && ray < 3) {
				dx = -(ray - 2);
				dy = 1;
			} else if (ray >= 3 && ray < 5) {
				dx = -1;
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
			float sx = vx;
			float sy = vy;
			for (;;) {
				sx += dx;
				sy += dy;
				// 90% of time spend in this function is on this
				// line
				if (SOLID(S(fast_f2nat(sx), fast_f2nat(sy)))) {
					rdist[i] = (float)(fabs(sx - vx) +
					    fabs(sy - vy));
					break;
				}
			}
		} else
			rdist[i] = 2;







|







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
			float sx = vx;
			float sy = vy;
			for (;;) {
				sx += dx;
				sy += dy;
				// 90% of time spend in this function is on this
				// line
				if (SOLID(S((int)sx, (int)sy))) {
					rdist[i] = (float)(fabs(sx - vx) +
					    fabs(sy - vy));
					break;
				}
			}
		} else
			rdist[i] = 2;
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
198
199
200
				l = ma(cx - vx, cy + csize - vy);
			} // E
		} else {
			h = ca(cx + csize - vx, cy - vy);
			l = ca(cx - vx, cy + csize - vy);
		} // H
	}
	int si = fast_f2nat(h * (NUMRAYS / 8)) +
	    NUMRAYS; // get indexes into occlusion map from angles

	int ei = fast_f2nat(l * (NUMRAYS / 8)) + NUMRAYS + 1;
	if (ei <= si)
		ei += NUMRAYS;

	for (int i = si; i <= ei; i++) {
		if (dist < rdist[i & (NUMRAYS - 1)])
			// if any value in this segment of the occlusion map is
			// further away then cube is not occluded
			return 0;
	}

	return 1; // cube is entirely occluded
}







<
|
>
|












176
177
178
179
180
181
182

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
				l = ma(cx - vx, cy + csize - vy);
			} // E
		} else {
			h = ca(cx + csize - vx, cy - vy);
			l = ca(cx - vx, cy + csize - vy);
		} // H
	}

	// get indexes into occlusion map from angles
	int si = h * (NUMRAYS / 8) + NUMRAYS;
	int ei = l * (NUMRAYS / 8) + NUMRAYS + 1;
	if (ei <= si)
		ei += NUMRAYS;

	for (int i = si; i <= ei; i++) {
		if (dist < rdist[i & (NUMRAYS - 1)])
			// if any value in this segment of the occlusion map is
			// further away then cube is not occluded
			return 0;
	}

	return 1; // cube is entirely occluded
}