Commit 2c86a948 authored by Jan Möbius's avatar Jan Möbius

Dennis:

Improved Stereo support
Options for stereo settings

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5572 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 01eecace
......@@ -168,6 +168,16 @@ void Core::readApplicationOptions(INIFile& _ini) {
if ( _ini.get_entry( stereoMode, "Options" , "StereoMode") )
OpenFlipper::Options::stereoMode(static_cast<OpenFlipper::Options::StereoMode> (stereoMode));
//============================================================================
// Load stereo view settings
//============================================================================
float val;
if ( _ini.get_entry( val, "Options" , "EyeDistance") )
OpenFlipper::Options::eyeDistance(val);
if ( _ini.get_entry( val, "Options" , "FocalDistance") )
OpenFlipper::Options::focalDistance(val);
//============================================================================
// Load the custom anaglyph stereo mode color matrices
//============================================================================
......@@ -517,6 +527,9 @@ void Core::writeApplicationOptions(INIFile& _ini) {
_ini.add_entry("Options","StereoMode",OpenFlipper::Options::stereoMode() );
_ini.add_entry("Options" , "EyeDistance", OpenFlipper::Options::eyeDistance());
_ini.add_entry("Options" , "FocalDistance", OpenFlipper::Options::focalDistance());
_ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() );
_ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() );
}
......
......@@ -95,7 +95,13 @@ static bool stereo_ = true;
static bool glStereo_ = true;
/// Stereo mode
StereoMode stereoMode_ = OpenGL;
static StereoMode stereoMode_ = OpenGL;
/// get stereo eye distance (default = 7cm)
static float eyeDistance_ = 0.07;
/// stereo focal distance relative to scene near plane (default = to center of scene)
static float focalDistance_ = 0.5;
/// vectroy containing left/right color matrices for custom anaglyph mode
std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0);
......@@ -440,6 +446,30 @@ StereoMode stereoMode( ) {
return stereoMode_;
}
/// Store stereo eye distance
void eyeDistance( float _eye )
{
eyeDistance_ = _eye;
}
/// get stereo eye distance
float eyeDistance( )
{
return eyeDistance_;
}
/// Store stereo focal distance relative to scene near plane
void focalDistance( float _focal )
{
focalDistance_ = _focal;
}
/// get stereo focal distance relative to scene near plane
float focalDistance( )
{
return focalDistance_;
}
/// Store the 3x3 left eye color matrix values for custom anaglyph stereo mode
void anaglyphLeftEyeColorMatrix( std::vector<float> _mat )
{
......
......@@ -340,6 +340,22 @@ void fontsDir(QDir _dir);
DLLEXPORT
StereoMode stereoMode( );
/// Store stereo eye distance
DLLEXPORT
void eyeDistance( float _eye );
/// get stereo eye distance
DLLEXPORT
float eyeDistance( );
/// Store stereo focal distance relative to scene near plane
DLLEXPORT
void focalDistance( float _focal );
/// get stereo focal distance relative to scene near plane
DLLEXPORT
float focalDistance( );
/// Store the 3x3 left eye color matrix values for custom anaglyph stereo mode
DLLEXPORT
void anaglyphLeftEyeColorMatrix( std::vector<float> _mat );
......
......@@ -458,8 +458,6 @@ void CoreWidget::registerCoreKeys() {
emit registerKey(Qt::Key_L , Qt::ControlModifier, "Show/Hide Logger");
emit registerKey(Qt::Key_T , Qt::ControlModifier, "Show/Hide Toolbox");
emit registerKey(Qt::Key_F , Qt::ControlModifier, "Toggle Fullscreen");
emit registerKey(Qt::Key_E , Qt::ControlModifier | Qt::AltModifier, "Adjust Eye distance for stereo mode");
emit registerKey(Qt::Key_F , Qt::ControlModifier | Qt::AltModifier, "Adjust Focal distance for stereo mode");
emit registerKey(Qt::Key_Escape , Qt::NoModifier, "Switch to last action mode ( Move,Picking,Light or Info Mode)");
emit registerKey(Qt::Key_Space , Qt::NoModifier, "Toggle between multiview and single view");
......@@ -471,75 +469,28 @@ void CoreWidget::registerCoreKeys() {
void CoreWidget::coreKeyPressEvent (QKeyEvent* _e){
if (_e->modifiers() & Qt::ControlModifier ) {
if (_e->modifiers() & Qt::AltModifier )
if ( OpenFlipper::Options::stereo() ) {
switch (_e->key()) {
// Stereo seeing: eye distance
case Qt::Key_E:
{
bool ok(false);
double val = QInputDialog::getDouble( this, "Eye Dist", "Eye Dist:",
examiner_widgets_[0]->eyeDistance(),
0.0, 100.0, 10,
&ok);
if (ok) {
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i)
examiner_widgets_[i]->setEyeDistance(val);
}
break;
}
// Stereo setting: focal length
case Qt::Key_F:
{
bool ok(false);
double val = QInputDialog::getDouble( this, "Focal Dist", "Focal Dist:",
examiner_widgets_[0]->focalDistance(),
0.0, 100.0, 10,
&ok);
if (ok) {
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i)
examiner_widgets_[i]->setFocalDistance(val);
}
break;
}
default:
break;
}
} else
emit log(LOGWARN,"Activate stereo mode to change stereo settings");
else
switch (_e->key()) {
case Qt::Key_F :
toggleFullscreen();
return;
switch (_e->key()) {
case Qt::Key_F :
toggleFullscreen();
return;
case Qt::Key_L :
toggleLogger();
return;
case Qt::Key_L :
toggleLogger();
return;
case Qt::Key_T :
toggleToolbox();
return;
case Qt::Key_T :
toggleToolbox();
return;
case Qt::Key_O :
loadMenu();
case Qt::Key_O :
loadMenu();
case Qt::Key_S :
saveMenu();
case Qt::Key_S :
saveMenu();
default:
return;
}
default:
return;
}
}
......
......@@ -147,9 +147,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene,
far_ = 100.0;
fovy_ = 45.0;
focalDist_ = 3.0;
eyeDist_ = 0.01;
sceneGraphRoot_ = 0;
normalsMode_ = DONT_TOUCH_NORMALS;
......
......@@ -554,29 +554,9 @@ private:
/// enable/disable stereo mode
virtual void setStereoMode(bool _b);
public:
/** \brief Set eye distance for stereo
*
* Set the eye distance used for stereo projection. The function will enforce a redraw.
*/
void setEyeDistance(double _distance);
/// Get the current eye Distance
double eyeDistance( );
/** \brief Set focal distance for stereo
*
* Set the focal distance used for stereo projection. The function will enforce a redraw.
*/
void setFocalDistance(double _distance);
/// Get the current focal Distance
double focalDistance( );
private:
// stereo stuff
bool stereo_;
double eyeDist_, focalDist_;
// custom anaglyph stuff
int agTexWidth_;
......
......@@ -71,27 +71,6 @@ static const char* customAnaglyphProg = {
//-----------------------------------------------------------------------------
void glViewer::setEyeDistance(double _distance) {
eyeDist_ = _distance;
updateGL();
}
double glViewer::eyeDistance( ) {
return eyeDist_;
}
void glViewer::setFocalDistance(double _distance) {
focalDist_ = _distance;
updateGL();
}
double glViewer::focalDistance( ) {
return focalDist_;
}
//-----------------------------------------------------------------------------
void
glViewer::setStereoMode(bool _b)
{
......@@ -111,7 +90,7 @@ glViewer::setStereoMode(bool _b)
void
glViewer::drawScene_glStereo()
{
double l, r, t, b, w, h, a, radians, wd2, ndfl;
double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth();
h = glHeight();
......@@ -119,23 +98,23 @@ glViewer::drawScene_glStereo()
radians = fovy_ * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians);
ndfl = near_ / focalDist_ * scene_radius_;
zerop = near_ + ((far_ - near_) * OpenFlipper::Options::focalDistance ());
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
l = -a*wd2;
r = a*wd2;
t = wd2;
b = -wd2;
double offset = 0.5 * eyeDist_;
double offset = 0.5 * OpenFlipper::Options::eyeDistance () * xrange;
double offset2 = offset * ndfl;
// left eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, near_, far_);
glTranslatef(-offset, 0.0, 0.0);
glTranslatef(+offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_LEFT);
glstate_->clearBuffers ();
......@@ -147,7 +126,7 @@ glViewer::drawScene_glStereo()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, near_, far_);
glTranslatef(offset, 0.0, 0.0);
glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_RIGHT);
glstate_->clearBuffers ();
......@@ -163,7 +142,7 @@ glViewer::drawScene_glStereo()
void
glViewer::drawScene_anaglyphStereo()
{
double l, r, t, b, w, h, a, radians, wd2, ndfl;
double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth();
h = glHeight();
......@@ -171,21 +150,23 @@ glViewer::drawScene_anaglyphStereo()
radians = fovy_ * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians);
ndfl = near_ / focalDist_ * scene_radius_;
zerop = near_ + ((far_ - near_) * OpenFlipper::Options::focalDistance ());
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
l = -a*wd2;
r = a*wd2;
t = wd2;
b = -wd2;
double offset = 0.5 * eyeDist_;
double offset = 0.5 * OpenFlipper::Options::eyeDistance () * xrange;
double offset2 = offset * ndfl;
// left eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, near_, far_);
glTranslatef(-offset, 0.0, 0.0);
glTranslatef(offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers ();
......@@ -201,7 +182,7 @@ glViewer::drawScene_anaglyphStereo()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, near_, far_);
glTranslatef(offset, 0.0, 0.0);
glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glClear(GL_DEPTH_BUFFER_BIT);
......@@ -292,7 +273,7 @@ glViewer::drawScene_customAnaglyphStereo()
if (!customAnaglyphSupported_)
return;
double l, r, t, b, w, h, a, radians, wd2, ndfl;
double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth();
h = glHeight();
......@@ -300,14 +281,16 @@ glViewer::drawScene_customAnaglyphStereo()
radians = fovy_ * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians);
ndfl = near_ / focalDist_ * scene_radius_;
zerop = near_ + ((far_ - near_) * OpenFlipper::Options::focalDistance ());
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
l = -a*wd2;
r = a*wd2;
t = wd2;
b = -wd2;
double offset = 0.5 * eyeDist_;
double offset = 0.5 * OpenFlipper::Options::eyeDistance () * xrange;
double offset2 = offset * ndfl;
int vp_l, vp_b, vp_w, vp_h;
......@@ -320,7 +303,7 @@ glViewer::drawScene_customAnaglyphStereo()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, near_, far_);
glTranslatef(-offset, 0.0, 0.0);
glTranslatef(offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT);
......@@ -334,7 +317,7 @@ glViewer::drawScene_customAnaglyphStereo()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, near_, far_);
glTranslatef(offset, 0.0, 0.0);
glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT);
......
......@@ -157,6 +157,9 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
stereoAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphRedCyan);
stereoCustomAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphCustom);
eyeDistance->setValue (OpenFlipper::Options::eyeDistance());
focalDistance->setValue (OpenFlipper::Options::focalDistance() * 1000);
std::vector<float> mat = OpenFlipper::Options::anaglyphLeftEyeColorMatrix ();
lcm0->setValue (mat[0]);
lcm1->setValue (mat[1]);
......@@ -417,6 +420,9 @@ void OptionsWidget::slotApply() {
else
OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);
OpenFlipper::Options::eyeDistance(eyeDistance->value ());
OpenFlipper::Options::focalDistance((float)focalDistance->value () / 1000);
std::vector<float> mat (9, 0);
mat[0] = lcm0->value ();
mat[1] = lcm1->value ();
......
......@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>541</width>
<height>779</height>
<width>549</width>
<height>819</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -391,7 +391,7 @@ You can select multiple modes at the same time.</string>
<attribute name="title" >
<string>Stereo</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_18" >
<layout class="QVBoxLayout" name="verticalLayout_19" >
<item>
<widget class="QGroupBox" name="groupBox_5" >
<property name="title" >
......@@ -422,6 +422,116 @@ You can select multiple modes at the same time.</string>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7" >
<property name="title" >
<string>View properties</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_15" >
<item>
<layout class="QVBoxLayout" name="verticalLayout_18" >
<item>
<widget class="QLabel" name="label_11" >
<property name="text" >
<string>Eye distance:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12" >
<property name="text" >
<string>Focal distance:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_20" >
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14" >
<item>
<widget class="QDoubleSpinBox" name="eyeDistance" >
<property name="decimals" >
<number>4</number>
</property>
<property name="maximum" >
<double>1.000000000000000</double>
</property>
<property name="singleStep" >
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16" >
<item>
<widget class="QLabel" name="label_13" >
<property name="font" >
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text" >
<string>Near</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="focalDistance" >
<property name="maximum" >
<number>1000</number>
</property>
<property name="singleStep" >
<number>10</number>
</property>
<property name="pageStep" >
<number>100</number>
</property>
<property name="value" >
<number>50</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_14" >
<property name="font" >
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text" >
<string>Far</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6" >
<property name="title" >
......
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