Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Random point in frustum?

This topic is 5382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

not sure, but this should work. get a random number between near clip plane, and far clip plane, then, since the width of the frustum can be said as a function of z and FOV:

x offset = tan(Horizontal FOV / 2) * The first random number between near and far clip plane

say x is a random number between positive x offset and negative x offset.

then, repeat for vertical FOV. here is quick pseudocode (probably mistakes, and untested)

float z = (rand() / RAND_MAX) * (FarLipPlane - NearClipPlane) + NearClipPlane;
float hoffset = tan(FOV / 2) * z;
float x = ((2 * rand() / RAND_MAX) - 1) * hoffset; // random number between -1 and 1, times horizontal offset
float voffset = tan((FOV / Aspect) / 2) * z;
float y = ((2 * rand() / RAND_MAX) - 1) * voffset;

if needed, transform it to world space.

Share this post

Link to post
Share on other sites
billybob-s method will work, but it will not give you even distribution of points(more points near camera). For that you'll have to change random number generator.

You should never let your fears become the boundaries of your dreams.

[edited by - _DarkWIng_ on February 22, 2004 1:49:16 PM]

Share this post

Link to post
Share on other sites

Cheers chappies. I''ll give that a go - don''t really mind too much about not being evenly distributed at the moment

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!