Skip to content

Commit e315a4a

Browse files
author
Haydelj
committed
added state change signaling for the camera state
1 parent c1faebb commit e315a4a

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ namespace SCIRun{
9696
static_cast<float>(mInterface.getScreenHeightPixels());}
9797

9898
float getDistance() const {return mArcLookAt->getDistance();}
99-
void setDistance(const float f) {mArcLookAt->setDistance(f);}
99+
void setDistance(const float f) {mArcLookAt->setDistance(f); setClippingPlanes();}
100100

101101
glm::vec3 getLookAt() const {return mArcLookAt->getLookAt();}
102-
void setLookAt(const glm::vec3 v) {mArcLookAt->setLookAt(v);}
102+
void setLookAt(const glm::vec3 v) {mArcLookAt->setLookAt(v); setClippingPlanes();}
103103

104104
glm::quat getRotation() const {return mArcLookAt->getRotation();}
105-
void setRotation(const glm::quat q) {mArcLookAt->setRotation(q);}
105+
void setRotation(const glm::quat q) {mArcLookAt->setRotation(q); setClippingPlanes();}
106106

107107
void setLockZoom(bool lock) {lockZoom_ = lock;}
108108
void setLockPanning(bool lock) {lockPanning_ = lock;}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,8 @@ namespace SCIRun {
14081408
//----------------------------------------------------------------------------------------------
14091409
void SRInterface::doFrame(double currentTime, double constantDeltaTime)
14101410
{
1411-
/// \todo Only render a frame if something has changed (new or deleted
1412-
/// objects, or the view point has changed).
1411+
// todo Only render a frame if something has changed (new or deleted
1412+
// objects, or the view point has changed).
14131413
mContext->makeCurrent();
14141414

14151415
applyAutoRotation();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ namespace SCIRun {
202202
void setupLights();
203203

204204
//---------------- Camera ----------------------------------------------------------------------
205-
void updateCamera(); // Places mCamera's transform into our static camera component.
206205
void applyAutoRotation();
206+
void updateCamera(); // Places mCamera's transform into our static camera component.
207207

208208
//---------------- Widgets -------------------------------------------------------------------
209209
bool foundWidget(const glm::ivec2& pos); // search for a widget at mouse position

src/Interface/Modules/Render/ViewScene.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ ViewSceneDialog::ViewSceneDialog(const std::string& name, ModuleStateHandle stat
140140
state->connectSpecificStateChanged(Parameters::GeomData,[this](){Q_EMIT newGeometryValueForwarder();});
141141
connect(this, SIGNAL(newGeometryValueForwarder()), this, SLOT(updateAllGeometries()));
142142

143+
state->connectSpecificStateChanged(Modules::Render::ViewScene::CameraRotation,[this](){Q_EMIT cameraRotationChangeForwarder();});
144+
connect(this, SIGNAL(cameraRotationChangeForwarder()), this, SLOT(pullCameraRotation()));
145+
146+
state->connectSpecificStateChanged(Modules::Render::ViewScene::CameraLookAt,[this](){Q_EMIT cameraLookAtChangeForwarder();});
147+
connect(this, SIGNAL(cameraLookAtChangeForwarder()), this, SLOT(pullCameraLookAt()));
148+
149+
state->connectSpecificStateChanged(Modules::Render::ViewScene::CameraDistance,[this](){Q_EMIT cameraDistnaceChangeForwarder();});
150+
connect(this, SIGNAL(cameraDistnaceChangeForwarder()), this, SLOT(pullCameraDistance()));
151+
143152
std::string filesystemRoot = Application::Instance().executablePath().string();
144153
std::string sep;
145154
sep += boost::filesystem::path::preferred_separator;
@@ -492,9 +501,43 @@ void ViewSceneDialog::pullCameraState()
492501
spire->setCameraRotation(glm::quat(rotation[0], rotation[1], rotation[2], rotation[3]));
493502
}
494503

504+
//--------------------------------------------------------------------------------------------------
505+
void ViewSceneDialog::pullCameraRotation()
506+
{
507+
if(pushingCameraState_) return;
508+
auto spire = mSpire.lock();
509+
if(!spire) return;
510+
511+
auto rotation = toDoubleVector(state_->getValue(Modules::Render::ViewScene::CameraRotation).toVector());
512+
spire->setCameraRotation(glm::quat(rotation[0], rotation[1], rotation[2], rotation[3]));
513+
}
514+
515+
//--------------------------------------------------------------------------------------------------
516+
void ViewSceneDialog::pullCameraLookAt()
517+
{
518+
if(pushingCameraState_) return;
519+
auto spire = mSpire.lock();
520+
if(!spire) return;
521+
522+
auto lookAt = toDoubleVector(state_->getValue(Modules::Render::ViewScene::CameraLookAt).toVector());
523+
spire->setCameraLookAt(glm::vec3(lookAt[0], lookAt[1], lookAt[2]));
524+
}
525+
526+
//--------------------------------------------------------------------------------------------------
527+
void ViewSceneDialog::pullCameraDistance()
528+
{
529+
if(pushingCameraState_) return;
530+
auto spire = mSpire.lock();
531+
if(!spire) return;
532+
533+
float distance = state_->getValue(Modules::Render::ViewScene::CameraDistance).toDouble();
534+
spire->setCameraDistance(distance);
535+
}
536+
495537
//--------------------------------------------------------------------------------------------------
496538
void ViewSceneDialog::pushCameraState()
497539
{
540+
pushingCameraState_ = true;
498541
auto spire = mSpire.lock();
499542
if(!spire) return;
500543

@@ -507,6 +550,7 @@ void ViewSceneDialog::pushCameraState()
507550
glm::quat q = spire->getCameraRotation();
508551
auto rotation = makeAnonymousVariableList((double)q.w, (double)q.x, (double)q.y, (double)q.z);
509552
state_->setValue(Modules::Render::ViewScene::CameraRotation, rotation);
553+
pushingCameraState_ = false;
510554
}
511555

512556
//--------------------------------------------------------------------------------------------------

src/Interface/Modules/Render/ViewScene.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ namespace SCIRun {
6969

7070
Q_SIGNALS:
7171
void newGeometryValueForwarder();
72+
void cameraRotationChangeForwarder();
73+
void cameraLookAtChangeForwarder();
74+
void cameraDistnaceChangeForwarder();
7275
void mousePressSignalForTestingGeometryObjectFeedback(int x, int y, const std::string& selName);
7376

7477

@@ -110,6 +113,9 @@ namespace SCIRun {
110113
void autoRotateLeft();
111114
void autoRotateUp();
112115
void autoRotateDown();
116+
void pullCameraRotation();
117+
void pullCameraLookAt();
118+
void pullCameraDistance();
113119

114120

115121
//---------------- Widgets -------------------------------------------------------------------
@@ -298,6 +304,7 @@ namespace SCIRun {
298304
bool saveScreenshotOnNewGeometry_ {false};
299305
bool pulledSavedVisibility_ {false};
300306
QTimer resizeTimer_ {};
307+
std::atomic<bool> pushingCameraState_ {false};
301308

302309
//geometries
303310
Modules::Visualization::TextBuilder textBuilder_ {};

0 commit comments

Comments
 (0)