Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top