Commit ba6273b2 authored by Jan Möbius's avatar Jan Möbius

Modified ViewerProperties to allow setting near and far plane via one function only.

Would lead to inconsistencies if they are updated one after the other (e.g. setting a larger near plane before far is increased will lead to a temporary near>far)

Improved detection of wrong near and far planes in the core.

closes #1368

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16072 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1de860b5
......@@ -436,17 +436,12 @@ namespace Viewer {
/// Return distance to near Plane
double nearPlane(){ return nearPlane_;};
/// set new near Plane distance
void nearPlane(double _near){nearPlane_ = _near; emit updated(); };
/// Set near and far plane at the same time
void setPlanes( double _near, double _far ) {nearPlane_ = _near; farPlane_ = _far; emit updated();} ;
/// Return distance to far Plane
double farPlane(){ return farPlane_;};
/// set new near Plane distance
void farPlane(double _far){farPlane_ = _far; emit updated(); };
/// Get current scene center (rendering center)
ACG::Vec3d sceneCenter(){ return sceneCenter_; };
......
......@@ -456,12 +456,23 @@ void glViewer::setScenePos(const ACG::Vec3d& _center, double _radius, const bool
ACG::Vec3d c = glstate_->modelview().transform_point(properties_.sceneCenter());
// Set far plane
properties_.farPlane( std::max(0.0002f * properties_.sceneRadius(), -(c[2] - properties_.sceneRadius() )) );
double near = std::max(0.0001f * properties_.sceneRadius(), -(c[2] + properties_.sceneRadius()));
double far = std::max(0.0002f * properties_.sceneRadius(), -(c[2] - properties_.sceneRadius()));
// Safety check, if near < 0
if ( near <= 0.0 ) {
std::cerr << "Error in BaseViewer drawScene, nearplane <= 0.0" << std::endl;
near = 0.000000000000001;
}
// Safety check. Make sure that they are in the right order
if ( near > far ) {
std::cerr << "Error in BaseViewer setScenePos, Nearplane > Farplane" << std::endl;
std::swap(near,far);
}
properties_.setPlanes(near,far);
// Set near plane
properties_.nearPlane( std::max(0.0001f * properties_.sceneRadius(), -(c[2] + properties_.sceneRadius())) );
updateProjectionMatrix();
updateGL();
......@@ -567,11 +578,22 @@ void glViewer::drawScene()
// Far plane
ACG::Vec3d c = glstate_->modelview().transform_point(properties_.sceneCenter());
// Set far plane
properties_.farPlane( std::max(0.0002f * properties_.sceneRadius(), -(c[2] - properties_.sceneRadius())) );
double near = std::max(0.0001f * properties_.sceneRadius(), -(c[2] + properties_.sceneRadius()));
double far = std::max(0.0002f * properties_.sceneRadius(), -(c[2] - properties_.sceneRadius()));
// Safety check, if near < 0
if ( near <= 0.0 ) {
std::cerr << "Error in BaseViewer drawScene, nearplane < 0" << std::endl;
near = 0.000000000000001;
}
// Safety check. Make sure that they are in the right order
if ( near > far ) {
std::cerr << "Error in BaseViewer drawScene, Nearplane > Farplane" << std::endl;
std::swap(near,far);
}
// Set near plane
properties_.nearPlane( std::max(0.0001f * properties_.sceneRadius(), -(c[2] + properties_.sceneRadius())) );
properties_.setPlanes(near,far);
updateProjectionMatrix();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment