Skip to content
Open

pr #2357

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/deps/miniz/miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int
pnghdr[18] = (mz_uint8)(w >> 8);
pnghdr[19] = (mz_uint8)w;
pnghdr[22] = (mz_uint8)(h >> 8);
pnghdr[22] = (mz_uint8)h;
pnghdr[23] = (mz_uint8)h;
pnghdr[25] = chans[num_chans];
pnghdr[33] = (mz_uint8)(*pLen_out >> 24);
pnghdr[34] = (mz_uint8)(*pLen_out >> 16);
Expand Down
9 changes: 9 additions & 0 deletions core/include/tangram/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct CameraPosition {
float zoom = 0;
float rotation = 0;
float tilt = 0;
float roll = 0;
};

struct EdgePadding {
Expand Down Expand Up @@ -126,6 +127,8 @@ struct CameraUpdate {
set_tilt_by = 1 << 6,
set_bounds = 1 << 7,
set_camera = 1 << 8,
set_roll = 1 << 9,
set_roll_by = 1 << 10,
};
int set = 0;

Expand All @@ -136,6 +139,8 @@ struct CameraUpdate {
float rotationBy = 0;
float tilt = 0;
float tiltBy = 0;
float roll = 0;
float rollBy = 0;
std::array<LngLat,2> bounds;
EdgePadding padding;
};
Expand Down Expand Up @@ -283,6 +288,10 @@ class Map {
// Get the tilt angle of the view in radians; 0 corresponds to straight down
float getTilt();

void setRoll(float _radians);

float getRoll();

// Set the padding on the map view. The center position of the map will be drawn at the center of the view area
// inside the padding.
void setPadding(const EdgePadding& padding);
Expand Down
64 changes: 45 additions & 19 deletions core/src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct CameraEase {
float zoom = 0;
float rotation = 0;
float tilt = 0;
float roll = 0;
} start, end;
};

Expand Down Expand Up @@ -352,6 +353,7 @@ CameraPosition Map::getCameraPosition() {
camera.zoom = getZoom();
camera.rotation = getRotation();
camera.tilt = getTilt();
camera.roll = impl->view.getRoll();

return camera;
}
Expand All @@ -370,8 +372,9 @@ void Map::setCameraPosition(const CameraPosition& _camera) {
cancelCameraAnimation();

impl->view.setZoom(_camera.zoom);
impl->view.setRoll(_camera.rotation);
impl->view.setYaw(_camera.rotation);
impl->view.setPitch(_camera.tilt);
impl->view.setRoll(_camera.roll);
impl->view.setCenterCoordinates(LngLat(_camera.longitude, _camera.latitude));

impl->platform.requestRender();
Expand Down Expand Up @@ -401,27 +404,31 @@ void Map::setCameraPositionEased(const CameraPosition& _camera, float _duration,
e.start.zoom = getZoom();
e.end.zoom = glm::clamp(_camera.zoom, getMinZoom(), getMaxZoom());

float radiansStart = getRotation();

float yawStart = getRotation();
// Ease over the smallest angular distance needed
float radiansDelta = glm::mod(_camera.rotation - radiansStart, (float)TWO_PI);
if (radiansDelta > PI) { radiansDelta -= TWO_PI; }
float yawDelta = glm::mod(_camera.rotation - yawStart, (float)TWO_PI);
if (yawDelta > PI) { yawDelta -= TWO_PI; }

e.start.rotation = radiansStart;
e.end.rotation = radiansStart + radiansDelta;
e.start.rotation = yawStart;
e.end.rotation = yawStart + yawDelta;

e.start.tilt = getTilt();
e.end.tilt = _camera.tilt;

e.start.roll = impl->view.getRoll();
e.end.roll = _camera.roll;

impl->ease = std::make_unique<Ease>(_duration,
[=](float t) {
impl->view.setPosition(ease(e.start.pos.x, e.end.pos.x, t, _e),
ease(e.start.pos.y, e.end.pos.y, t, _e));
impl->view.setZoom(ease(e.start.zoom, e.end.zoom, t, _e));

impl->view.setRoll(ease(e.start.rotation, e.end.rotation, t, _e));
impl->view.setYaw(ease(e.start.rotation, e.end.rotation, t, _e));

impl->view.setPitch(ease(e.start.tilt, e.end.tilt, t, _e));
impl->view.setRoll(ease(e.start.roll, e.end.roll, t, _e));
});

platform->requestRender();
Expand Down Expand Up @@ -464,6 +471,9 @@ void Map::updateCameraPosition(const CameraUpdate& _update, float _duration, Eas
if ((_update.set & CameraUpdate::set_tilt) != 0) {
camera.tilt = _update.tilt;
}
if ((_update.set & CameraUpdate::set_roll) != 0) {
camera.roll = _update.roll;
}
if ((_update.set & CameraUpdate::set_zoom_by) != 0) {
camera.zoom += _update.zoomBy;
}
Expand All @@ -473,6 +483,9 @@ void Map::updateCameraPosition(const CameraUpdate& _update, float _duration, Eas
if ((_update.set & CameraUpdate::set_tilt_by) != 0) {
camera.tilt += _update.tiltBy;
}
if ((_update.set & CameraUpdate::set_roll_by) != 0) {
camera.roll += _update.rollBy;
}

if (_duration == 0.f) {
setCameraPosition(camera);
Expand Down Expand Up @@ -532,12 +545,12 @@ float Map::getMaxZoom() const {
void Map::setRotation(float _radians) {
cancelCameraAnimation();

impl->view.setRoll(_radians);
impl->view.setYaw(_radians);
impl->platform.requestRender();
}

float Map::getRotation() {
return impl->view.getRoll();
return impl->view.getYaw();
}

void Map::setTilt(float _radians) {
Expand All @@ -551,6 +564,17 @@ float Map::getTilt() {
return impl->view.getPitch();
}

void Map::setRoll(float _radians) {
cancelCameraAnimation();

impl->view.setRoll(_radians);
impl->platform.requestRender();
}

float Map::getRoll() {
return impl->view.getRoll();
}

void Map::setPadding(const EdgePadding& padding) {
impl->view.setPadding(padding);
}
Expand Down Expand Up @@ -603,13 +627,14 @@ void Map::flyTo(const CameraPosition& _camera, float _duration, float _speed) {
double lngStart = 0., latStart = 0., lngEnd = _camera.longitude, latEnd = _camera.latitude;
getPosition(lngStart, latStart);
float zStart = getZoom();
float rStart = getRotation();
float tStart = getTilt();
float yawStart = getRotation();
float tiltStart = getTilt();
float rollStart = impl->view.getRoll();

// Ease over the smallest angular distance needed
float radiansDelta = glm::mod(_camera.rotation - rStart, (float)TWO_PI);
if (radiansDelta > PI) { radiansDelta -= TWO_PI; }
float rEnd = rStart + radiansDelta;
float yawDelta = glm::mod(_camera.rotation - yawStart, (float)TWO_PI);
if (yawDelta > PI) { yawDelta -= TWO_PI; }
float yawEnd = yawStart + yawDelta;

double dLongitude = lngEnd - lngStart;
if (dLongitude > 180.0) {
Expand All @@ -628,15 +653,16 @@ void Map::flyTo(const CameraPosition& _camera, float _duration, float _speed) {
distance);

EaseType e = EaseType::cubic;
auto cb =
auto cb =
[=](float t) {
glm::dvec3 pos = fn(t);
impl->view.setPosition(pos.x, pos.y);
impl->view.setZoom(pos.z);
impl->view.setRoll(ease(rStart, rEnd, t, e));
impl->view.setPitch(ease(tStart, _camera.tilt, t, e));
impl->view.setYaw(ease(yawStart, yawEnd, t, e));
impl->view.setPitch(ease(tiltStart, _camera.tilt, t, e));
impl->view.setRoll(ease(rollStart, _camera.roll, t, e));
impl->platform.requestRender();
};
};

if (_speed <= 0.f) { _speed = 1.f; }

Expand Down
2 changes: 1 addition & 1 deletion core/src/scene/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <condition_variable>

using YAML::Node;
using YAML::NodeType;
namespace NodeType = YAML::NodeType;

namespace Tangram {

Expand Down
2 changes: 1 addition & 1 deletion core/src/scene/sceneLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <vector>

using YAML::Node;
using YAML::NodeType;
namespace NodeType = YAML::NodeType;
using YAML::BadConversion;

#define LOGNode(fmt, node, ...) LOGW(fmt ":\n'%s'\n", ## __VA_ARGS__, Dump(node).c_str())
Expand Down
2 changes: 1 addition & 1 deletion core/src/util/inputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void InputHandler::handleRotateGesture(float _posX, float _posY, float _radians)
glm::vec2 translation = offset - glm::rotate(offset, _radians);
m_view.translate(translation.x, translation.y);

m_view.roll(_radians);
m_view.yaw(_radians);
}

void InputHandler::handleShoveGesture(float _distance) {
Expand Down
Loading