Commit 5d54447a authored by Jan Möbius's avatar Jan Möbius
Browse files

Moved scene and trackball radius and center to viewerproperties

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10427 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 904f56f8
...@@ -78,7 +78,11 @@ namespace Viewer { ...@@ -78,7 +78,11 @@ namespace Viewer {
rotationLocked_(false), rotationLocked_(false),
orthoWidth_(2.0), orthoWidth_(2.0),
nearPlane_(0.01), nearPlane_(0.01),
farPlane_(100.0) farPlane_(100.0),
sceneCenter_(ACG::Vec3d( 0.0, 0.0, 0.0 )),
sceneRadius_(1.0),
trackballCenter_(ACG::Vec3d( 0.0, 0.0, 0.0 )),
trackballRadius_(1.0)
{ {
} }
......
...@@ -420,18 +420,48 @@ namespace Viewer { ...@@ -420,18 +420,48 @@ namespace Viewer {
/// Set the width of the gl scene in orthogonal projection mode /// Set the width of the gl scene in orthogonal projection mode
void orthoWidth(double _width){ orthoWidth_ = _width; emit updated(); }; void orthoWidth(double _width){ orthoWidth_ = _width; emit updated(); };
/// Return distance to near Plane /// Return distance to near Plane
double nearPlane(){ return nearPlane_;}; double nearPlane(){ return nearPlane_;};
/// set new near Plane distance /// set new near Plane distance
void nearPlane(double _near){nearPlane_ = _near; emit updated(); }; void nearPlane(double _near){nearPlane_ = _near; emit updated(); };
/// Return distance to far Plane /// Return distance to far Plane
double farPlane(){ return farPlane_;}; double farPlane(){ return farPlane_;};
/// set new near Plane distance /// set new near Plane distance
void farPlane(double _far){farPlane_ = _far; emit updated(); }; void farPlane(double _far){farPlane_ = _far; emit updated(); };
/// Get current scene center (rendering center)
ACG::Vec3d sceneCenter(){ return sceneCenter_; };
/// Set current scene center (rendering center)
void sceneCenter(ACG::Vec3d _center){ sceneCenter_ = _center; emit updated(); };
/// Get radius of the current scene
double sceneRadius() {return sceneRadius_;};
/// Set radius of the current scene
void sceneRadius(double _radius ) { sceneRadius_ = _radius; emit updated();};
/// Get virtual trackball center (rotation center when using mouse)
ACG::Vec3d trackballCenter(){ return trackballCenter_; };
/// Set virtual trackball center (rotation center when using mouse)
void trackballCenter(ACG::Vec3d _center){ trackballCenter_ = _center; emit updated(); };
/// Get trackball radius (rotation sphere when using mouse)
double trackballRadius() {return trackballRadius_;};
/// Set trackball radius (rotation sphere when using mouse)
void trackballRadius(double _radius ) { trackballRadius_ = _radius; emit updated();};
private: private:
/// Width of the gl scene in orthogonal mode ( defaults to 2.0 ) /// Width of the gl scene in orthogonal mode ( defaults to 2.0 )
...@@ -442,8 +472,19 @@ namespace Viewer { ...@@ -442,8 +472,19 @@ namespace Viewer {
///distance to far Plane ///distance to far Plane
double farPlane_; double farPlane_;
/// Current scene center (rendering center)
ACG::Vec3d sceneCenter_;
/// Radius of the current scene
double sceneRadius_;
/// Virtual trackball center (rotation center when using mouse)
ACG::Vec3d trackballCenter_;
/// trackball radius (rotation sphere when using mouse)
double trackballRadius_;
/** @} */ /** @} */
......
...@@ -442,20 +442,21 @@ void glViewer::updateProjectionMatrix() ...@@ -442,20 +442,21 @@ void glViewer::updateProjectionMatrix()
void glViewer::setScenePos(const ACG::Vec3d& _center, double _radius, const bool _resetTrackBall) void glViewer::setScenePos(const ACG::Vec3d& _center, double _radius, const bool _resetTrackBall)
{ {
if(_resetTrackBall) { if(_resetTrackBall) {
trackball_center_ = _center; properties_.trackballCenter(_center);
} }
scene_center_ = _center; properties_.sceneCenter(_center);
scene_radius_ = trackball_radius_ = _radius; properties_.sceneRadius(_radius);
properties_.trackballRadius(_radius);
ACG::Vec3d c = glstate_->modelview().transform_point(scene_center_); ACG::Vec3d c = glstate_->modelview().transform_point(properties_.sceneCenter());
// Set far plane // Set far plane
properties_.farPlane( std::max(0.0002f * scene_radius_, -(c[2] - scene_radius_)) ); properties_.farPlane( std::max(0.0002f * properties_.sceneRadius(), -(c[2] - properties_.sceneRadius() )) );
// Set near plane // Set near plane
properties_.nearPlane( std::max(0.0001f * scene_radius_, -(c[2] + scene_radius_)) ); properties_.nearPlane( std::max(0.0001f * properties_.sceneRadius(), -(c[2] + properties_.sceneRadius())) );
updateProjectionMatrix(); updateProjectionMatrix();
updateGL(); updateGL();
...@@ -463,19 +464,6 @@ void glViewer::setScenePos(const ACG::Vec3d& _center, double _radius, const bool ...@@ -463,19 +464,6 @@ void glViewer::setScenePos(const ACG::Vec3d& _center, double _radius, const bool
emit viewChanged(); emit viewChanged();
} }
//-----------------------------------------------------------------------------
void glViewer::setSceneCenter( const ACG::Vec3d& _center ) {
scene_center_ = _center;
}
//-----------------------------------------------------------------------------
void glViewer::setTrackBallCenter( const ACG::Vec3d& _center ) {
trackball_center_ = _center;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -483,10 +471,10 @@ void glViewer::setTrackBallCenter( const ACG::Vec3d& _center ) { ...@@ -483,10 +471,10 @@ void glViewer::setTrackBallCenter( const ACG::Vec3d& _center ) {
void glViewer::viewingDirection( const ACG::Vec3d& _dir, const ACG::Vec3d& _up ) void glViewer::viewingDirection( const ACG::Vec3d& _dir, const ACG::Vec3d& _up )
{ {
// calc eye point for this direction // calc eye point for this direction
ACG::Vec3d eye = scene_center_ - _dir*(3.0*scene_radius_); ACG::Vec3d eye = properties_.sceneCenter() - _dir * ( 3.0 * properties_.sceneRadius());
glstate_->reset_modelview(); glstate_->reset_modelview();
glstate_->lookAt((ACG::Vec3d)eye, (ACG::Vec3d)scene_center_, (ACG::Vec3d)_up); glstate_->lookAt((ACG::Vec3d)eye, (ACG::Vec3d)properties_.sceneCenter(), (ACG::Vec3d)_up);
emit viewChanged(); emit viewChanged();
} }
...@@ -498,8 +486,8 @@ void glViewer::lookAt(const ACG::Vec3d& _eye, const ACG::Vec3d& _center, const A ...@@ -498,8 +486,8 @@ void glViewer::lookAt(const ACG::Vec3d& _eye, const ACG::Vec3d& _center, const A
glstate_->reset_modelview(); glstate_->reset_modelview();
glstate_->lookAt(_eye, _center, _up); glstate_->lookAt(_eye, _center, _up);
scene_center_ = _center; properties_.sceneCenter( _center );
scene_radius_ = (scene_center_ - _eye).norm(); properties_.sceneRadius( (properties_.sceneCenter() - _eye).norm() );
emit viewChanged(); emit viewChanged();
} }
...@@ -571,13 +559,13 @@ void glViewer::drawScene() ...@@ -571,13 +559,13 @@ void glViewer::drawScene()
// Adjust clipping planes // Adjust clipping planes
// ***************************************************************** // *****************************************************************
// Far plane // Far plane
ACG::Vec3d c = glstate_->modelview().transform_point(scene_center_); ACG::Vec3d c = glstate_->modelview().transform_point(properties_.sceneCenter());
// Set far plane // Set far plane
properties_.farPlane( std::max(0.0002f * scene_radius_, -(c[2] - scene_radius_)) ); properties_.farPlane( std::max(0.0002f * properties_.sceneRadius(), -(c[2] - properties_.sceneRadius())) );
// Set near plane // Set near plane
properties_.nearPlane( std::max(0.0001f * scene_radius_, -(c[2] + scene_radius_)) ); properties_.nearPlane( std::max(0.0001f * properties_.sceneRadius(), -(c[2] + properties_.sceneRadius())) );
updateProjectionMatrix(); updateProjectionMatrix();
...@@ -791,8 +779,8 @@ void glViewer::setHome() ...@@ -791,8 +779,8 @@ void glViewer::setHome()
home_modelview_ = glstate_->modelview(); home_modelview_ = glstate_->modelview();
home_inverse_modelview_ = glstate_->inverse_modelview(); home_inverse_modelview_ = glstate_->inverse_modelview();
homeOrthoWidth_ = properties_.orthoWidth(); homeOrthoWidth_ = properties_.orthoWidth();
home_center_ = trackball_center_; home_center_ = properties_.trackballCenter();
home_radius_ = trackball_radius_; home_radius_ = properties_.trackballRadius();
} }
...@@ -801,8 +789,8 @@ void glViewer::home() ...@@ -801,8 +789,8 @@ void glViewer::home()
makeCurrent(); makeCurrent();
glstate_->set_modelview(home_modelview_, home_inverse_modelview_); glstate_->set_modelview(home_modelview_, home_inverse_modelview_);
properties_.orthoWidth( homeOrthoWidth_ ); properties_.orthoWidth( homeOrthoWidth_ );
trackball_center_ = home_center_; properties_.trackballCenter( home_center_ );
trackball_radius_ = home_radius_; properties_.trackballRadius(home_radius_);
updateProjectionMatrix(); updateProjectionMatrix();
updateGL(); updateGL();
...@@ -816,27 +804,27 @@ void glViewer::home() ...@@ -816,27 +804,27 @@ void glViewer::home()
void glViewer::viewAll() void glViewer::viewAll()
{ {
makeCurrent(); makeCurrent();
// update scene graph (get new bounding box and set projection right, including near and far plane) // update scene graph (get new bounding box and set projection right, including near and far plane)
properties_.lockUpdate(); properties_.lockUpdate();
// move center (in camera coords) to origin and translate in -z dir // move center (in camera coords) to origin and translate in -z dir
translate(-(glstate_->modelview().transform_point(scene_center_)) translate(-(glstate_->modelview().transform_point(properties_.sceneCenter()))
- ACG::Vec3d(0.0, 0.0, 3.0 * scene_radius_)); - ACG::Vec3d(0.0, 0.0, 3.0 * properties_.sceneRadius()));
properties_.orthoWidth( 1.1 * scene_radius_ ); properties_.orthoWidth( 1.1 * properties_.sceneRadius() );
double aspect = (double) glWidth() / (double) glHeight(); double aspect = (double) glWidth() / (double) glHeight();
if (aspect > 1.0) if (aspect > 1.0)
properties_.orthoWidth( aspect * properties_.orthoWidth() ) ; properties_.orthoWidth( aspect * properties_.orthoWidth() ) ;
sceneGraph(PluginFunctions::getSceneGraphRootNode(), true); sceneGraph(PluginFunctions::getSceneGraphRootNode(), true);
properties_.unLockUpdate(); properties_.unLockUpdate();
updateProjectionMatrix(); updateProjectionMatrix();
updateGL(); updateGL();
emit viewChanged(); emit viewChanged();
} }
...@@ -885,7 +873,7 @@ void glViewer::flyTo(const QPoint& _pos, bool _move_back) ...@@ -885,7 +873,7 @@ void glViewer::flyTo(const QPoint& _pos, bool _move_back)
// Set the double click point as the new trackball center // Set the double click point as the new trackball center
// Rotations will use this point as the center. // Rotations will use this point as the center.
trackball_center_ = hitPoint; properties_.trackballCenter( hitPoint );
// how many frames in _time ms ? // how many frames in _time ms ?
unsigned int frames = (unsigned int)(300 / frame_time_); unsigned int frames = (unsigned int)(300 / frame_time_);
...@@ -1004,9 +992,8 @@ void glViewer::flyTo(const ACG::Vec3d& _position, ...@@ -1004,9 +992,8 @@ void glViewer::flyTo(const ACG::Vec3d& _position,
} }
trackball_center_ = _center; properties_.trackballCenter( _center );
trackball_radius_ = std::max(scene_radius_, properties_.trackballRadius( std::max( properties_.sceneRadius(),( _center - _position ).norm() * 0.9f ) );
(_center-_position).norm()*0.9f);
} }
...@@ -1049,11 +1036,6 @@ void glViewer::initializeGL() ...@@ -1049,11 +1036,6 @@ void glViewer::initializeGL()
// Update all settings which would require a redraw // Update all settings which would require a redraw
applyProperties(); applyProperties();
// scene pos and size
scene_center_ = trackball_center_ = ACG::Vec3d( 0.0, 0.0, 0.0 );
scene_radius_ = trackball_radius_ = 1.0;
// modelview // modelview
glstate_->translate(0.0, 0.0, -3.0); glstate_->translate(0.0, 0.0, -3.0);
setHome(); setHome();
...@@ -1459,7 +1441,7 @@ void glViewer::slotWheelY(double _dAngle) ...@@ -1459,7 +1441,7 @@ void glViewer::slotWheelY(double _dAngle)
void glViewer::slotWheelZ(double _dist) void glViewer::slotWheelZ(double _dist)
{ {
double dz=_dist*0.5/M_PI*scene_radius_*2.0; double dz = _dist * 0.5 / M_PI * properties_.sceneRadius() * 2.0;
translate(ACG::Vec3d(0,0,dz)); translate(ACG::Vec3d(0,0,dz));
updateGL(); updateGL();
...@@ -1860,8 +1842,8 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) { ...@@ -1860,8 +1842,8 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) {
if (_event->modifiers() & Qt::ShiftModifier) { if (_event->modifiers() & Qt::ShiftModifier) {
ACG::Vec3d c; ACG::Vec3d c;
if (fast_pick(pos, c)) { if (fast_pick(pos, c)) {
trackball_center_ = c; properties_.trackballCenter( c );
trackball_radius_ = std::max(scene_radius_, (c - glstate_->eye()).norm() * 0.9f); properties_.trackballRadius( std::max(properties_.sceneRadius(), (c - glstate_->eye()).norm() * 0.9f) );
} }
} }
...@@ -1899,7 +1881,7 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) { ...@@ -1899,7 +1881,7 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) {
if ((_event->buttons() & Qt::LeftButton) && (_event->buttons() & Qt::MidButton)) { if ((_event->buttons() & Qt::LeftButton) && (_event->buttons() & Qt::MidButton)) {
switch (projectionMode()) { switch (projectionMode()) {
case PERSPECTIVE_PROJECTION: { case PERSPECTIVE_PROJECTION: {
value_y = scene_radius_ * ((newPoint2D.y() - lastPoint2D_.y())) * 3.0 / (double) glHeight(); value_y = properties_.sceneRadius() * ((newPoint2D.y() - lastPoint2D_.y())) * 3.0 / (double) glHeight();
translate(ACG::Vec3d(0.0, 0.0, value_y * factor)); translate(ACG::Vec3d(0.0, 0.0, value_y * factor));
updateGL(); updateGL();
emit viewChanged(); emit viewChanged();
...@@ -1929,8 +1911,8 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) { ...@@ -1929,8 +1911,8 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) {
// if start depth is 1, no object was hit when starting translation // if start depth is 1, no object was hit when starting translation
if ( startDepth_ == 1 ) { if ( startDepth_ == 1 ) {
value_x = scene_radius_ * ((newPoint2D.x() - lastPoint2D_.x())) * 2.0 / (double) glWidth(); value_x = properties_.sceneRadius() * ((newPoint2D.x() - lastPoint2D_.x())) * 2.0 / (double) glWidth();
value_y = scene_radius_ * ((newPoint2D.y() - lastPoint2D_.y())) * 2.0 / (double) glHeight(); value_y = properties_.sceneRadius() * ((newPoint2D.y() - lastPoint2D_.y())) * 2.0 / (double) glHeight();
translation = ACG::Vec3d(value_x * factor, -value_y * factor, 0.0); translation = ACG::Vec3d(value_x * factor, -value_y * factor, 0.0);
} else { } else {
...@@ -2017,7 +1999,7 @@ void glViewer::viewWheelEvent( QWheelEvent* _event) ...@@ -2017,7 +1999,7 @@ void glViewer::viewWheelEvent( QWheelEvent* _event)
if (projectionMode() == PERSPECTIVE_PROJECTION || stereo_) if (projectionMode() == PERSPECTIVE_PROJECTION || stereo_)
{ {
double d = -(double)_event->delta() / 120.0 * 0.2 * factor * trackball_radius_/3; double d = -(double)_event->delta() / 120.0 * 0.2 * factor * properties_.trackballRadius() / 3.0;
translate( ACG::Vec3d(0.0, 0.0, d) ); translate( ACG::Vec3d(0.0, 0.0, d) );
updateGL(); updateGL();
} }
......
...@@ -218,28 +218,28 @@ public: ...@@ -218,28 +218,28 @@ public:
/** /**
* Set new center point of scene * Set new center point of scene
*/ */
void setSceneCenter( const ACG::Vec3d& _center ); void setSceneCenter( const ACG::Vec3d& _center ) { properties_.sceneCenter(_center); };
/** \brief Set Trackball Center point of scene /** \brief Set Trackball Center point of scene
* *
* The scene is rotated around the trackball center when using the mouse * The scene is rotated around the trackball center when using the mouse
*/ */
void setTrackBallCenter( const ACG::Vec3d& _center ); void setTrackBallCenter( const ACG::Vec3d& _center ) { properties_.trackballCenter(_center); }
/** \brief Get Trackball Center point of scene /** \brief Get Trackball Center point of scene
* *
* The scene is rotated around the trackball center when using the mouse * The scene is rotated around the trackball center when using the mouse
*/ */
const ACG::Vec3d trackBallCenter( ) { return trackball_center_; }; const ACG::Vec3d trackBallCenter( ) { return properties_.trackballCenter(); };
/** Get scene's center /** Get scene's center
\see setScenePos() \see setScenePos()
*/ */
const ACG::Vec3d& scene_center() const { return scene_center_; } const ACG::Vec3d scene_center() const { return properties_.sceneCenter(); }
/** Get scene's radius /** Get scene's radius
\see setScenePos() \see setScenePos()
*/ */
double scene_radius() const { return scene_radius_; } double scene_radius() const { return properties_.sceneRadius(); }
/// set the viewing direction /// set the viewing direction
void viewingDirection( const ACG::Vec3d& _dir, const ACG::Vec3d& _up ); void viewingDirection( const ACG::Vec3d& _dir, const ACG::Vec3d& _up );
...@@ -311,7 +311,7 @@ public: ...@@ -311,7 +311,7 @@ public:
/// rotate the scene (around its center) and update modelview matrix /// rotate the scene (around its center) and update modelview matrix
void rotate(const ACG::Vec3d& axis, double angle) void rotate(const ACG::Vec3d& axis, double angle)
{ rotate(axis, angle, trackball_center_); } { rotate(axis, angle, properties_.trackballCenter()); }
/// rotate the scene and update modelview matrix /// rotate the scene and update modelview matrix
void rotate(const ACG::Vec3d& axis, double angle, const ACG::Vec3d& _center); void rotate(const ACG::Vec3d& axis, double angle, const ACG::Vec3d& _center);
...@@ -543,11 +543,6 @@ private: ...@@ -543,11 +543,6 @@ private:
//-------------------------------------------------------------- protected data //-------------------------------------------------------------- protected data
protected: protected:
// scene center and radius
ACG::Vec3d scene_center_, trackball_center_;
double scene_radius_, trackball_radius_;
// helper // helper
bool isRotating_; bool isRotating_;
bool lookAround_; bool lookAround_;
......
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