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

Method bakeProjectionOffset

Engine/source/math/util/frustum.cpp:251–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249//-----------------------------------------------------------------------------
250
251bool Frustum::bakeProjectionOffset()
252{
253 // Nothing to bake if ortho
254 if( mIsOrtho )
255 return false;
256
257 // Nothing to bake if no offset
258 if( mProjectionOffset.isZero() )
259 return false;
260
261 // Near plane points in camera space
262 Point3F np[4];
263 np[0].set( mNearLeft, mNearDist, mNearTop ); // NearTopLeft
264 np[1].set( mNearRight, mNearDist, mNearTop ); // NearTopRight
265 np[2].set( mNearLeft, mNearDist, mNearBottom ); // NearBottomLeft
266 np[3].set( mNearRight, mNearDist, mNearBottom ); // NearBottomRight
267
268 // Generate the near plane
269 PlaneF nearPlane( np[0], np[1], np[3] );
270
271 // Far plane points in camera space
272 const F32 farOverNear = mFarDist / mNearDist;
273 Point3F fp0( mNearLeft * farOverNear, mFarDist, mNearTop * farOverNear ); // FarTopLeft
274 Point3F fp1( mNearRight * farOverNear, mFarDist, mNearTop * farOverNear ); // FarTopRight
275 Point3F fp2( mNearLeft * farOverNear, mFarDist, mNearBottom * farOverNear ); // FarBottomLeft
276 Point3F fp3( mNearRight * farOverNear, mFarDist, mNearBottom * farOverNear ); // FarBottomRight
277
278 // Generate the far plane
279 PlaneF farPlane( fp0, fp1, fp3 );
280
281 // The offset camera point
282 Point3F offsetCamera( mProjectionOffset.x, 0.0f, mProjectionOffset.y );
283
284 // The near plane point we'll be using for our calculations below
285 U32 nIndex = 0;
286 if( mProjectionOffset.x < 0.0 )
287 {
288 // Offset to the left so we'll need to use the near plane point on the right
289 nIndex = 1;
290 }
291 if( mProjectionOffset.y > 0.0 )
292 {
293 // Offset to the top so we'll need to use the near plane point at the bottom
294 nIndex += 2;
295 }
296
297 // Begin by calculating the offset point on the far plane as it goes
298 // from the offset camera to the edge of the near plane.
299 Point3F farPoint;
300 Point3F fdir = np[nIndex] - offsetCamera;
301 fdir.normalize();
302 if( farPlane.intersect(offsetCamera, fdir, &farPoint) )
303 {
304 // Calculate the new near plane edge from the non-offset camera position
305 // to the far plane point from above.
306 Point3F nearPoint;
307 Point3F ndir = farPoint;
308 ndir.normalize();

Callers 1

SceneCullingStateMethod · 0.80

Calls 4

isZeroMethod · 0.45
setMethod · 0.45
normalizeMethod · 0.45
intersectMethod · 0.45

Tested by

no test coverage detected