Jump to content
  • Advertisement
Sign in to follow this  
Degra

Camera positioning

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by jyk
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)


Thats sorted it, thanks [smile]

Degra

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!