0

I'd like to randomly create objects at different translations from the origin, but i want to guarantee that they're always visible, meaning i don't want to just discard objects they aren't visible. Assuming that my view matrix is an identity, can I randomly compute locations where the object is qt least partly visible? Using some basic trigonometry, with knowing the aspect ratio and near and far z values, i can compute the dimensions of the perspective frustum. The problem is that if I want to draw an object at a random x position in the frustum, chances are its random z position puts it out of view. Any suggestions?

Joey Carson
  • 2,973
  • 7
  • 36
  • 60

1 Answers1

1

I assume you know how you have set up your frustum so the parameters for the frustum should be known: left, right, bottom, top, near, far

Normally you would need viewingDirection, cameraPosition and upVector of the camera to determine the position inside the frustum, but because view matrix is identity, viewingDir is (0,0,-1), camPosition is (0,0,0) and upVector is (0,1,0).

So you just have to check that your random point lies between (left, bottom, -near) and (right, top, -far).

D-rk
  • 5,513
  • 1
  • 37
  • 55