Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix light source move in Viewer3D #1262

Merged
merged 3 commits into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
for instance to add callbacks to key or mouse events, or to modify
what is drawn on the window.
(Jacques-Olivier Lachaud, [#1259](https://github.com/DGtal-team/DGtal/pull/1259))

## Changes

- *IO*
- TableReader can now read all elements contained in each line of a file
with the new method getLinesElementsFromFile().
(Bertrand Kerautret, [#1260](https://github.com/DGtal-team/DGtal/pull/1260))


## Bug Fixes

- *Configuration/General*
Expand All @@ -31,7 +31,10 @@
handle 32/16 bits images. Also includes a new testITKReader and ITK tests in
GenericReader.
(Bertrand Kerautret, [#1255](https://github.com/DGtal-team/DGtal/pull/1255))

- Viewer3D: fix bad light source move according X/Y mouse move and new Key_Z to
move away/closer the light source.
(Bertrand Kerautret, [#1262](https://github.com/DGtal-team/DGtal/pull/1262))

- *Kernel Package*
- Fix testBasicPointFunctor. (Bertrand Kerautret
[#1245](https://github.com/DGtal-team/DGtal/pull/1245))
Expand Down
43 changes: 41 additions & 2 deletions src/DGtal/io/viewers/Viewer3D.ih
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ DGtal::Viewer3D<TSpace, TKSpace>::init()
setKeyDescription ( Qt::Key_O, "Switch the ball display mode (quad ball display (default) or OpenGL point)." );
setKeyDescription ( Qt::Key_M, "Switch the rendering mode bewteen Default, Metallic and Plastic mode." );
setKeyDescription ( Qt::Key_P, "Switch the light source position mode between the camera mode (default: the light source position is fixed according to the camera position) and scene mode (the light source position is fixed according the scene coordinate system)." );
setKeyDescription ( Qt::Key_Z, "Move away the light source according to the scence center (move closer with SHIFT+Z)");
setKeyDescription ( Qt::ShiftModifier+Qt::Key_Z, "Move closer the light source according to the scence center (move awya with key Z)" );

#if !defined (QGLVIEWER_VERSION) || QGLVIEWER_VERSION < 0x020500
setMouseBindingDescription((Qt::ControlModifier|Qt::ShiftModifier) + Qt::LeftButton, "move light source position defined in the main coordinate system (an x-axis (resp. y-axis) mouse move changes the azimuth (resp. inclination) angle of the light source). Note that light source is always looking at the center point (0,0,0).");
#else
Expand Down Expand Up @@ -1215,8 +1218,8 @@ DGtal::Viewer3D<TSpace, TKSpace>::mouseMoveEvent ( QMouseEvent *e )
if(e->modifiers() == (Qt::ControlModifier|Qt::ShiftModifier)){
int varX = e->x() - myRefMouseXPos;
int varY = e->y() - myRefMouseYPos;
myLightPhi += varX*myLigthRotationStep;
myLightTheta += varY*myLigthRotationStep/2.0;
myLightPhi -= varY*myLigthRotationStep;
myLightTheta -= varX*myLigthRotationStep/2.0;
myLightPosition[0] = myLightR*cos(myLightTheta)*cos(myLightPhi);
myLightPosition[1] = myLightR*cos(myLightTheta)*sin(myLightPhi);
myLightPosition[2] = myLightR*sin(myLightTheta);
Expand Down Expand Up @@ -1288,7 +1291,43 @@ DGtal::Viewer3D<TSpace, TKSpace>::keyPressEvent ( QKeyEvent *e )
updateList(false);
updateGL();
}
if( e->key() == Qt::Key_Z)
{
if( myLightPositionFixToCamera )
{
updateLightCoordsFromCamera();
}
myLightR = sqrt( myLightPosition[0]* myLightPosition[0]+
myLightPosition[1]* myLightPosition[1]+
myLightPosition[2]* myLightPosition[2]);
myLightTheta = asin( myLightPosition[2]/myLightR);
myLightPhi = atan2( myLightPosition[1], myLightPosition[0]);

stringstream ss;
if(e->modifiers()==Qt::ShiftModifier)
{
myLightR += 5.0;
ss << "Move away light source at distance: " << myLightR;
}
else
{
myLightR -= 5.0;
ss << "Move closer light source at distance: " << myLightR;
}
displayMessage(QString(ss.str().c_str()), 3000);
myLightPosition[0] = myLightR*cos(myLightTheta)*cos(myLightPhi);
myLightPosition[1] = myLightR*cos(myLightTheta)*sin(myLightPhi);
myLightPosition[2] = myLightR*sin(myLightTheta);
if(myLightPositionFixToCamera)
{
updateRelativeCameraFromLightPosition();
}
myIsMovingLight=true;
glLightfv(GL_LIGHT0, GL_POSITION, myLightPosition);
updateGL();
}


if ( ( e->key() ==Qt::Key_P ) )
{
myLightPositionFixToCamera =! myLightPositionFixToCamera;
Expand Down