• Create Account

We're offering banner ads on our site from just \$5!

### #ActualGamer Pro

Posted 04 February 2013 - 01:22 PM

Thanks for the responce EWClay, I found out that the API I'm using can be set up to calculate this for me but I appreciate the answer.

But now I have a math problem. My trigonometry isn't working.

My box's dimensions are: 1213, 623, 21; I have the heading at 0° and the elevation at 90° so the camera is giving me a bird's eye view with North to the top of my screen (IE: there's no rotations). My vertical field of view is 60°, the area I'm rendering to is 1920x850, which calculates my horiztonal field of view to be 105° (2 * atan(tan(FIELD_OF_VIEW_RADIANS / 2) * aspectRatio)). I use: distance = halfDimension / tan(FOV / 2) for both vertical and horizontal dimensions which gives me 646 & 818, respectively. Now this tells me that I need to position my camera 646 units away to fit the cube's vertically and 818 units away to fit the cube horizontally. I choose horizontally (so that the entire cube is visible). This should be right, right?

The problem is that if I position my camera 818 units away the cube is smaller than the frustum. The cube is centered on the origin and on my screen, so the above math (assuming it's right) states that the very right of my screen is 606.5 positive units on the x-axis, making the cube just fit horizontally. However I can place a small cube at 1065 units on the x-axis and it's on the edge of my screen (I just picked numbers till the cube was just on my screen).

I've looked over my math and it looks right. Maybe I'm missing something? Could their be something about the perspective camera I didn't take into account?

### #2Gamer Pro

Posted 04 February 2013 - 01:21 PM

Thanks for the responce EWClay, I found out that the API I'm using can be set up to calculate this for me but I appreciate the answer.

But now I have a math problem. My trigonometry isn't working.

My box's dimensions are: 1213, 623, 21; I have the heading at 0° and the elevation at 90° so the camera is giving me a bird's eye view with North to the top of my screen (IE: there's no rotations). My vertical field of view is 60°, the area I'm rendering to is 1920x850, which calculates my horiztonal field of view to be 105° (2 * atan(tan(FIELD_OF_VIEW_RADIANS / 2) * aspectRatio)). I use: distance = halfDimension / tan(FOV / 2) for both vertical and horizontal dimensions which gives me 646 & 818, respectively. Now this tells me that I need to position my camera 646 units away to fit the cube's vertically and 818 units away to fit the cube horizontally. I choose horizontally (so that the entire cube is visible). This should be right, right?

The problem is that if I position my camera 818 units away the cube is smaller than the frustum. The cube is centered on the origin and on my screen, so the above math (assuming it's right) states that the very right of my screen is 606.5 positive units on the x-axis, making the cube just fit horizontally. However I can place a small cube at 1065 units on the x-axis and it's on the edge of my screen (I just picked numbers till the
cube was just on my screen).

I've looked over my math and it looks right. Maybe I'm missing something? Could their be something about the perspective camera I didn't take into account?

### #1Gamer Pro

Posted 04 February 2013 - 01:20 PM

Thanks for the responce EWClay, I found out that the API I'm using can be set up to calculate this for me but I appreciate the answer.

But now I have a math problem. My trigonometry isn't working.

My box's dimensions are: 1213, 623, 21; I have the heading at 0° and the elevation at 90° so the camera is giving me a bird's eye view with North to the top of my screen (IE: there's no rotations). My vertical field of view is 60°, the area I'm rendering to is 1920x850, which calculates my horiztonal field of view to be 105° (2 * atan(tan(FIELD_OF_VIEW_RADIANS / 2) * aspectRatio)). I use: distance = halfDimension / tan(FOV / 2) for both vertical and horizontal dimensions which gives me 646 & 818, respectively. Now this tells me that I need to position my camera 646 units away to fit the cube's vertically and 818 units away to fit the cube horizontally. I choose horizontally (so that the entire cube is
visible). This should be right, right?

The problem is that if I position my camera 818 units away the cube is smaller than the frustum. The cube is centered on the origin and on my screen, so the above math (assuming it's right) states that the very right of my screen is 606.5 positive units on the x-axis, making the cube just fit horizontally. However I can place a small cube at 1065 units on the x-axis and it's on the edge of my screen (I just picked numbers till the
cube was just on my screen).

I've looked over my math and it looks right. Maybe I'm missing something? Could their be something about the perspective camera I didn't take into account?

PARTNERS