Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] allow changing pitch in GLFW based apps
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Nov 17, 2015
1 parent 7288473 commit 85ab486
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/mbgl/platform/default/glfw_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class GLFWView : public mbgl::View {
const bool benchmark = false;
bool tracking = false;
bool rotating = false;
bool pitching = false;

// Frame timer
int frames = 0;
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/platform/default/settings_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Settings_JSON {
double latitude = 0;
double zoom = 0;
double bearing = 0;
double pitch = 0;

bool debug = false;
};
Expand Down
10 changes: 9 additions & 1 deletion linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) {
bool benchmark = false;
std::string style;
double latitude = 0, longitude = 0;
double bearing = 0, zoom = 1;
double bearing = 0, zoom = 1, pitch = 0;
bool skipConfig = false;

const struct option long_options[] = {
Expand All @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) {
{"lat", required_argument, 0, 'y'},
{"zoom", required_argument, 0, 'z'},
{"bearing", required_argument, 0, 'r'},
{"pitch", required_argument, 0, 'p'},
{0, 0, 0, 0}
};

Expand Down Expand Up @@ -83,6 +84,10 @@ int main(int argc, char *argv[]) {
bearing = atof(optarg);
skipConfig = true;
break;
case 'p':
pitch = atof(optarg);
skipConfig = true;
break;
default:
break;
}
Expand Down Expand Up @@ -121,10 +126,12 @@ int main(int argc, char *argv[]) {
if (skipConfig) {
map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom);
map.setBearing(bearing);
map.setPitch(pitch);
mbgl::Log::Info(mbgl::Event::General, "Location: %f/%f (z%.2f, %.2f deg)", latitude, longitude, zoom, bearing);
} else {
map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom);
map.setBearing(settings.bearing);
map.setPitch(settings.pitch);
map.setDebug(settings.debug);
}

Expand Down Expand Up @@ -159,6 +166,7 @@ int main(int argc, char *argv[]) {
settings.longitude = latLng.longitude;
settings.zoom = map.getZoom();
settings.bearing = map.getBearing();
settings.pitch = map.getPitch();
settings.debug = map.getDebug();
if (!skipConfig) {
settings.save();
Expand Down
2 changes: 2 additions & 0 deletions macosx/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ int main(int argc, char* argv[]) {
mbgl::Settings_NSUserDefaults settings;
map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom);
map.setBearing(settings.bearing);
map.setPitch(settings.pitch);
map.setDebug(settings.debug);

view.setChangeStyleCallback([&map, &view] () {
Expand Down Expand Up @@ -203,6 +204,7 @@ int main(int argc, char* argv[]) {
settings.longitude = latLng.longitude;
settings.zoom = map.getZoom();
settings.bearing = map.getBearing();
settings.pitch = map.getPitch();
settings.debug = map.getDebug();
settings.save();

Expand Down
8 changes: 8 additions & 0 deletions platform/default/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modi
(button == GLFW_MOUSE_BUTTON_LEFT && modifiers & GLFW_MOD_CONTROL)) {
view->rotating = action == GLFW_PRESS;
view->map->setGestureInProgress(view->rotating);
} else if (button == GLFW_MOUSE_BUTTON_LEFT && (modifiers & GLFW_MOD_SHIFT)) {
view->pitching = action == GLFW_PRESS;
view->map->setGestureInProgress(view->pitching);
} else if (button == GLFW_MOUSE_BUTTON_LEFT) {
view->tracking = action == GLFW_PRESS;
view->map->setGestureInProgress(view->tracking);
Expand Down Expand Up @@ -336,6 +339,11 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) {
}
} else if (view->rotating) {
view->map->rotateBy({ view->lastX, view->lastY }, { x, y });
} else if (view->pitching) {
const double dy = y - view->lastY;
if (dy) {
view->map->setPitch(view->map->getPitch() - dy / 2);
}
}
view->lastX = x;
view->lastY = y;
Expand Down
3 changes: 3 additions & 0 deletions platform/default/settings_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void Settings_JSON::load() {
file >> latitude;
file >> zoom;
file >> bearing;
file >> pitch;
file >> debug;
}
}
Expand All @@ -23,6 +24,7 @@ void Settings_JSON::save() {
file << latitude << std::endl;
file << zoom << std::endl;
file << bearing << std::endl;
file << pitch << std::endl;
file << debug << std::endl;
}
}
Expand All @@ -32,5 +34,6 @@ void Settings_JSON::clear() {
latitude = 0;
zoom = 0;
bearing = 0;
pitch = 0;
debug = false;
}

0 comments on commit 85ab486

Please sign in to comment.