mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#168 Improved the front and back clipping plane calculation in relation to parallel projection.
Added a margin of 20% to account for inaccuracies. Not new for far-plane, but became missing in the first commit regarding parallel projection.
This commit is contained in:
parent
c529e18351
commit
a3499152a5
@ -273,31 +273,53 @@ void caf::Viewer::optimizeClippingPlanes()
|
|||||||
cvf::Vec3d bboxCorners[8];
|
cvf::Vec3d bboxCorners[8];
|
||||||
bb.cornerVertices(bboxCorners);
|
bb.cornerVertices(bboxCorners);
|
||||||
|
|
||||||
|
// Find the distance to the bbox corners most behind and most in front of camera
|
||||||
|
|
||||||
double maxDistEyeToCornerAlongViewDir = -HUGE_VAL;
|
double maxDistEyeToCornerAlongViewDir = -HUGE_VAL;
|
||||||
double minDistEyeToCornerAlongViewDir = HUGE_VAL;
|
double minDistEyeToCornerAlongViewDir = HUGE_VAL;
|
||||||
for (int bcIdx = 0; bcIdx < 8; ++bcIdx )
|
for (int bcIdx = 0; bcIdx < 8; ++bcIdx )
|
||||||
{
|
{
|
||||||
double distEyeBoxCornerAlongViewDir = (bboxCorners[bcIdx] - eye)*viewdir;
|
double distEyeBoxCornerAlongViewDir = (bboxCorners[bcIdx] - eye)*viewdir;
|
||||||
|
|
||||||
if (distEyeBoxCornerAlongViewDir > maxDistEyeToCornerAlongViewDir)
|
if (distEyeBoxCornerAlongViewDir > maxDistEyeToCornerAlongViewDir)
|
||||||
|
{
|
||||||
maxDistEyeToCornerAlongViewDir = distEyeBoxCornerAlongViewDir;
|
maxDistEyeToCornerAlongViewDir = distEyeBoxCornerAlongViewDir;
|
||||||
if (distEyeBoxCornerAlongViewDir < minDistEyeToCornerAlongViewDir)
|
|
||||||
minDistEyeToCornerAlongViewDir = distEyeBoxCornerAlongViewDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double farPlaneDist = CVF_MIN(maxDistEyeToCornerAlongViewDir, m_maxFarPlaneDistance);
|
if (distEyeBoxCornerAlongViewDir < minDistEyeToCornerAlongViewDir)
|
||||||
double nearPlaneDist = minDistEyeToCornerAlongViewDir;
|
{
|
||||||
|
minDistEyeToCornerAlongViewDir = distEyeBoxCornerAlongViewDir; // Sometimes negative-> behind camera
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double farPlaneDist = CVF_MIN(maxDistEyeToCornerAlongViewDir * 1.2, m_maxFarPlaneDistance);
|
||||||
|
|
||||||
|
// Near-plane:
|
||||||
|
|
||||||
bool isOrthoNearPlaneFollowingCamera = false;
|
bool isOrthoNearPlaneFollowingCamera = false;
|
||||||
|
double nearPlaneDist = HUGE_VAL;
|
||||||
|
|
||||||
|
// If we have perspective projection, set the near plane just in front of camera, and not behind
|
||||||
|
|
||||||
if (m_mainCamera->projection() == cvf::Camera::PERSPECTIVE || isOrthoNearPlaneFollowingCamera)
|
if (m_mainCamera->projection() == cvf::Camera::PERSPECTIVE || isOrthoNearPlaneFollowingCamera)
|
||||||
{
|
{
|
||||||
if (nearPlaneDist < m_minNearPlaneDistance) nearPlaneDist = m_minNearPlaneDistance;
|
nearPlaneDist = CVF_MAX( m_minNearPlaneDistance, minDistEyeToCornerAlongViewDir);
|
||||||
if (m_navigationPolicy.notNull() && m_navigationPolicyEnabled)
|
if (m_navigationPolicy.notNull() && m_navigationPolicyEnabled)
|
||||||
{
|
{
|
||||||
double pointOfInterestDist = (eye - m_navigationPolicy->pointOfInterest()).length();
|
double pointOfInterestDist = (eye - m_navigationPolicy->pointOfInterest()).length();
|
||||||
nearPlaneDist = CVF_MIN(nearPlaneDist, pointOfInterestDist*0.2);
|
nearPlaneDist = CVF_MIN(nearPlaneDist, pointOfInterestDist*0.2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else // Orthographic projection. Set to encapsulate the complete boundingbox, possibly setting a negative nearplane
|
||||||
|
{
|
||||||
|
if(minDistEyeToCornerAlongViewDir >= 0)
|
||||||
|
{
|
||||||
|
nearPlaneDist = CVF_MIN(0.8 * minDistEyeToCornerAlongViewDir, m_maxFarPlaneDistance);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nearPlaneDist = CVF_MAX(1.2 * minDistEyeToCornerAlongViewDir, -m_maxFarPlaneDistance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
Loading…
Reference in New Issue
Block a user