Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Rectangle intersection API?

    Help
    3
    4
    144
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      Nisse5 F last edited by

      Is there any API to get if 2 rectangles (vectors as x, y, w, h) intersect? My own function is called so many times during an update(), that it currently hurt performance.

      mixaal 1 Reply Last reply Reply Quote 0
      • mixaal
        mixaal F @Nisse5 last edited by

        @Nisse5 The 2D rectangle intersection shouldn't make a huge difference since the algo is quite simple. Do you have one of these?

        https://gamedev.stackexchange.com/questions/586/what-is-the-fastest-way-to-work-out-2d-bounding-box-intersection

        1. Some magic around centers (minimizes ifs - might speed things up, but never tried it)
        2. Classic-one having 4 ifs and 3 ors
        N 1 Reply Last reply Reply Quote 0
        • N
          Nisse5 F @mixaal last edited by

          @mixaal Yes, I do. My conclusion is that it's not the algorithm that causing the delays, it's the constant repetition of interpreted code. Running the function about 1000 times cause 4-5 milliseconds per frame update (time that I would like to use elsewhere, to keep my update cycle to always be below 16 ms). I can gain about 1 ms performance by putting the code directly in the loop (and not use a function call).

          I'd expect an API doing the same thing to have insignificant impact on performance.

          1 Reply Last reply Reply Quote 0
          • M
            MikeDX last edited by

            absolutely true here on many counts. the iteration is costly, the calculations are not.

            we are already looking at ways to improve this!

            1 Reply Last reply Reply Quote 2
            • First post
              Last post