| 343 | //----------------------------------------------------------------------------- |
| 344 | |
| 345 | void FrustumData::_update() const |
| 346 | { |
| 347 | if( !mDirty ) |
| 348 | return; |
| 349 | |
| 350 | PROFILE_SCOPE( Frustum_update ); |
| 351 | |
| 352 | const Point3F& cameraPos = mPosition; |
| 353 | |
| 354 | // Build the frustum points in camera space first. |
| 355 | |
| 356 | if( mIsOrtho ) |
| 357 | { |
| 358 | mPoints[ NearTopLeft ].set( mNearLeft, mNearDist, mNearTop ); |
| 359 | mPoints[ NearTopRight ].set( mNearRight, mNearDist, mNearTop ); |
| 360 | mPoints[ NearBottomLeft ].set( mNearLeft, mNearDist, mNearBottom ); |
| 361 | mPoints[ NearBottomRight ].set( mNearRight, mNearDist, mNearBottom ); |
| 362 | mPoints[ FarTopLeft ].set( mNearLeft, mFarDist, mNearTop ); |
| 363 | mPoints[ FarTopRight ].set( mNearRight, mFarDist, mNearTop ); |
| 364 | mPoints[ FarBottomLeft ].set( mNearLeft, mFarDist, mNearBottom ); |
| 365 | mPoints[ FarBottomRight ].set( mNearRight, mFarDist, mNearBottom ); |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | const F32 farOverNear = mFarDist / mNearDist; |
| 370 | |
| 371 | mPoints[ NearTopLeft ].set( mNearLeft, mNearDist, mNearTop ); |
| 372 | mPoints[ NearTopRight ].set( mNearRight, mNearDist, mNearTop ); |
| 373 | mPoints[ NearBottomLeft ].set( mNearLeft, mNearDist, mNearBottom ); |
| 374 | mPoints[ NearBottomRight ].set( mNearRight, mNearDist, mNearBottom ); |
| 375 | mPoints[ FarTopLeft ].set( mNearLeft * farOverNear, mFarDist, mNearTop * farOverNear ); |
| 376 | mPoints[ FarTopRight ].set( mNearRight * farOverNear, mFarDist, mNearTop * farOverNear ); |
| 377 | mPoints[ FarBottomLeft ].set( mNearLeft * farOverNear, mFarDist, mNearBottom * farOverNear ); |
| 378 | mPoints[ FarBottomRight ].set( mNearRight * farOverNear, mFarDist, mNearBottom * farOverNear ); |
| 379 | } |
| 380 | |
| 381 | // Transform the points into the desired culling space. |
| 382 | |
| 383 | for( U32 i = 0; i < mPoints.size(); ++ i ) |
| 384 | mTransform.mulP( mPoints[ i ] ); |
| 385 | |
| 386 | // Update the axis aligned bounding box from |
| 387 | // the newly transformed points. |
| 388 | |
| 389 | mBounds = Box3F::aroundPoints( mPoints.address(), mPoints.size() ); |
| 390 | |
| 391 | // Finally build the planes. |
| 392 | |
| 393 | if( mIsOrtho ) |
| 394 | { |
| 395 | mPlanes[ PlaneLeft ].set( mPoints[ NearBottomLeft ], |
| 396 | mPoints[ FarTopLeft ], |
| 397 | mPoints[ FarBottomLeft ] ); |
| 398 | |
| 399 | mPlanes[ PlaneRight ].set( mPoints[ NearTopRight ], |
| 400 | mPoints[ FarBottomRight ], |
| 401 | mPoints[ FarTopRight ] ); |
| 402 | |