afritz1 / OpenTESArena

Open-source re-implementation of The Elder Scrolls: Arena.
MIT License
915 stars 68 forks source link

Raycast #169

Closed faha223 closed 4 years ago

faha223 commented 4 years ago

rewrote the raycast selection logic to work correctly with entities, diagonal walls, and raised platforms as well as to work in 3D with floors and ceilings. The calculation for getting the rayDirection in the GameWorldPanel seems to be broken in Modern UI mode if you look up or down, but it's pretty close. The selection works pretty much flawlessly in classic mode.

There are some functions in MathUtils that make some functions in the Collisions PR redundant, but we can combine them later.

faha223 commented 4 years ago

Travis CI broke for Linux and OS X because of the use of FLT_MAX and DBL_MAX in a few places where I should have used std::numeric_limits::max()

afritz1 commented 4 years ago

Just going through and doing some iterative changes. Will try to get more done tomorrow.

afritz1 commented 4 years ago

Sorry for the confusion, but I realized we probably want to move the ray generation from handleClickInWorld() to a renderer function similar to getFlatTexel(), like

static Double3 SoftwareRenderer::screenPointToRay(double xPercent, double yPercent, const Camera &camera, const Options &options);

I want handleClickInWorld() to ideally not worry any about renderer values like TALL_PIXEL_RATIO. It would call game.getRenderer().screenPointToRay(...). We can revert the classic/modern branch that I suggested, so maybe passing const Options& to the screen point function might not be necessary.

afritz1 commented 4 years ago

Making progress here and there. Some things I wanted to note (not exhaustive):

I'll get to some more rigorous testing of this in a while.

If you want to better test the exact sprite selection areas, add this at line 6731 in the software renderer (the else case of the texel.a > 0.0 condition):

else
{
    frame.colorBuffer[index] = 0x00FF0000;
    frame.depthBuffer[index] = depth;
}
afritz1 commented 4 years ago

It's not perfect but it's good enough for testing, and I want to move onto other tasks. I'll make another issue for improving it in the future.