• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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

...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!
 

GMWolf

aka fel666
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.
 
There was this old example on converting world-space coordinates to screen-space and vice versa, which can be used if the thing is on-screen
http://gmc.yoyogames.com/index.php?showtopic=416555
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.
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.
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.
 

GMWolf

aka fel666
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.
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.
 
Top