Skip to content

Commit 59c60dc

Browse files
committed
move camera to model front after mesh is unfolded, viewer to singleton
1 parent 951a681 commit 59c60dc

File tree

7 files changed

+88
-67
lines changed

7 files changed

+88
-67
lines changed

src/GeomProc/meshmanager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "MeshFactory/MeshDFormer.h"
1111
#include "MeshIterator.h"
1212
#include "GeomProc/MeshConnector.h"
13+
#include "UI/MeshViewer.h"
1314

1415
#include "Utils/utils.h"
1516

@@ -628,6 +629,7 @@ bool MeshManager::unfoldMesh()
628629
// unfolded successfully
629630
outMesh->printInfo("unfolded mesh:");
630631
operationStack->push(outMesh);
632+
MeshViewer::getInstance()->unfoldView(outMesh);
631633
return true;
632634
}
633635
else

src/UI/Camera.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ perspCamera::perspCamera(const QVector3D& eyePos, const QVector3D& targetPos,
1010
CameraToScreen.perspective(verticalAngle, aspectRatio, nearPlane, farPlane);
1111
}
1212

13-
QVector3D perspCamera::getTarget() const
14-
{
15-
return target;
16-
}
1713

1814
void perspCamera::zoom(Float x_val, Float y_val, Float z_val)
1915
{

src/UI/Camera.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class perspCamera
2525
Float verticalAngle = 54.3, Float aspectRatio = 1.67,
2626
Float nearPlane = 0.01, Float farPlane = 100);
2727

28-
QVector3D getTarget() const;
28+
QVector3D getTarget() const { return target; }
29+
void setTarget(const QVector3D &vec) { target = vec; }
2930

3031
void zoom(Float x_val = 0, Float y_val = 0, Float z_val = 0);
3132
void rotate(Float x_rot = 0, Float y_rot = 0, Float z_rot = 0);

src/UI/MeshViewer.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <QFileDialog>
33
#include "GeomProc/meshunfolder.h"
44
#include "UI/SelectByRefIdPanel.h"
5-
//MeshViewer* MeshViewer::instance = nullptr;
65

6+
MeshViewer* MeshViewer::instance = nullptr;
77

88
MeshViewer::MeshViewer(QWidget *parent)
99
: QOpenGLWidget(parent)
@@ -132,6 +132,18 @@ void MeshViewer::initializeGL()
132132
glGenBuffers(2, fRBO.tbo);
133133
}
134134

135+
void MeshViewer::unfoldView(const HDS_Mesh* inMesh)
136+
{
137+
QVector3D boundMid = inMesh->bound->getMidPoint();
138+
view_cam.setTarget(boundMid);
139+
boundMid.setZ(10);
140+
141+
view_cam.WorldToCamera.setToIdentity();
142+
view_cam.WorldToCamera.lookAt(
143+
boundMid, view_cam.getTarget(), QVector3D(0, 1, 0));
144+
view_cam.CameraToWorld = view_cam.WorldToCamera.inverted();
145+
}
146+
135147
void MeshViewer::allocateGL()
136148
{
137149
// Clear Selection

src/UI/MeshViewer.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,21 @@ class MeshViewer
105105
: public QOpenGLWidget, oglFuncs
106106
{
107107
Q_OBJECT
108-
public:
108+
private:
109109
explicit MeshViewer(QWidget *parent = nullptr);
110+
MeshViewer(const MeshViewer &) = delete;
111+
MeshViewer& operator = (const MeshViewer &) = delete;
112+
110113
~MeshViewer();
111114
public:
112-
//void getInstance();
115+
static MeshViewer* getInstance()
116+
{
117+
if (!instance)
118+
{
119+
instance = new MeshViewer;
120+
}
121+
return instance;
122+
}
113123

114124
void bindHalfEdgeMesh(HDS_Mesh *mesh);
115125

@@ -157,6 +167,7 @@ class MeshViewer
157167
void toggleLightingWireframe();
158168
void toggleText();
159169

170+
void unfoldView(const HDS_Mesh* inMesh);
160171
private: // paint function
161172
void allocateGL();
162173

@@ -279,7 +290,7 @@ class MeshViewer
279290
uint32_t dispComp;//Display Components Flag
280291
uint32_t hlComp;// Highlight Components Flag
281292
private:
282-
//static MeshViewer* instance;
293+
static MeshViewer* instance;
283294
//viewer status
284295
perspCamera view_cam;
285296

0 commit comments

Comments
 (0)