For one of my recently uploaded Fairground scenes I was having difficulty finding a position for the camera which did not cause obvious problems with perpective as the various parts of the sceen were moved about. As the image I was using for the background had nicely defined horizontal planes at floor and ceiling level with a strong rectangular grid pattern on the ceiling and with a rather weaker one on the floor I decided to add a gridwork box of my own and tweak the camera position, camera target and camera angle until the grids in the original scene coincided. I thought some of you might find the technique useful so I have made this post showing what I did.
The attached screen shots show a few stages in the process. They correspond to the following sequence of parameter values:-
type : 3D
// starting point - capture 1
// angle : 45
// pos : 0, -700, 1500
// target : 0, -700, 0
// capture 2
// angle : 45
// pos : 90, -500, 1500
// target : 90, -500, 0
// capture 3
// angle : 45
// pos : 90, -550, 1500
// target : 90, -550, 0
// capture 3
// angle : 45
// pos : 90, -550, 1500
// target : 90, -550, 0
// capture 4
// angle : 90
// pos : 90, -550, 500
// target : 90, -550, 0
// capture 5
// angle : 121
// pos : 90, -550, 300
// target : 90, -550, 0
In practice I used rather more intemediate steps as I iterrated towards the final set of values. I was surprised just how close the camera had to be and how wide an angle was required to match the perspective of the original photograph - though on looking at the image afterwards that should not have been a surprise even though they are a long way from the normal range of values that I tend to use. As you will see from the images the two sets of grids were made to correpond more closely at each stage until I was satified that they were close enough.
Once the perpective match had been acheived it was possible to use a single Y co-ordinate value for anything placed on the floor and to simply move things away from or towards the camera by only adjusting the Z co-ordinate of its position rather than having to adjust Y and height.
To generate the grid I used a simple shader to generate a grid in a frame buffer and positioned 4 copies of this grid to form the floor, ceiling and sides of my gridded box. You can use the same technique without a shader by creating a seperate grid image and use that as a texture but i find the shader based version more convenient. The shader is present in the Fairgrounds zip file and the scene file still contains the way it was used as comments.
Although the technique was sugested by the nicely aligned grid patterns in the image I was using it can be used with images in which the grids are rotated (you just rotate the gridded box to match) or even for settings without such grids in which case you just have to imagine them.