[core] allow changing pitch in GLFW based apps

This commit is contained in:
Konstantin Käfer
2015-11-17 13:27:42 +01:00
parent 728847329c
commit 85ab48636c
6 changed files with 24 additions and 1 deletions

View File

@@ -65,6 +65,7 @@ private:
const bool benchmark = false;
bool tracking = false;
bool rotating = false;
bool pitching = false;
// Frame timer
int frames = 0;

View File

@@ -15,6 +15,7 @@ public:
double latitude = 0;
double zoom = 0;
double bearing = 0;
double pitch = 0;
bool debug = false;
};

View File

@@ -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[] = {
@@ -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}
};
@@ -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;
}
@@ -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);
}
@@ -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();

View File

@@ -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] () {
@@ -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();

View File

@@ -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);
@@ -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;

View File

@@ -12,6 +12,7 @@ void Settings_JSON::load() {
file >> latitude;
file >> zoom;
file >> bearing;
file >> pitch;
file >> debug;
}
}
@@ -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;
}
}
@@ -32,5 +34,6 @@ void Settings_JSON::clear() {
latitude = 0;
zoom = 0;
bearing = 0;
pitch = 0;
debug = false;
}