Overview
Comment: | Fix wrong argument order for calculating distance |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
75095b4f6e2b5ed05c3279c84b686252 |
User & Date: | js on 2025-03-23 22:14:48 |
Other Links: | manifest | tags |
Context
2025-03-24
| ||
21:11 | Work around conflicting declaration of gamma check-in: 7c3936be15 user: js tags: trunk | |
2025-03-23
| ||
22:14 | Fix wrong argument order for calculating distance check-in: 75095b4f6e user: js tags: trunk | |
21:52 | Avoid pointless pointers check-in: 304230c1e1 user: js tags: trunk | |
Changes
Modified src/Monster.m from [df6f0d84fe] to [9674185459].
︙ | ︙ | |||
268 269 270 271 272 273 274 | } else { self.yaw -= curtime * 0.5f; if (self.targetYaw > self.yaw) self.yaw = self.targetYaw; } float disttoenemy = | | | 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | } else { self.yaw -= curtime * 0.5f; if (self.targetYaw > self.yaw) self.yaw = self.targetYaw; } float disttoenemy = OFDistanceOfVectors3D(self.enemy.origin, self.origin); self.pitch = atan2(self.enemy.origin.z - self.origin.z, disttoenemy) * 180 / PI; // special case: if we run into scenery if (self.blocked) { self.blocked = false; // try to jump over obstackle (rare) |
︙ | ︙ | |||
466 467 468 469 470 471 472 | if (lastmillis - monster.lastAction < 2000) { monster.move = 0; moveplayer(monster, 1, false); } } else { v.z += monster.eyeHeight; float dist = | | | 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | if (lastmillis - monster.lastAction < 2000) { monster.move = 0; moveplayer(monster, 1, false); } } else { v.z += monster.eyeHeight; float dist = OFDistanceOfVectors3D(v, monster.origin); v.z -= monster.eyeHeight; if (dist < 4) teleport(i, monster); } } }]; |
︙ | ︙ |
Modified src/entities.m from [3530688d6b] to [fe7c9a5680].
︙ | ︙ | |||
317 318 319 320 321 322 323 | return; if (OUTBORD(e.x, e.y)) return; OFVector3D v = OFMakeVector3D( e.x, e.y, (float)S(e.x, e.y)->floor + player1.eyeHeight); | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | return; if (OUTBORD(e.x, e.y)) return; OFVector3D v = OFMakeVector3D( e.x, e.y, (float)S(e.x, e.y)->floor + player1.eyeHeight); float dist = OFDistanceOfVectors3D(v, player1.origin); if (dist < (e.type == TELEPORT ? 4 : 2.5)) pickup(i, player1); }]; } void |
︙ | ︙ |
Modified src/renderparticles.m from [41bd950ef0] to [c7ff826e5c].
︙ | ︙ | |||
146 147 148 149 150 151 152 | newparticle(p, d, rnd(fade * 3), type); } } void particle_trail(int type, int fade, OFVector3D s, OFVector3D e) { | | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | newparticle(p, d, rnd(fade * 3), type); } } void particle_trail(int type, int fade, OFVector3D s, OFVector3D e) { float d = OFDistanceOfVectors3D(e, s); OFVector3D v = OFSubtractVectors3D(e, s); v = OFMultiplyVector3D(v, 1.0f / (d * 2 + 0.1f)); for (int i = 0; i < ((int)d * 2); i++) { s = OFAddVectors3D(s, v); OFVector3D d = OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5); newparticle(s, d, rnd(fade) + fade, type); } |
︙ | ︙ |
Modified src/savegamedemo.m from [16ee4d908b] to [b93241b086].
︙ | ︙ | |||
494 495 496 497 498 499 500 | // printf("* %d\n", lastmillis); float bf = (itime - a.lastUpdate) / (float)(b.lastUpdate - a.lastUpdate); fixwrap(a, player1); fixwrap(c, player1); fixwrap(z, player1); float dist = | | | 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | // printf("* %d\n", lastmillis); float bf = (itime - a.lastUpdate) / (float)(b.lastUpdate - a.lastUpdate); fixwrap(a, player1); fixwrap(c, player1); fixwrap(z, player1); float dist = OFDistanceOfVectors3D(c.origin, z.origin); // if teleport or spawn, don't interpolate if (dist < 16) { catmulrom(z.origin, a.origin, b.origin, c.origin, bf, player1.origin); OFVector3D vz = OFMakeVector3D( z.yaw, z.pitch, z.roll); OFVector3D va = OFMakeVector3D( |
︙ | ︙ |
Modified src/sound.m from [1d0c412a26] to [93eb0a5b3c].
︙ | ︙ | |||
110 111 112 113 114 115 116 | static void updatechanvol(int chan, const OFVector3D *loc) { int vol = soundvol, pan = 255 / 2; if (loc) { OFVector3D origin = player1.origin; | | | | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | static void updatechanvol(int chan, const OFVector3D *loc) { int vol = soundvol, pan = 255 / 2; if (loc) { OFVector3D origin = player1.origin; float dist = OFDistanceOfVectors3D(origin, *loc); OFVector3D v = OFSubtractVectors3D(origin, *loc); // simple mono distance attenuation vol -= (int)(dist * 3 * soundvol / 255); if (stereo && (v.x != 0 || v.y != 0)) { // relative angle of sound along X-Y axis float yaw = |
︙ | ︙ |
Modified src/weapon.m from [7fa0099398] to [d5d4aa755b].
︙ | ︙ | |||
69 70 71 72 73 74 75 | (a3.length > 0 ? a3.cube_intValue : -1)); }) // create random spread of rays for the shotgun void createrays(OFVector3D from, OFVector3D to) { | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | (a3.length > 0 ? a3.cube_intValue : -1)); }) // create random spread of rays for the shotgun void createrays(OFVector3D from, OFVector3D to) { float dist = OFDistanceOfVectors3D(to, from); float f = dist * SGSPREAD / 1000; for (int i = 0; i < SGRAYS; i++) #define RNDD (rnd(101) - 50) * f sg[i] = OFAddVectors3D(to, OFMakeVector3D(RNDD, RNDD, RNDD)); } // if lineseg hits entity bounding box |
︙ | ︙ | |||
181 182 183 184 185 186 187 | radialeffect( DynamicEntity *o, OFVector3D v, int cn, int qdam, DynamicEntity *at) { if (o.state != CS_ALIVE) return; OFVector3D origin = o.origin; | | | < | 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | radialeffect( DynamicEntity *o, OFVector3D v, int cn, int qdam, DynamicEntity *at) { if (o.state != CS_ALIVE) return; OFVector3D origin = o.origin; float dist = OFDistanceOfVectors3D(origin, v); OFVector3D temp = OFSubtractVectors3D(origin, v); dist -= 2; // account for eye distance imprecision if (dist < RL_DAMRAD) { if (dist < 0) dist = 0; int damage = (int)(qdam * (1 - (dist / RL_DAMRAD))); hit(cn, damage, o, at); temp = OFMultiplyVector3D(temp, (RL_DAMRAD - dist) * damage / 800); o.velocity = OFAddVectors3D(o.velocity, temp); } } static void |
︙ | ︙ | |||
263 264 265 266 267 268 269 | if (!p.inuse) continue; int qdam = guns[p.gun].damage * (p.owner.quadMillis ? 4 : 1); if ([p.owner isKindOfClass:Monster.class]) qdam /= MONSTERDAMAGEFACTOR; | | | | | | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | if (!p.inuse) continue; int qdam = guns[p.gun].damage * (p.owner.quadMillis ? 4 : 1); if ([p.owner isKindOfClass:Monster.class]) qdam /= MONSTERDAMAGEFACTOR; OFVector3D po = p.o, pto = p.to; float dist = OFDistanceOfVectors3D(pto, po); OFVector3D v = OFSubtractVectors3D(pto, po); float dtime = dist * 1000 / p.speed; if (time > dtime) dtime = time; v = OFMultiplyVector3D(v, time / dtime); v = OFAddVectors3D(v, po); if (p.local) { for (id player in players) if (player != [OFNull null]) projdamage(player, p, v, i, -1, qdam); if (p.owner != player1) projdamage(player1, p, v, -1, -1, qdam); |
︙ | ︙ | |||
346 347 348 349 350 351 352 | } void hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at, OFVector3D from, OFVector3D to) { hit(target, damage, d, at); | | | | 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | } void hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at, OFVector3D from, OFVector3D to) { hit(target, damage, d, at); float dist = OFDistanceOfVectors3D(to, from); OFVector3D v = OFSubtractVectors3D(to, from); v = OFMultiplyVector3D(v, damage / dist / 50); d.velocity = OFAddVectors3D(d.velocity, v); } void raydamage( DynamicEntity *o, OFVector3D from, OFVector3D to, DynamicEntity *d, int i) |
︙ | ︙ | |||
397 398 399 400 401 402 403 | } if (d.gunSelect) d.ammo[d.gunSelect]--; OFVector3D from = d.origin; OFVector3D to = targ; from.z -= 0.2f; // below eye | | | | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | } if (d.gunSelect) d.ammo[d.gunSelect]--; OFVector3D from = d.origin; OFVector3D to = targ; from.z -= 0.2f; // below eye float dist = OFDistanceOfVectors3D(to, from); OFVector3D unitv = OFSubtractVectors3D(to, from); unitv = OFMultiplyVector3D(unitv, 1.0f / dist); OFVector3D kickback = OFMultiplyVector3D(unitv, guns[d.gunSelect].kickamount * -0.01f); d.velocity = OFAddVectors3D(d.velocity, kickback); if (d.pitch < 80.0f) d.pitch += guns[d.gunSelect].kickamount * 0.05f; |
︙ | ︙ |
Modified src/world.m from [892a60074f] to [c2453dcf9a].
︙ | ︙ | |||
294 295 296 297 298 299 300 | __block int best; __block float bdist = 99999; [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { if (e.type == NOTUSED) return; OFVector3D v = OFMakeVector3D(e.x, e.y, e.z); | | | 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | __block int best; __block float bdist = 99999; [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { if (e.type == NOTUSED) return; OFVector3D v = OFMakeVector3D(e.x, e.y, e.z); float dist = OFDistanceOfVectors3D(v, player1.origin); if (dist < bdist) { best = i; bdist = dist; } }]; return (bdist == 99999 ? -1 : best); |
︙ | ︙ |