Skip to content

Commit e67f967

Browse files
dynamodanwhitequark
authored andcommitted
Implement turntable (SketchUp-like) mouse navigation.
1 parent c2c26e9 commit e67f967

File tree

7 files changed

+46
-8
lines changed

7 files changed

+46
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ New export/import features:
4646
exported. This format allows to easily hack on triangle mesh data created
4747
in SolveSpace, supports colour information and is more space efficient than
4848
most other formats.
49-
* Export 2d section: custom styled entities that lie in the same
49+
* Export 2d section: custom styled entities that lie in the same
5050
plane as the exported section are included.
5151

5252
New rendering features:
@@ -68,6 +68,7 @@ New measurement/analysis features:
6868
Other new features:
6969
* New command-line interface, for batch exporting and more.
7070
* The graphical interface now supports HiDPI screens on every OS.
71+
* New option to lock Z axis to be always vertical, like in SketchUp.
7172
* New link to match the on-screen size of the sketch with its actual size,
7273
"view → set to full scale".
7374
* When zooming to fit, constraints are also considered.

src/confscreen.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ void TextWindow::ScreenChangeBackFaces(int link, uint32_t v) {
8383
SS.GW.Invalidate(/*clearPersistent=*/true);
8484
}
8585

86+
void TextWindow::ScreenChangeTurntableNav(int link, uint32_t v) {
87+
SS.turntableNav = !SS.turntableNav;
88+
if(SS.turntableNav) {
89+
// If turntable nav is being turned on, align view so Z is vertical
90+
SS.GW.AnimateOnto(Quaternion::From(Vector::From(-1, 0, 0), Vector::From(0, 0, 1)),
91+
SS.GW.offset);
92+
}
93+
}
94+
8695
void TextWindow::ScreenChangeShowContourAreas(int link, uint32_t v) {
8796
SS.showContourAreas = !SS.showContourAreas;
8897
SS.GW.Invalidate();
@@ -306,13 +315,14 @@ void TextWindow::ShowConfiguration() {
306315
Printf(false, " %Fd%f%Ll%s check sketch for closed contour%E",
307316
&ScreenChangeCheckClosedContour,
308317
SS.checkClosedContour ? CHECK_TRUE : CHECK_FALSE);
309-
Printf(false, " %Fd%f%Ll%s enable automatic line constraints%E",
310-
&ScreenChangeAutomaticLineConstraints,
311-
SS.automaticLineConstraints ? CHECK_TRUE : CHECK_FALSE);
312318
Printf(false, " %Fd%f%Ll%s show areas of closed contours%E",
313319
&ScreenChangeShowContourAreas,
314320
SS.showContourAreas ? CHECK_TRUE : CHECK_FALSE);
315-
321+
Printf(false, " %Fd%f%Ll%s enable automatic line constraints%E",
322+
&ScreenChangeAutomaticLineConstraints,
323+
SS.automaticLineConstraints ? CHECK_TRUE : CHECK_FALSE);
324+
Printf(false, " %Fd%f%Ll%s use turntable mouse navigation%E", &ScreenChangeTurntableNav,
325+
SS.turntableNav ? CHECK_TRUE : CHECK_FALSE);
316326
Printf(false, "");
317327
Printf(false, "%Ft autosave interval (in minutes)%E");
318328
Printf(false, "%Ba %d %Fl%Ll%f[change]%E",

src/graphicswin.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,21 @@ void GraphicsWindow::AnimateOntoWorkplane() {
427427

428428
Entity *w = SK.GetEntity(ActiveWorkplane());
429429
Quaternion quatf = w->Normal()->NormalGetNum();
430+
431+
// Get Z pointing vertical, if we're on turntable nav mode:
432+
if(SS.turntableNav) {
433+
Vector normalRight = quatf.RotationU();
434+
Vector normalUp = quatf.RotationV();
435+
Vector normal = normalRight.Cross(normalUp);
436+
if(normalRight.z != 0) {
437+
double theta = atan2(normalUp.z, normalRight.z);
438+
theta -= atan2(1, 0);
439+
normalRight = normalRight.RotatedAbout(normal, theta);
440+
normalUp = normalUp.RotatedAbout(normal, theta);
441+
quatf = Quaternion::From(normalRight, normalUp);
442+
}
443+
}
444+
430445
Vector offsetf = (SK.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1);
431446

432447
// If the view screen is open, then we need to refresh it.

src/mouse.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,14 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
135135

136136
if(!(shiftDown || ctrlDown)) {
137137
double s = 0.3*(PI/180)*scale; // degrees per pixel
138-
projRight = orig.projRight.RotatedAbout(orig.projUp, -s*dx);
139-
projUp = orig.projUp.RotatedAbout(orig.projRight, s*dy);
138+
if(SS.turntableNav) { // lock the Z to vertical
139+
projRight = orig.projRight.RotatedAbout(Vector::From(0, 0, 1), -s * dx);
140+
projUp = orig.projUp.RotatedAbout(
141+
Vector::From(orig.projRight.x, orig.projRight.y, orig.projRight.y), s * dy);
142+
} else {
143+
projRight = orig.projRight.RotatedAbout(orig.projUp, -s * dx);
144+
projUp = orig.projUp.RotatedAbout(orig.projRight, s * dy);
145+
}
140146

141147
NormalizeProjectionVectors();
142148
} else if(ctrlDown) {

src/solvespace.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ void SolveSpaceUI::Init() {
6868
fixExportColors = settings->ThawBool("FixExportColors", true);
6969
// Draw back faces of triangles (when mesh is leaky/self-intersecting)
7070
drawBackFaces = settings->ThawBool("DrawBackFaces", true);
71+
// Use turntable mouse navigation
72+
turntableNav = settings->ThawBool("TurntableNav", false);
7173
// Check that contours are closed and not self-intersecting
7274
checkClosedContour = settings->ThawBool("CheckClosedContour", true);
7375
// Enable automatic constrains for lines
@@ -243,6 +245,8 @@ void SolveSpaceUI::Exit() {
243245
settings->FreezeBool("ShowContourAreas", showContourAreas);
244246
// Check that contours are closed and not self-intersecting
245247
settings->FreezeBool("CheckClosedContour", checkClosedContour);
248+
// Use turntable mouse navigation
249+
settings->FreezeBool("TurntableNav", turntableNav);
246250
// Enable automatic constrains for lines
247251
settings->FreezeBool("AutomaticLineConstraints", automaticLineConstraints);
248252
// Export shaded triangles in a 2d view

src/solvespace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class StepFileWriter {
324324
public:
325325
void ExportSurfacesTo(const Platform::Path &filename);
326326
void WriteHeader();
327-
void WriteProductHeader();
327+
void WriteProductHeader();
328328
int ExportCurve(SBezier *sb);
329329
int ExportCurveLoop(SBezierLoop *loop, bool inner);
330330
void ExportSurface(SSurface *ss, SBezierList *sbl);
@@ -590,6 +590,7 @@ class SolveSpaceUI {
590590
bool drawBackFaces;
591591
bool showContourAreas;
592592
bool checkClosedContour;
593+
bool turntableNav;
593594
bool automaticLineConstraints;
594595
bool showToolbar;
595596
Platform::Path screenshotFile;

src/ui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ class TextWindow {
425425
static void ScreenChangeBackFaces(int link, uint32_t v);
426426
static void ScreenChangeShowContourAreas(int link, uint32_t v);
427427
static void ScreenChangeCheckClosedContour(int link, uint32_t v);
428+
static void ScreenChangeTurntableNav(int link, uint32_t v);
428429
static void ScreenChangeAutomaticLineConstraints(int link, uint32_t v);
429430
static void ScreenChangePwlCurves(int link, uint32_t v);
430431
static void ScreenChangeCanvasSizeAuto(int link, uint32_t v);

0 commit comments

Comments
 (0)