| 284 | //----------------------------------------------------------------------------- |
| 285 | |
| 286 | F32 GuiTSCtrl::calculateViewDistance(F32 radius) |
| 287 | { |
| 288 | F32 fov = mLastCameraQuery.fov; |
| 289 | F32 wwidth; |
| 290 | F32 wheight; |
| 291 | F32 renderWidth = (mRenderStyle == RenderStyleStereoSideBySide) ? F32(getWidth())*0.5f : F32(getWidth()); |
| 292 | F32 renderHeight = F32(getHeight()); |
| 293 | F32 aspectRatio = renderWidth / renderHeight; |
| 294 | |
| 295 | // Use the FOV to calculate the viewport height scale |
| 296 | // then generate the width scale from the aspect ratio. |
| 297 | if(!mLastCameraQuery.ortho) |
| 298 | { |
| 299 | wheight = mLastCameraQuery.nearPlane * mTan(mLastCameraQuery.fov / 2.0f); |
| 300 | wwidth = aspectRatio * wheight; |
| 301 | } |
| 302 | else |
| 303 | { |
| 304 | wheight = mLastCameraQuery.fov; |
| 305 | wwidth = aspectRatio * wheight; |
| 306 | } |
| 307 | |
| 308 | // Now determine if we should use the width |
| 309 | // fov or height fov. |
| 310 | // |
| 311 | // If the window is taller than it is wide, use the |
| 312 | // width fov to keep the object completely in view. |
| 313 | if (wheight > wwidth) |
| 314 | fov = mAtan( wwidth / mLastCameraQuery.nearPlane ) * 2.0f; |
| 315 | |
| 316 | return radius / mTan(fov / 2.0f); |
| 317 | } |
| 318 | |
| 319 | //----------------------------------------------------------------------------- |
| 320 |
no test coverage detected