Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 834889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:44:26+00:00 2026-05-15T04:44:26+00:00

It might be that my math is rusty or I’m just stuck in my

  • 0

It might be that my math is rusty or I’m just stuck in my box after trying to solve this for so long, either way I need your help.

Background: I’m making a 2d-based game in C# using XNA. In that game I want a camera to be able to zoom in/out so that a certain part of objects always are in view. Needless to say, the objects move in two dimensions while the camera moves in three.

Situation: I’m currently using basic trigonometry to calculate which height the camera should be at for all objects to show. I also position the camera between those objects.

It looks something like this:

1.Loop through all objects to find the outer edges of our objects : farRight, farLeft, farUp, farDown.

2.When we know what the edges of what has to be shown are, calculate the center, also known as the camera position:

CenterX = farLeft + (farRight - farLeft) * 0.5f;
CenterY = farUp + (farDown - farUp) * 0.5f;

3.Loop through our edges to find the largest value compared to our camera position, thus the furthest distance from the center of screen.

4.Using the largest distance-value we can easily calculate the needed height to show all of those objects (points):

float T = 90f - Constants.CAMERA_FIELDOFVIEW * 0.5f;
float height = (float)Math.Tan(MathHelper.ToRadians(T)) * (length);

So far so good, the camera positions itself perfectly based on the calculations.

Problem:

a) My rendering target is 1280*720 with a Field of View of 45 degrees, so one always sees a bit more on the X-axis, 560 pixels more actually. This is not a problem per se but more one that on b)…

b) I want the camera to be a bit further out than it is, so that one sees a bit more on what is happening beyond the furthest point. Sure, this happens on the X-axis, but that is technically my flawed logic’s result. I want to be able to see more on both the X- and Y-axis and to control this behavior.

Question

Uhm, so to clarify. I would like to have some input on a way to make the camera position itself, creating this state:

Objects won’t get closer than say… 150 pixels to the edge of the X-axis and 100 pixels to the edge of the Y-axis. To do this the camera shall position itself along the Z-axis so that the field of view covers it all.

I don’t need help with the coding, just the math and logic of calculating the height of my camera. As you probably can see, I have a hard time wrapping this inside my head and even harder time trying to explain it to you.

If anyone out there has been dealing with this or is just better than me at math, I’d appreciate whatever you have to say! 🙂

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:44:27+00:00Added an answer on May 15, 2026 at 4:44 am

    Don’t you just need to add or subtract 150 or 100 pixels (depending on which edge you are looking at) to each distance measurement in your loop at step 3 and carry this larger value into length at step 4? Or am I missing something.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question might just show that I haven't understand something important in C: The
You might think that this question is already answered. However, I couldn't find the
I have a file that might contain a line like this. A B //Seperated
I realize this question might not be that programming related, and that it by
I realize this might be more of a math problem. To draw the lines
What's the recommended way to use Maven for a project that might grow large
This might be more Math related than C#, but I need a C# solution
That might be a naive git question but here it is: Before doing a
As you all might know that the MIPS instruction set supports clz (count leading
I've got a question that might sound strange. We are using node.js, but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.