# Camera positioning

This topic is 4962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Basically, I have an 800x600 rectangle on screen (centre at the point 0,0,0 and in the plane XY), and I need to work out where to position the camera on the Z axis so that the whole rectangle can be seen filling the screen. This probably sounds really n00b but I can't find any information anywhere on doing this (probably cos it is really simple). Anyway, I can't get my head round it so any help will be greatly appreciated [smile]. Degra

##### Share on other sites
We'll assume the aspect ratio of the screen is 4/3, the same as your rectangle. Viewing the problem from the top down, you have a right triangle; one side is the camera's displacement along the z axis, one side is half of the rectangle and has a length of 400, and the angle opposite this second side is horizontalFov/2. Then:

tan(hFov/2) = 400/z
z*tan(hFov/2) = 400
z = 400/tan(hFov/2)

Or if you have the vertical instead of horizontal field of view:

z = 300/tan(vFov/2)

##### Share on other sites
You need to know you fov.

zDistance = (xWidth / 2.0) / tan(FOV / 2.0)

because tan(FOV / 2.0) = (half screen width) / (distance to screen)

##### Share on other sites
Quote:
 Original post by jykWe'll assume the aspect ratio of the screen is 4/3, the same as your rectangle. Viewing the problem from the top down, you have a right triangle; one side is the camera's displacement along the z axis, one side is half of the rectangle and has a length of 400, and the angle opposite this second side is horizontalFov/2. Then:tan(hFov/2) = 400/zz*tan(hFov/2) = 400z = 400/tan(hFov/2)Or if you have the vertical instead of horizontal field of view:z = 300/tan(vFov/2)

Thats sorted it, thanks [smile]

Degra

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634047
• Total Posts
3015231
×