I am coding a physic engine for a custom doom engine.
I don't aim to replicate the exact behavior of the original doom.
In doom, every "thing" (player, monsters etc) is an axis aligned bounding box. I want to keep that.
I already have a working tesselation algorithm for the sectors.
I already have a working quadtree, using AABB boxes of triangles of sectors.
The quad tree will return a list of candidate for intersection with a given AABB (the player, for example).
What I want : an algorithm to test if a triangle intersect an AABB in 2D.
What I can do : split the AABB into two triangles, then do triangle-triangle intersection check. What I can do : use a "triangle vs aabb" algorithm working with 3D and set the "z" to 0. What I can do :
1/ check if a point of the triangle is inside the AABB.
2/ check if the center of the AABB is inside the triangle (the center is the better candidate to avoid rounding problems).
3/ check if a line segment of the triangle intersects a segment of the AABB.
I don't want to do that because : I think that given this precise situation, there should be a more optimized way to do it. It is precisely something that the GPU has to face often : find if a triangle is inside the viewport. I think that question, more than any other question, has been solved to hell.
Note that the situation can be even simpler : I can translate everything so the AABB start at (0,O). I can resize everything so the question becomes: "how to determine if a triangle intersect [0,1][0,1]".
I already did some research but:
1/ most results are for 3D stuff.
2/ this is strangely enough a not often covered case. Even in the book "game physics cookbook" this question is not mentionned.
3/ answers I found goes the hard, generic, way, with SAT (separation axis theorem) or equivalent stuff.
I'll have to do this test for a lot of "thing" (player, monster) everyframe for every candidate triangle given by the quadtree.
There is one last option I have, but I really don't know where to start or even if it's a good idea. Here is a quick summary of what I have in my minds.
1/ as the gpu already has all these triangles.
2/ as it's massively parallelizable.
3/ as, passed the fixed cost, there'll be no additionnal cost.
=> ask the gpu.
But I don't know how to do that. The communication cpu/gpu will have a cost, but a fixed cost (it will roughly cost the same thing for 1 or 100.000 things). I prefer to avoid this solution (but as the website ask me to say the ideas I had, I am talking about it).
Please note that this is my first message on this website. Please note that english is not my native language. Please note that, right now right here, it's 3:32 am (in the night). Please note that I will not be able to answer before tomorrow at roughly the same hour (and this is true for every day actually).
Thanks for reading, thanks in advance for answers.