Archived

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

Random point in frustum?

This topic is 5043 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