Differences From Artifact [a7de71ad12]:
- File
src/worldocull.m
— part of check-in
[75e920ae30]
at
2025-03-29 14:25:43
on branch trunk
— Switch from clang-format to manual formatting
clang-format does too many weird things. (user: js, size: 4487) [annotate] [blame] [check-ins using]
To Artifact [2e489013a3]:
- File src/worldocull.m — part of check-in [c634a689e7] at 2025-03-29 17:13:40 on branch trunk — More style fixes (user: js, size: 4481) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
34 35 36 37 38 39 40 | 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) || | | | > > | 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 62 63 64 65 66 67 | 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; dy = -(ray - 4); } else if (ray >= 5 && ray < 7) { dx = ray - 6; dy = -1; } else { dx = 1; dy = ray > 4 ? ray - 8 : ray; } float sx = vx; float sy = vy; for (;;) { sx += dx; sy += dy; // 90% of time spend in this function is on this // line |
︙ | ︙ | |||
121 122 123 124 125 126 127 | // find highest and lowest angle in the occlusion map that this cube // spans, based on its most left and right points on the border from the // viewer pov... I see no easier way to do this than this silly code // below float h, l; | | < > | < > | < > > < | > | < | | < > > > | | > | < < | > < | > | < > | < > > < | > < > > < > | < | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | // find highest and lowest angle in the occlusion map that this cube // spans, based on its most left and right points on the border from the // viewer pov... I see no easier way to do this than this silly code // below float h, l; if (cx <= vx) { // ABDFG if (cx + csize < vx) { // ADF if (cy <= vy) { // AD if (cy + csize < vy) { // A h = ca(-(cx - vx), -(cy + csize - vy)) + 4; l = ca(-(cx + csize - vx), -(cy - vy)) + 4; } else { // D h = ma(-(cx + csize - vx), -(cy + csize - vy)) + 4; l = ma(-(cx + csize - vx), -(cy - vy)) + 4; } } else { // F h = ca(cy + csize - vy, -(cx + csize - vx)) + 2; l = ca(cy - vy, -(cx - vx)) + 2; } } else { // BG if (cy <= vy) { if (cy + csize < vy) { // B h = ma(-(cy + csize - vy), cx - vx) + 6; l = ma(-(cy + csize - vy), cx + csize - vx) + 6; } else return 0; } else { // G h = ma(cy - vy, -(cx + csize - vx)) + 2; l = ma(cy - vy, -(cx - vx)) + 2; } } } else { // CEH if (cy <= vy) { // CE if (cy + csize < vy) { // C h = ca(-(cy - vy), cx - vx) + 6; l = ca(-(cy + csize - vy), cx + csize - vx) + 6; } else { // E h = ma(cx - vx, cy - vy); l = ma(cx - vx, cy + csize - vy); } } else { // H h = ca(cx + csize - vx, cy - vy); l = ca(cx - vx, cy + csize - vy); } } // 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 } |