Implement turntable (SketchUp-like) mouse navigation.

This commit is contained in:
Dynamo Dan 2016-12-29 09:34:30 -05:00 committed by whitequark
parent c2c26e95ad
commit e67f967933
7 changed files with 46 additions and 8 deletions

View File

@ -46,7 +46,7 @@ New export/import features:
exported. This format allows to easily hack on triangle mesh data created exported. This format allows to easily hack on triangle mesh data created
in SolveSpace, supports colour information and is more space efficient than in SolveSpace, supports colour information and is more space efficient than
most other formats. most other formats.
* Export 2d section: custom styled entities that lie in the same * Export 2d section: custom styled entities that lie in the same
plane as the exported section are included. plane as the exported section are included.
New rendering features: New rendering features:
@ -68,6 +68,7 @@ New measurement/analysis features:
Other new features: Other new features:
* New command-line interface, for batch exporting and more. * New command-line interface, for batch exporting and more.
* The graphical interface now supports HiDPI screens on every OS. * The graphical interface now supports HiDPI screens on every OS.
* New option to lock Z axis to be always vertical, like in SketchUp.
* New link to match the on-screen size of the sketch with its actual size, * New link to match the on-screen size of the sketch with its actual size,
"view → set to full scale". "view → set to full scale".
* When zooming to fit, constraints are also considered. * When zooming to fit, constraints are also considered.

View File

@ -83,6 +83,15 @@ void TextWindow::ScreenChangeBackFaces(int link, uint32_t v) {
SS.GW.Invalidate(/*clearPersistent=*/true); SS.GW.Invalidate(/*clearPersistent=*/true);
} }
void TextWindow::ScreenChangeTurntableNav(int link, uint32_t v) {
SS.turntableNav = !SS.turntableNav;
if(SS.turntableNav) {
// If turntable nav is being turned on, align view so Z is vertical
SS.GW.AnimateOnto(Quaternion::From(Vector::From(-1, 0, 0), Vector::From(0, 0, 1)),
SS.GW.offset);
}
}
void TextWindow::ScreenChangeShowContourAreas(int link, uint32_t v) { void TextWindow::ScreenChangeShowContourAreas(int link, uint32_t v) {
SS.showContourAreas = !SS.showContourAreas; SS.showContourAreas = !SS.showContourAreas;
SS.GW.Invalidate(); SS.GW.Invalidate();
@ -306,13 +315,14 @@ void TextWindow::ShowConfiguration() {
Printf(false, " %Fd%f%Ll%s check sketch for closed contour%E", Printf(false, " %Fd%f%Ll%s check sketch for closed contour%E",
&ScreenChangeCheckClosedContour, &ScreenChangeCheckClosedContour,
SS.checkClosedContour ? CHECK_TRUE : CHECK_FALSE); SS.checkClosedContour ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%s enable automatic line constraints%E",
&ScreenChangeAutomaticLineConstraints,
SS.automaticLineConstraints ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%s show areas of closed contours%E", Printf(false, " %Fd%f%Ll%s show areas of closed contours%E",
&ScreenChangeShowContourAreas, &ScreenChangeShowContourAreas,
SS.showContourAreas ? CHECK_TRUE : CHECK_FALSE); SS.showContourAreas ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%s enable automatic line constraints%E",
&ScreenChangeAutomaticLineConstraints,
SS.automaticLineConstraints ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%s use turntable mouse navigation%E", &ScreenChangeTurntableNav,
SS.turntableNav ? CHECK_TRUE : CHECK_FALSE);
Printf(false, ""); Printf(false, "");
Printf(false, "%Ft autosave interval (in minutes)%E"); Printf(false, "%Ft autosave interval (in minutes)%E");
Printf(false, "%Ba %d %Fl%Ll%f[change]%E", Printf(false, "%Ba %d %Fl%Ll%f[change]%E",

View File

@ -427,6 +427,21 @@ void GraphicsWindow::AnimateOntoWorkplane() {
Entity *w = SK.GetEntity(ActiveWorkplane()); Entity *w = SK.GetEntity(ActiveWorkplane());
Quaternion quatf = w->Normal()->NormalGetNum(); Quaternion quatf = w->Normal()->NormalGetNum();
// Get Z pointing vertical, if we're on turntable nav mode:
if(SS.turntableNav) {
Vector normalRight = quatf.RotationU();
Vector normalUp = quatf.RotationV();
Vector normal = normalRight.Cross(normalUp);
if(normalRight.z != 0) {
double theta = atan2(normalUp.z, normalRight.z);
theta -= atan2(1, 0);
normalRight = normalRight.RotatedAbout(normal, theta);
normalUp = normalUp.RotatedAbout(normal, theta);
quatf = Quaternion::From(normalRight, normalUp);
}
}
Vector offsetf = (SK.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1); Vector offsetf = (SK.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1);
// If the view screen is open, then we need to refresh it. // If the view screen is open, then we need to refresh it.

View File

@ -135,8 +135,14 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
if(!(shiftDown || ctrlDown)) { if(!(shiftDown || ctrlDown)) {
double s = 0.3*(PI/180)*scale; // degrees per pixel double s = 0.3*(PI/180)*scale; // degrees per pixel
projRight = orig.projRight.RotatedAbout(orig.projUp, -s*dx); if(SS.turntableNav) { // lock the Z to vertical
projUp = orig.projUp.RotatedAbout(orig.projRight, s*dy); projRight = orig.projRight.RotatedAbout(Vector::From(0, 0, 1), -s * dx);
projUp = orig.projUp.RotatedAbout(
Vector::From(orig.projRight.x, orig.projRight.y, orig.projRight.y), s * dy);
} else {
projRight = orig.projRight.RotatedAbout(orig.projUp, -s * dx);
projUp = orig.projUp.RotatedAbout(orig.projRight, s * dy);
}
NormalizeProjectionVectors(); NormalizeProjectionVectors();
} else if(ctrlDown) { } else if(ctrlDown) {

View File

@ -68,6 +68,8 @@ void SolveSpaceUI::Init() {
fixExportColors = settings->ThawBool("FixExportColors", true); fixExportColors = settings->ThawBool("FixExportColors", true);
// Draw back faces of triangles (when mesh is leaky/self-intersecting) // Draw back faces of triangles (when mesh is leaky/self-intersecting)
drawBackFaces = settings->ThawBool("DrawBackFaces", true); drawBackFaces = settings->ThawBool("DrawBackFaces", true);
// Use turntable mouse navigation
turntableNav = settings->ThawBool("TurntableNav", false);
// Check that contours are closed and not self-intersecting // Check that contours are closed and not self-intersecting
checkClosedContour = settings->ThawBool("CheckClosedContour", true); checkClosedContour = settings->ThawBool("CheckClosedContour", true);
// Enable automatic constrains for lines // Enable automatic constrains for lines
@ -243,6 +245,8 @@ void SolveSpaceUI::Exit() {
settings->FreezeBool("ShowContourAreas", showContourAreas); settings->FreezeBool("ShowContourAreas", showContourAreas);
// Check that contours are closed and not self-intersecting // Check that contours are closed and not self-intersecting
settings->FreezeBool("CheckClosedContour", checkClosedContour); settings->FreezeBool("CheckClosedContour", checkClosedContour);
// Use turntable mouse navigation
settings->FreezeBool("TurntableNav", turntableNav);
// Enable automatic constrains for lines // Enable automatic constrains for lines
settings->FreezeBool("AutomaticLineConstraints", automaticLineConstraints); settings->FreezeBool("AutomaticLineConstraints", automaticLineConstraints);
// Export shaded triangles in a 2d view // Export shaded triangles in a 2d view

View File

@ -324,7 +324,7 @@ class StepFileWriter {
public: public:
void ExportSurfacesTo(const Platform::Path &filename); void ExportSurfacesTo(const Platform::Path &filename);
void WriteHeader(); void WriteHeader();
void WriteProductHeader(); void WriteProductHeader();
int ExportCurve(SBezier *sb); int ExportCurve(SBezier *sb);
int ExportCurveLoop(SBezierLoop *loop, bool inner); int ExportCurveLoop(SBezierLoop *loop, bool inner);
void ExportSurface(SSurface *ss, SBezierList *sbl); void ExportSurface(SSurface *ss, SBezierList *sbl);
@ -590,6 +590,7 @@ public:
bool drawBackFaces; bool drawBackFaces;
bool showContourAreas; bool showContourAreas;
bool checkClosedContour; bool checkClosedContour;
bool turntableNav;
bool automaticLineConstraints; bool automaticLineConstraints;
bool showToolbar; bool showToolbar;
Platform::Path screenshotFile; Platform::Path screenshotFile;

View File

@ -425,6 +425,7 @@ public:
static void ScreenChangeBackFaces(int link, uint32_t v); static void ScreenChangeBackFaces(int link, uint32_t v);
static void ScreenChangeShowContourAreas(int link, uint32_t v); static void ScreenChangeShowContourAreas(int link, uint32_t v);
static void ScreenChangeCheckClosedContour(int link, uint32_t v); static void ScreenChangeCheckClosedContour(int link, uint32_t v);
static void ScreenChangeTurntableNav(int link, uint32_t v);
static void ScreenChangeAutomaticLineConstraints(int link, uint32_t v); static void ScreenChangeAutomaticLineConstraints(int link, uint32_t v);
static void ScreenChangePwlCurves(int link, uint32_t v); static void ScreenChangePwlCurves(int link, uint32_t v);
static void ScreenChangeCanvasSizeAuto(int link, uint32_t v); static void ScreenChangeCanvasSizeAuto(int link, uint32_t v);