MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / calculateViewDistance

Method calculateViewDistance

Engine/source/gui/3d/guiTSControl.cpp:286–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284//-----------------------------------------------------------------------------
285
286F32 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

Callers 1

guiTSControl.cppFile · 0.80

Calls 4

getWidthFunction · 0.85
mTanFunction · 0.85
mAtanFunction · 0.85
getHeightFunction · 0.50

Tested by

no test coverage detected