Skip to content

Commit a1721e4

Browse files
authored
Merge branch 'master' into modules
2 parents dfa8b01 + bbdab7c commit a1721e4

File tree

8 files changed

+211
-55
lines changed

8 files changed

+211
-55
lines changed

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,37 @@ namespace SCIRun {
8080
{
8181
glm::vec2 screenSpace = calculateScreenSpaceCoords(pos);
8282
mArcLookAt->doReferenceDown(screenSpace);
83+
lastPos = screenSpace;
84+
movementVec = glm::vec2(0.0, 0.0);
8385
}
8486

8587
//----------------------------------------------------------------------------------------------
8688
void SRCamera::mouseMoveEvent(const glm::ivec2& pos, SRInterface::MouseButton btn)
8789
{
90+
static const float spinThreashold = 0.01f;
8891
glm::vec2 screenSpace = calculateScreenSpaceCoords(pos);
8992
switch (mInterface.getMouseMode())
9093
{
9194
case SRInterface::MOUSE_OLDSCIRUN:
9295
if (btn == SRInterface::MOUSE_LEFT && !lockPanning_) mArcLookAt->doPan(screenSpace);
9396
if (btn == SRInterface::MOUSE_RIGHT && !lockZoom_) mArcLookAt->doZoom(screenSpace);
94-
if (btn == SRInterface::MOUSE_MIDDLE && !lockRotation_) mArcLookAt->doRotation(screenSpace);
97+
if (btn == SRInterface::MOUSE_MIDDLE && !lockRotation_)
98+
{
99+
mArcLookAt->doRotation(screenSpace);
100+
movementVec = screenSpace - lastPos;
101+
if(glm::length(movementVec) < spinThreashold) movementVec = glm::vec2(0.0, 0.0);
102+
lastPos = screenSpace;
103+
}
95104
break;
96105

97106
case SRInterface::MOUSE_NEWSCIRUN:
98-
if (btn == SRInterface::MOUSE_LEFT && !lockRotation_) mArcLookAt->doRotation(screenSpace);
107+
if (btn == SRInterface::MOUSE_LEFT && !lockRotation_)
108+
{
109+
mArcLookAt->doRotation(screenSpace);
110+
movementVec = screenSpace - lastPos;
111+
if(glm::length(movementVec) < spinThreashold) movementVec = glm::vec2(0.0, 0.0);
112+
lastPos = screenSpace;
113+
}
99114
if (btn == SRInterface::MOUSE_RIGHT && !lockPanning_) mArcLookAt->doPan(screenSpace);
100115
break;
101116
}
@@ -173,6 +188,22 @@ namespace SCIRun {
173188
mInvertVal = -1;
174189
}
175190

191+
//----------------------------------------------------------------------------------------------
192+
void SRCamera::tryAutoRotate()
193+
{
194+
mArcLookAt->doReferenceDown(lastPos);
195+
mArcLookAt->doRotation(lastPos + movementVec);
196+
setClippingPlanes();
197+
}
198+
199+
//----------------------------------------------------------------------------------------------
200+
void SRCamera::rotate(glm::vec2 vector)
201+
{
202+
mArcLookAt->doReferenceDown(glm::vec2(0.0, 0.0));
203+
mArcLookAt->doRotation(vector);
204+
setClippingPlanes();
205+
}
206+
176207
//----------------------------------------------------------------------------------------------
177208
glm::vec2 SRCamera::calculateScreenSpaceCoords(const glm::ivec2& mousePos)
178209
{

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ namespace SCIRun{
7575
/// Toggles the zoom controls on New Mouse Controls Inverted/Not Inverted
7676
void setZoomInverted(bool value);
7777

78+
void tryAutoRotate();
79+
80+
void rotate(glm::vec2);
81+
7882
// P = Projection matrix | IV = Inverse view matrix | V = View matrix
7983
const glm::mat4& getWorldToProjection() const {return mVP;}
8084
const glm::mat4& getWorldToView() const {return mV;}
@@ -111,6 +115,9 @@ namespace SCIRun{
111115
float mZFar {getDefaultZFar()}; ///< Position of far plane along view vec.
112116
float mRadius {-1.0};
113117

118+
glm::vec2 lastPos {0.0, 0.0};
119+
glm::vec2 movementVec {0.0, 0.0};
120+
114121
glm::mat4 mVP {}; ///< Projection * View transformation.
115122
glm::mat4 mV {}; ///< View transformation.
116123
glm::mat4 mIV {}; ///< Inverse View transformation.

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,16 @@ namespace SCIRun {
182182
//todo make this select widget
183183
}
184184
}
185+
autoRotateVector = glm::vec2(0.0, 0.0);
186+
tryAutoRotate = false;
185187
mCamera->mouseDownEvent(pos, btn);
186188
}
187189

188190
//----------------------------------------------------------------------------------------------
189191
void SRInterface::inputMouseUp(const glm::ivec2& /*pos*/, MouseButton /*btn*/)
190192
{
191193
widgetSelected_ = false;
194+
tryAutoRotate = doAutoRotateOnDrag;
192195
}
193196

194197
//----------------------------------------------------------------------------------------------
@@ -297,7 +300,30 @@ namespace SCIRun {
297300
}
298301
}
299302

303+
//----------------------------------------------------------------------------------------------
304+
void SRInterface::applyAutoRotation()
305+
{
306+
if(glm::length(autoRotateVector) > 0.1) mCamera->rotate(autoRotateVector * autoRotateSpeed);
307+
if(tryAutoRotate) mCamera->tryAutoRotate();
308+
}
309+
310+
//----------------------------------------------------------------------------------------------
311+
void SRInterface::setAutoRotateVector(glm::vec2 axis)
312+
{
313+
tryAutoRotate = false;
314+
if(autoRotateVector.x == axis.x && autoRotateVector.y == axis.y)
315+
{
316+
autoRotateVector = glm::vec2(0.0, 0.0);
317+
}
318+
else
319+
{
320+
autoRotateVector = axis;
321+
}
322+
}
323+
300324
//Getters/Setters-------------------------------------------------------------------------------
325+
void SRInterface::setAutoRotateSpeed(double speed) { autoRotateSpeed = speed; }
326+
void SRInterface::setAutoRotateOnDrag(bool value) { doAutoRotateOnDrag = value; }
301327
void SRInterface::setZoomInverted(bool value) {mCamera->setZoomInverted(value);}
302328
void SRInterface::setLockZoom(bool lock) {mCamera->setLockZoom(lock);}
303329
void SRInterface::setLockPanning(bool lock) {mCamera->setLockPanning(lock);}
@@ -1378,6 +1404,7 @@ namespace SCIRun {
13781404
/// objects, or the view point has changed).
13791405
mContext->makeCurrent();
13801406

1407+
applyAutoRotation();
13811408
updateCamera();
13821409
updateWorldLight();
13831410

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ namespace SCIRun {
130130
void setLockZoom(bool lock);
131131
void setLockPanning(bool lock);
132132
void setLockRotation(bool lock);
133+
void setAutoRotateVector(glm::vec2 axis);
134+
void setAutoRotateSpeed(double speed);
135+
void setAutoRotateOnDrag(bool value);
133136
const glm::mat4& getWorldToProjection() const;
134137
const glm::mat4& getWorldToView() const;
135138
const glm::mat4& getViewToWorld() const;
@@ -193,6 +196,7 @@ namespace SCIRun {
193196

194197
//---------------- Camera ----------------------------------------------------------------------
195198
void updateCamera(); // Places mCamera's transform into our static camera component.
199+
void applyAutoRotation();
196200

197201
//---------------- Widgets -------------------------------------------------------------------
198202
bool foundWidget(const glm::ivec2& pos); // search for a widget at mouse position
@@ -299,6 +303,8 @@ namespace SCIRun {
299303
bool selectWidget_ {false}; // Whether mouse click will select a widget.
300304
bool widgetSelected_ {false}; // Whether or not a widget is currently selected.
301305
bool widgetExists_ {false}; // Geometry contains a widget to find.
306+
bool tryAutoRotate {false};
307+
bool doAutoRotateOnDrag {false};
302308

303309
float orientSize {1.0}; // Size of coordinate axes
304310
float orientPosX {0.5}; // X Position of coordinate axes
@@ -346,9 +352,12 @@ namespace SCIRun {
346352

347353
//light settings
348354
std::vector<glm::vec2> mLightDirectionPolar{};
349-
std::vector<glm::vec3> mLightDirectionView{};
355+
std::vector<glm::vec3> mLightDirectionView {};
350356
std::vector<bool> mLightsOn {};
351357

358+
glm::vec2 autoRotateVector {0.0, 0.0};
359+
float autoRotateSpeed {0.01};
360+
352361
const int frameInitLimit_ {};
353362
std::unique_ptr<SRCamera> mCamera; // Primary camera.
354363
};

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,48 @@ void ViewSceneDialog::setTextOffset(int value)
10141014
state_->setValue(Modules::Render::ViewScene::TextOffset, offset);
10151015
}
10161016

1017+
//--------------------------------------------------------------------------------------------------
1018+
void ViewSceneDialog::setAutoRotateSpeed(double speed)
1019+
{
1020+
auto spire = mSpire.lock();
1021+
spire->setAutoRotateSpeed(speed);
1022+
}
1023+
1024+
//--------------------------------------------------------------------------------------------------
1025+
void ViewSceneDialog::setAutoRotateOnDrag(bool value)
1026+
{
1027+
auto spire = mSpire.lock();
1028+
spire->setAutoRotateOnDrag(value);
1029+
}
1030+
1031+
//--------------------------------------------------------------------------------------------------
1032+
void ViewSceneDialog::autoRotateRight()
1033+
{
1034+
auto spire = mSpire.lock();
1035+
spire->setAutoRotateVector(glm::vec2(1.0, 0.0));
1036+
}
1037+
1038+
//--------------------------------------------------------------------------------------------------
1039+
void ViewSceneDialog::autoRotateLeft()
1040+
{
1041+
auto spire = mSpire.lock();
1042+
spire->setAutoRotateVector(glm::vec2(-1.0, 0.0));
1043+
}
1044+
1045+
//--------------------------------------------------------------------------------------------------
1046+
void ViewSceneDialog::autoRotateUp()
1047+
{
1048+
auto spire = mSpire.lock();
1049+
spire->setAutoRotateVector(glm::vec2(0.0, 1.0));
1050+
}
1051+
1052+
//--------------------------------------------------------------------------------------------------
1053+
void ViewSceneDialog::autoRotateDown()
1054+
{
1055+
auto spire = mSpire.lock();
1056+
spire->setAutoRotateVector(glm::vec2(0.0, -1.0));
1057+
}
1058+
10171059

10181060

10191061
//--------------------------------------------------------------------------------------------------

src/Interface/Modules/Render/ViewScene.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ namespace SCIRun {
104104
void setStereoFusion(int value);
105105
void setPolygonOffset(int value);
106106
void setTextOffset(int value);
107+
void setAutoRotateSpeed(double speed);
108+
void setAutoRotateOnDrag(bool value);
109+
void autoRotateRight();
110+
void autoRotateLeft();
111+
void autoRotateUp();
112+
void autoRotateDown();
113+
107114

108115
//---------------- Widgets -------------------------------------------------------------------
109116
void updateMeshComponentSelection(const QString& moduleId, const QString& component, bool selected);

0 commit comments

Comments
 (0)