top | item 30183184

(no title)

dormando | 4 years ago

Looks like the engine is missing the fish-eye correction in the ray-cast calc. I love writing these engines for fun :)

discuss

order

dahart|4 years ago

Fish eye is a feature! ;) https://strlen.com/gfxengine/fisheyequake/

I noticed it in the examples too, I’m speculating wildly that the ray cast is even angular steps rather than pinhole projection. Totally reasonable to not correct it, IMO, I’ve long thought we should have more non-linear cameras in games.

a_e_k|4 years ago

That's exactly what it's doing:

    let rayAngle = player.angle - player.fieldOfView / 2;
    for(let rayCount = 0; rayCount < screen.width; rayCount++) {

      // ... SNIP ...

      // the ray moves at constant increments
      let rayCos = Math.cos(degreeToRadians(rayAngle)) / precision;
      let raySin = Math.sin(degreeToRadians(rayAngle)) / precision;

      // ... SNIP ...

      // increment the angle for the next ray
      rayAngle += incrementAngle;
    }
It's also using Euclidean distance rather than planar distance for the apparent wall height calculation.

hrydgard|4 years ago

If you generate the rays the linear way instead, you don't even need any correction.

Generate two points which represent the left and right edges of the screen - you'd put them in at say 45 degrees left and right of the forward vector of the player. Then to generate the direction vector for each column of the screen, just interpolate linearly between those two points, and find the vector from the player to that intermediate point.

dormando|4 years ago

The venerable lodev tutorial uses this method, which I also used for most of my engines. I learned an interesting tidbit while comparing the two methods though:

The old-school original methods used pretty small cos/sin/atan lookup tables to do the ray and then the correction calc. Using the linear method you end up with a couple divisions per ray that aren't there in the lookup method. Divisions were (and are, depending on the platform) pretty slow. Linear method still works with lookup tables but they're relatively huge.

Also IIRC With the linear method door-indents need a workaround.