Skip to content

Commit a56bab4

Browse files
committed
Closes #1647
1 parent 1584fca commit a56bab4

File tree

8 files changed

+113
-48
lines changed

8 files changed

+113
-48
lines changed

src/Interface/Modules/Render/ES/SRCamera.cc

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ namespace Render {
4040
//------------------------------------------------------------------------------
4141
SRCamera::SRCamera(SRInterface& iface) :
4242
mTrafoSeq(0),
43-
mInvertVal(-1),
4443
mPerspective(true),
44+
mInvertVal(-1),
4545
mFOV(getDefaultFOVY()),
4646
mZNear(getDefaultZNear()),
4747
mZFar(getDefaultZFar()),
@@ -54,17 +54,12 @@ SRCamera::SRCamera(SRInterface& iface) :
5454
cam[3] = (glm::vec4(0.0f, 0.0f, 7.0f, 1.0f));
5555
}
5656

57-
//------------------------------------------------------------------------------
58-
SRCamera::~SRCamera()
59-
{
60-
}
61-
6257
//------------------------------------------------------------------------------
6358
void SRCamera::setAsPerspective()
6459
{
6560
mPerspective = true;
6661

67-
float aspect = static_cast<float>(mInterface.getScreenWidthPixels()) /
62+
float aspect = static_cast<float>(mInterface.getScreenWidthPixels()) /
6863
static_cast<float>(mInterface.getScreenHeightPixels());
6964
mP = glm::perspective(mFOV, aspect, mZNear, mZFar);
7065
}
@@ -74,8 +69,8 @@ void SRCamera::setAsOrthographic(float halfWidth, float halfHeight)
7469
{
7570
mPerspective = false;
7671

77-
mP = glm::ortho(-halfWidth, halfWidth,
78-
-halfHeight, halfHeight,
72+
mP = glm::ortho(-halfWidth, halfWidth,
73+
-halfHeight, halfHeight,
7974
mZNear, mZFar);
8075
}
8176

@@ -109,22 +104,22 @@ void SRCamera::mouseMoveEvent(const glm::ivec2& pos, SRInterface::MouseButton bt
109104
switch (mInterface.getMouseMode())
110105
{
111106
case SRInterface::MOUSE_OLDSCIRUN:
112-
if (btn == SRInterface::MOUSE_LEFT) mArcLookAt->doPan(screenSpace);
113-
if (btn == SRInterface::MOUSE_RIGHT) mArcLookAt->doZoom(screenSpace);
114-
if (btn == SRInterface::MOUSE_MIDDLE) mArcLookAt->doRotation(screenSpace);
107+
if (btn == SRInterface::MOUSE_LEFT && !lockPanning_) mArcLookAt->doPan(screenSpace);
108+
if (btn == SRInterface::MOUSE_RIGHT && !lockZoom_) mArcLookAt->doZoom(screenSpace);
109+
if (btn == SRInterface::MOUSE_MIDDLE && !lockRotation_) mArcLookAt->doRotation(screenSpace);
115110
break;
116111

117112
case SRInterface::MOUSE_NEWSCIRUN:
118-
if (btn == SRInterface::MOUSE_LEFT) mArcLookAt->doRotation(screenSpace);
119-
if (btn == SRInterface::MOUSE_RIGHT) mArcLookAt->doPan(screenSpace);
113+
if (btn == SRInterface::MOUSE_LEFT && !lockRotation_) mArcLookAt->doRotation(screenSpace);
114+
if (btn == SRInterface::MOUSE_RIGHT && !lockPanning_) mArcLookAt->doPan(screenSpace);
120115
break;
121116
}
122117
}
123118

124119
//------------------------------------------------------------------------------
125120
void SRCamera::mouseWheelEvent(int32_t delta, int zoomSpeed)
126121
{
127-
if (mInterface.getMouseMode() != SRInterface::MOUSE_OLDSCIRUN)
122+
if (mInterface.getMouseMode() != SRInterface::MOUSE_OLDSCIRUN && !lockZoom_)
128123
{
129124
//mArcLookAt->doZoom(-static_cast<float>(delta) / 100.0f, zoomSpeed);
130125
mArcLookAt->doZoom(mInvertVal*static_cast<float>(delta) / 100.0f, zoomSpeed);
@@ -169,7 +164,7 @@ glm::vec2 SRCamera::calculateScreenSpaceCoords(const glm::ivec2& mousePos)
169164

170165
// Transform incoming mouse coordinates into screen space.
171166
glm::vec2 mouseScreenSpace;
172-
mouseScreenSpace.x = 2.0f * (static_cast<float>(mousePos.x) - windowOriginX)
167+
mouseScreenSpace.x = 2.0f * (static_cast<float>(mousePos.x) - windowOriginX)
173168
/ static_cast<float>(mInterface.getScreenWidthPixels()) - 1.0f;
174169
mouseScreenSpace.y = 2.0f * (static_cast<float>(mousePos.y) - windowOriginY)
175170
/ static_cast<float>(mInterface.getScreenHeightPixels()) - 1.0f;
@@ -183,5 +178,4 @@ glm::vec2 SRCamera::calculateScreenSpaceCoords(const glm::ivec2& mousePos)
183178
}
184179

185180
} // namespace Render
186-
} // namespace SCIRun
187-
181+
} // namespace SCIRun

src/Interface/Modules/Render/ES/SRCamera.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ namespace Render {
4343
class SRCamera
4444
{
4545
public:
46-
SRCamera(SRInterface& iface);
47-
virtual ~SRCamera();
46+
explicit SRCamera(SRInterface& iface);
4847

4948
// V = View matrix
5049
// IV = Inverse view matrix
@@ -90,6 +89,10 @@ class SRCamera
9089
static float getDefaultZFar() {return 100000.0f;}
9190
/// @}
9291

92+
void setLockZoom(bool lock) { lockZoom_ = lock; }
93+
void setLockPanning(bool lock) { lockPanning_ = lock; }
94+
void setLockRotation(bool lock) { lockRotation_ = lock; }
95+
9396
private:
9497

9598
void buildTransform();
@@ -102,20 +105,23 @@ class SRCamera
102105
size_t mTrafoSeq; ///< Current sequence of the view transform.
103106
///< Helps us determine when a camera is 'dirty'.
104107

105-
bool mPerspective; ///< True if we are using a perspective
106-
///< transformation.
108+
bool mPerspective; ///< True if we are using a perspective
109+
///< transformation.
107110
int mInvertVal; ///< Invert multiplier
108111
float mFOV; ///< Field of view.
109112
float mZNear; ///< Position of near plane along view vec.
110113
float mZFar; ///< Position of far plane along view vec.
111114

112115
SRInterface& mInterface; ///< SRInterface.
113-
116+
114117
std::shared_ptr<CPM_LOOK_AT_NS::ArcLookAt> mArcLookAt;
115118

119+
bool lockRotation_{false};
120+
bool lockZoom_{false};
121+
bool lockPanning_{false};
116122
};
117123

118124
} // namespace Render
119-
} // namespace SCIRun
125+
} // namespace SCIRun
120126

121-
#endif
127+
#endif

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ namespace SCIRun {
8484
mScreenHeight(480),
8585
axesFailCount_(0),
8686
mContext(context),
87-
frameInitLimit_(frameInitLimit),
88-
mCamera(new SRCamera(*this)), // Should come after all vars have been initialized.
8987
clippingPlaneIndex_(0),
9088
mMatAmbient(0.2),
9189
mMatDiffuse(1.0),
@@ -94,11 +92,10 @@ namespace SCIRun {
9492
mFogIntensity(0.0),
9593
mFogStart(0.0),
9694
mFogEnd(1.0),
97-
mFogColor(glm::vec4(0.0))
95+
mFogColor(glm::vec4(0.0)),
96+
frameInitLimit_(frameInitLimit),
97+
mCamera(new SRCamera(*this)) // Should come after all vars have been initialized.
9898
{
99-
// Create default colormaps.
100-
//generateTextures();
101-
10299
showOrientation_ = true;
103100
autoRotate_ = false;
104101
selectWidget_ = false;
@@ -238,13 +235,28 @@ namespace SCIRun {
238235
{
239236
if (btn == MouseButton::MOUSE_LEFT)
240237
{
241-
//widgetSelected_ = foundWidget(pos);
242-
std::cout << "widget exists" << std::endl;
238+
// //widgetSelected_ = foundWidget(pos);
239+
// std::cout << "widget exists" << std::endl;
243240
}
244241
}
245242
mCamera->mouseDownEvent(pos, btn);
246243
}
247244

245+
void SRInterface::setLockZoom(bool lock)
246+
{
247+
mCamera->setLockZoom(lock);
248+
}
249+
250+
void SRInterface::setLockPanning(bool lock)
251+
{
252+
mCamera->setLockPanning(lock);
253+
}
254+
255+
void SRInterface::setLockRotation(bool lock)
256+
{
257+
mCamera->setLockRotation(lock);
258+
}
259+
248260
//------------------------------------------------------------------------------
249261
void SRInterface::inputMouseMove(const glm::ivec2& pos, MouseButton btn)
250262
{
@@ -573,7 +585,7 @@ namespace SCIRun {
573585
{
574586
return mWidgetTransform;
575587
}
576-
588+
577589
//------------------------------------------------------------------------------
578590
//--------------Clipping Plane Tools--------------------------------------------
579591
void SRInterface::checkClippingPlanes(int n)
@@ -1426,7 +1438,6 @@ namespace SCIRun {
14261438
return;
14271439

14281440
glm::mat4 viewToWorld = mCamera->getViewToWorld();
1429-
glm::vec3 position = glm::vec3(x, y, 0);
14301441
if (mLightPosition.size() > 0)
14311442
{
14321443
mLightPosition[index] = glm::vec3(x, y, 0.0);
@@ -1437,7 +1448,7 @@ namespace SCIRun {
14371448
if (light)
14381449
{
14391450
glm::vec3 viewDir = viewToWorld[2].xyz();
1440-
viewDir = -viewDir; // Cameras look down -Z.
1451+
viewDir = -viewDir; // Cameras look down -Z.
14411452
light->lightDir[index] = mLightsOn[index] ? viewDir-position : glm::vec3(0.0, 0.0, 0.0);
14421453
14431454
glm::vec3 view1 = viewToWorld[0].xyz();

src/Interface/Modules/Render/ES/SRInterface.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ namespace SCIRun {
176176
static std::string& getFSRoot();
177177
static std::string& getFSSeparator();
178178

179-
//Clipping Plane
179+
//Clipping Plane
180180
void setClippingPlaneIndex(int index);
181181
void setClippingPlaneVisible(bool value);
182182
void setClippingPlaneFrameOn(bool value);
@@ -199,6 +199,10 @@ namespace SCIRun {
199199
const glm::mat4& getViewToWorld() const;
200200
const glm::mat4& getViewToProjection() const;
201201

202+
void setLockZoom(bool lock);
203+
void setLockPanning(bool lock);
204+
void setLockRotation(bool lock);
205+
202206
//clipping planes
203207
StaticClippingPlanes* getClippingPlanes();
204208

@@ -337,7 +341,7 @@ namespace SCIRun {
337341

338342
// make sure clipping plane number matches
339343
void checkClippingPlanes(int n);
340-
344+
341345
bool showOrientation_; ///< Whether the coordinate axes will render or not.
342346
bool autoRotate_; ///< Whether the scene will continue to rotate.
343347
bool selectWidget_; ///< Whether mouse click will select a widget.
@@ -376,8 +380,6 @@ namespace SCIRun {
376380
ren::ShaderVBOAttribs<5> mArrowAttribs; ///< Pre-applied shader / VBO attributes.
377381
ren::CommonUniforms mArrowUniforms; ///< Common uniforms used in the arrow shader.
378382
RenderState::TransparencySortType mRenderSortType; ///< Which strategy will be used to render transparency
379-
const int frameInitLimit_;
380-
std::unique_ptr<SRCamera> mCamera; ///< Primary camera.
381383

382384
//material settings
383385
double mMatAmbient;
@@ -394,9 +396,12 @@ namespace SCIRun {
394396
//light settings
395397
std::vector<glm::vec3> mLightPosition;
396398
std::vector<bool> mLightsOn;
399+
400+
const int frameInitLimit_;
401+
std::unique_ptr<SRCamera> mCamera; ///< Primary camera.
397402
};
398403

399404
} // namespace Render
400-
} // namespace SCIRun
405+
} // namespace SCIRun
401406

402-
#endif
407+
#endif

src/Interface/Modules/Render/GLWidget.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void GLWidget::initializeGL()
9696
//------------------------------------------------------------------------------
9797
SCIRun::Render::SRInterface::MouseButton GLWidget::getSpireButton(QMouseEvent* event)
9898
{
99-
SCIRun::Render::SRInterface::MouseButton btn = SCIRun::Render::SRInterface::MOUSE_NONE;
99+
auto btn = SCIRun::Render::SRInterface::MOUSE_NONE;
100100
if (event->buttons() & Qt::LeftButton)
101101
btn = Render::SRInterface::MOUSE_LEFT;
102102
else if (event->buttons() & Qt::RightButton)
@@ -111,24 +111,23 @@ SCIRun::Render::SRInterface::MouseButton GLWidget::getSpireButton(QMouseEvent* e
111111
void GLWidget::mouseMoveEvent(QMouseEvent* event)
112112
{
113113
// Extract appropriate key.
114-
SCIRun::Render::SRInterface::MouseButton btn = getSpireButton(event);
114+
auto btn = getSpireButton(event);
115115
mGraphics->inputMouseMove(glm::ivec2(event->x(), event->y()), btn);
116116
event->ignore();
117117
}
118118

119119
//------------------------------------------------------------------------------
120120
void GLWidget::mousePressEvent(QMouseEvent* event)
121121
{
122-
123-
SCIRun::Render::SRInterface::MouseButton btn = getSpireButton(event);
122+
auto btn = getSpireButton(event);
124123
mGraphics->inputMouseDown(glm::ivec2(event->x(), event->y()), btn);
125124
event->ignore();
126125
}
127126

128127
//------------------------------------------------------------------------------
129128
void GLWidget::mouseReleaseEvent(QMouseEvent* event)
130129
{
131-
SCIRun::Render::SRInterface::MouseButton btn = getSpireButton(event);
130+
auto btn = getSpireButton(event);
132131
mGraphics->inputMouseUp(glm::ivec2(event->x(), event->y()), btn);
133132
event->ignore();
134133
}
@@ -143,7 +142,6 @@ void GLWidget::wheelEvent(QWheelEvent * event)
143142
//------------------------------------------------------------------------------
144143
void GLWidget::keyPressEvent(QKeyEvent* event)
145144
{
146-
std::cout << "key down" << std::endl;
147145
mGraphics->inputShiftKeyDown(event->key() == Qt::Key_Shift);
148146
event->ignore();
149147
}

src/Interface/Modules/Render/GLWidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class GLWidget : public QGLWidget
6868
/// contexts running on the same thread.
6969
void makeCurrent();
7070

71+
void setLockZoom(bool lock) { mGraphics->setLockZoom(lock); }
72+
void setLockPanning(bool lock) { mGraphics->setLockPanning(lock); }
73+
void setLockRotation(bool lock) { mGraphics->setLockRotation(lock); }
74+
7175
Q_SIGNALS:
7276
void fatalError(const QString& message);
7377
protected:

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,47 @@ void ViewSceneDialog::addViewBarButton()
14701470
mToolBar->addSeparator();
14711471
}
14721472

1473+
void ViewSceneDialog::addControlLockButton()
1474+
{
1475+
auto controlLock = new QPushButton();
1476+
controlLock->setToolTip("Lock specific view controls");
1477+
controlLock->setText("Lock View");
1478+
auto menu = new QMenu;
1479+
1480+
auto lockRot = menu->addAction("Lock Rotation");
1481+
lockRot->setCheckable(true);
1482+
connect(lockRot, SIGNAL(triggered()), this, SLOT(lockRotationToggled()));
1483+
1484+
auto lockPan = menu->addAction("Lock Panning");
1485+
lockPan->setCheckable(true);
1486+
connect(lockPan, SIGNAL(triggered()), this, SLOT(lockPanningToggled()));
1487+
1488+
auto lockZoom = menu->addAction("Lock Zoom");
1489+
lockZoom->setCheckable(true);
1490+
connect(lockZoom, SIGNAL(triggered()), this, SLOT(lockZoomToggled()));
1491+
1492+
controlLock->setMenu(menu);
1493+
mToolBar->addWidget(controlLock);
1494+
}
1495+
1496+
void ViewSceneDialog::lockRotationToggled()
1497+
{
1498+
auto action = qobject_cast<QAction*>(sender());
1499+
mGLWidget->setLockRotation(action->isChecked());
1500+
}
1501+
1502+
void ViewSceneDialog::lockPanningToggled()
1503+
{
1504+
auto action = qobject_cast<QAction*>(sender());
1505+
mGLWidget->setLockPanning(action->isChecked());
1506+
}
1507+
1508+
void ViewSceneDialog::lockZoomToggled()
1509+
{
1510+
auto action = qobject_cast<QAction*>(sender());
1511+
mGLWidget->setLockZoom(action->isChecked());
1512+
}
1513+
14731514
void ViewSceneDialog::addViewBar()
14741515
{
14751516
mViewBar = new QToolBar(this);
@@ -1482,6 +1523,7 @@ void ViewSceneDialog::addViewBar()
14821523
glLayout->addWidget(mViewBar);
14831524

14841525
addViewBarButton();
1526+
addControlLockButton();
14851527
}
14861528

14871529
void ViewSceneDialog::addViewOptions()

src/Interface/Modules/Render/ViewScene.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ namespace SCIRun {
141141
void toggleLight3(bool value);
142142
void resizingDone();
143143

144+
void lockRotationToggled();
145+
void lockPanningToggled();
146+
void lockZoomToggled();
147+
144148
protected:
145149
void mousePressEvent(QMouseEvent* event) override;
146150
void mouseReleaseEvent(QMouseEvent* event) override;
@@ -179,6 +183,7 @@ namespace SCIRun {
179183
void addAutoViewButton();
180184
void addScreenshotButton();
181185
void addViewBarButton();
186+
void addControlLockButton();
182187
void addViewBar();
183188
void addViewOptions();
184189
void addConfigurationButton();

0 commit comments

Comments
 (0)