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 8454279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:59:02+00:00 2026-06-10T11:59:02+00:00

I am drawing a rectangle with primitives in XNA. The width is: width =

  • 0

I am drawing a rectangle with primitives in XNA. The width is:

width = GraphicsDevice.Viewport.Width 

and the height is

height = GraphicsDevice.Viewport.Height

I am trying to fit this rectangle in the screen (using different screens and devices) but I am not sure where to put the camera on the Z-axis. Sometimes the camera is too close and sometimes to far.

This is what I am using to get the camera distance:

//Height of piramid
float alpha = 0;
float beta = 0;
float gamma = 0;

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

position = new Vector3(0, 0, gamma);

Any idea where to put the camera on the Z-axis?

  • 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-10T11:59:04+00:00Added an answer on June 10, 2026 at 11:59 am

    The trick to doing this is to draw the rectangle directly in raster space. This is the space that the GPU works in when actually rendering stuff.

    Normally your model starts in its own model space, you apply a world transform to get it into world space. You then apply a view transform to move the points in the world around the camera (to get the effect of the camera moving around the world). Then you apply a projection matrix to get all those points into the space that the GPU uses for drawing.

    It just so happens that this space is always – no matter the screen size – from (-1,-1) in the bottom left corner of the viewport, to (1,1) in the top right (and from 0 to 1 on the Z axis for depth).

    So the trick is to set all your matrices (world, view, project) to Matrix.Identity, and then draw a rectangle from (-1,-1,0) to (1,1,0). You probably also want to set DepthStencilState.None so that it doesn’t affect the depth buffer.


    An alternative method is to just use SpriteBatch and draw to a rectangle that is the same size as the Viewport.

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

Sidebar

Related Questions

I am trying to draw some primitives with monogame. I am using the GraphicsDevice
I have the following code : System.Drawing.Rectangle desktop_Rectangle = System.Windows.Forms.Screen.PrimaryScreen.Bounds which gives me the
I'm getting a fishy error when using glDrawElements(). I'm trying to render simple primitives
I was a problem with drawing rectangle using mouse. I have solve my problem
I'm trying to print a datagridview by drawing to bitmap using visual studio 2008
I'm drawing a rectangle and I'm trying to figure out the maximum dimensions of
I am drawing an rectangle using tutorial at here FlagClass.m -(void)drawRect:(CGRect)rect { CGContextRef context
In my iPad application i am drawing one rectangle on map using overlay. I
I have the following paint event (form) that is drawing the rectangle: void LogicSimulationViewerForm_Paint(object
I'm trying to draw 10 rectangles, but when I use g.DrawRectangle() it is drawing

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.