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

  • SEARCH
  • Home
  • 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 8504179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:57:21+00:00 2026-06-11T01:57:21+00:00

We are trying to align our camera in order to see as closest as

  • 0

We are trying to align our camera in order to see as closest as possible a rectangle(a face of a parallelepiped since we are in 3D). The aspect ratio of the viewport considered here and the rectangle to align do not match.

What we do:

In our scene is this rectangle. The camera is position in front of it. Here is the configuration of the camera:

projection = Matrix.CreatePerspectiveFieldOfView(
    Fov, AspectRatio, NearPlane, FarPlane
);

view = Matrix.CreateLookAt(Position, Target, this.Up);

float Fov = PI/4;

float AspectRatio = device.Viewport.AspectRatio;

Vector3 Target is set to the center of the rectangle.

Vector3 Position is the value we are looking for.

And then to initialize the camera:
oat width = (float)GraphicsDevice.Viewport.Width;
float height = (float)GraphicsDevice.Viewport.Height;

float dist = (width / 2) + (height / 2);

float alpha = 0;
float beta = 0;
float gamma = 0;

alpha = (float)Math.Sqrt(Math.Pow(width / 2, 2) + Math.Pow(height / 2, 2));
beta = height / ((float)Math.Cos(MathHelper.ToRadians(70.3f)) * 2);
gamma = (float)Math.Sqrt(beta * beta - alpha * alpha);


position = new Vector3(width / 2, -height / 2, gamma);
target = new Vector3(width / 2, -height / 2, dist / 2);

camera = new Camera(GraphicsDevice.Viewport)
{
    Position = position,
    Target = target,
    Near = 1f,
    Far = 10000f
};

(VS solution)

One more precision: to create the view, we are using Matrix.CreateLookAt and for the projection Matrix.CreatePerspectiveFieldOfView. We are not sure if these are the perfect choices either but sounds like it.

What we get:

After some basic trigonometry we got a camera Position which works when the Height > Width. As:
enter image description here
enter image description here

But it does not when the Width > Height:
enter image description here

Do you…

…have any idea what are we doing wrong? Do you have any other or better way to achieve this?

  • 1 1 Answer
  • 0 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-06-11T01:57:23+00:00Added an answer on June 11, 2026 at 1:57 am

    Finding the height of the pyramid does not work. Just use the Tan and since the Fov = PI/4 the code should look like this:

    float tanGamma = (height / 2) * ((float)Math.Tan(MathHelper.ToRadians(67.5f)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to align our 3 social media buttons : Facebook/Twitter/Google +, evenly
I'm trying to align my DIV Our source below Our region and then the
Why is trying to align something in the center of the viewport (or wrapper)
I am trying to align two list in a panelGrid Since one list is
I have been trying to align an entire label along with text to the
Problem: I am trying to align divs next to each other using float:left but
I'm trying to align an ImageView to the top of the screen with a
I'm trying to align a text horizontal and vertically. Using de horizontal axis, I
I am trying to align a textblock vertically and horizontally center in a stack
I am trying to align my bitmap font text in my OpenGL application but

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.