GMS 2 [Solvered.] How to check if something is within view?

Discussion in 'Programming' started by SupernaturalCow, Sep 12, 2019.

  1. SupernaturalCow

    SupernaturalCow Member

    Joined:
    Sep 11, 2016
    Posts:
    142
    ...in 3D :D

    Hi all,

    Just wondering how I can check for instances within the view of a perspective projection?

    Put in other words, how do you calculate the 3D coordinates of the view quad in a perspective projection? I want to unload assets out of view, and knowing the view boundary is kind of a must.

    Thanks in advance!
     
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,386
    SupernaturalCow likes this.
  3. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,398
    Have a bounding box for your shape.

    Then multiply each corner by the view projection matrix and divide by w.

    Now your bbox is in clip space (-1 - +1) so you can check if all vertices are to the left, above , below, etc of the view frustum.
     
    SupernaturalCow likes this.
  4. SupernaturalCow

    SupernaturalCow Member

    Joined:
    Sep 11, 2016
    Posts:
    142
    Thanks for the link. Unfortunately I'm wanting to check for things off-screen, but I've learned a great amount from this example regardless.
    Yep, so once the shape is in clip space, how do I know the bounds of the view frustum? Or is anything less than -1 and greater than 1 outside of view.
     
  5. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,398
    Yeah, but also consider the case where the bbox is larger than the view, that should not count.
    You need to check if all points are less than -1 or more than 1 on any axis.
     
    SupernaturalCow likes this.
  6. SupernaturalCow

    SupernaturalCow Member

    Joined:
    Sep 11, 2016
    Posts:
    142
    Nice, thanks!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice