Fitting a rectangle into screen with XNA

Posted by alecnash on Game Development See other posts from Game Development or by alecnash
Published on 2012-08-30T12:04:56Z Indexed on 2012/08/30 15:50 UTC
Read the original article Hit count: 309

Filed under:
|
|

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?

© Game Development or respective owner

Related posts about XNA

Related posts about c#