Members - Reputation: 133
Posted 21 October 2012 - 06:30 AM
I can't figure out how to take the FOV of the camera, the list of points, and the facing angle/projection matrix of the camera to determine how far back I need to pull the camera. I'm currently thinking that I might be able to reverse the 'is point on screen' equation using the cameras projection matrix, then get a required distance for each point and use the biggest distance. I'm just not sure how to reverse that equation - or if I'm even on the right track here.
Can someone point me in the right direction please?
Members - Reputation: 841
Posted 22 October 2012 - 08:45 AM
Place the camera at the median point of your point cloud. Transform all points to camera (view, eye) space.
Now translating camera along it's local Z is equivalent to translating all points along global Z in camera space. I.e. you have to find for each point, which is the smallest translation along z that moves it inside view frustum.
Let your point (in camera coordinate system) be P(x,y,z)
In clip coordinate system:
Qx = 2Px/(R-L) - Pz(R+L)/(R-L)
Qy = 2Py/(T-B) - Pz(T+B)/(T-B)
Qz = -(F+N)/(F-N) - 2FN/(F-N)
Qw = -Pz
And after perspective division
Sx = Qx/Qw
Sy = Qy/Qw
Sz = Qz/Qw
You want to ensure that:
-1 <= Sx <= 1
-1 <= Sy <= 1
-1 <= Sz (you do not want to check far plane here, because otherwise your inequalities may become unsolvable)
Now for each point and for each coordinate x, y and z find maximum z value Pz' that fills the conditions of these inequalities.
Required distance to move camera d = Pz - Pz'
While iterating over all points and all coordinates find the maximum d.
First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/