fix symbol collision detection in perspective view
This commit is contained in:
@@ -27,7 +27,7 @@ LiveTileData::LiveTileData(const TileID& id_,
|
||||
state,
|
||||
std::make_unique<CollisionTile>(id_.z, 4096,
|
||||
source_.tile_size * id.overscaling,
|
||||
0, false)) {
|
||||
0, 0, false)) {
|
||||
state = State::loaded;
|
||||
|
||||
if (!tile) {
|
||||
|
||||
@@ -284,8 +284,8 @@ TileData::State Source::addTile(MapData& data,
|
||||
|
||||
// If we don't find working tile data, we're just going to load it.
|
||||
if (info.type == SourceType::Vector) {
|
||||
auto tileData = std::make_shared<VectorTileData>(normalized_id, style, info,
|
||||
transformState.getAngle(), data.getCollisionDebug());
|
||||
auto tileData = std::make_shared<VectorTileData>(normalized_id, style, info,
|
||||
transformState.getAngle(), transformState.getPitch(), data.getCollisionDebug());
|
||||
tileData->request(data.pixelRatio, callback);
|
||||
new_tile.data = tileData;
|
||||
} else if (info.type == SourceType::Raster) {
|
||||
@@ -506,7 +506,7 @@ bool Source::update(MapData& data,
|
||||
updateTilePtrs();
|
||||
|
||||
for (auto& tilePtr : tilePtrs) {
|
||||
tilePtr->data->redoPlacement(transformState.getAngle(), data.getCollisionDebug());
|
||||
tilePtr->data->redoPlacement(transformState.getAngle(), transformState.getPitch(), data.getCollisionDebug());
|
||||
}
|
||||
|
||||
updated = data.getAnimationTime();
|
||||
@@ -568,7 +568,7 @@ void Source::tileLoadingCompleteCallback(const TileID& normalized_id, const Tran
|
||||
return;
|
||||
}
|
||||
|
||||
data->redoPlacement(transformState.getAngle(), collisionDebug);
|
||||
data->redoPlacement(transformState.getAngle(), transformState.getPitch(), collisionDebug);
|
||||
emitTileLoaded(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
|
||||
virtual Bucket* getBucket(const StyleLayer&) = 0;
|
||||
|
||||
virtual void redoPlacement(float, bool) {}
|
||||
virtual void redoPlacement(float, float, bool) {}
|
||||
|
||||
bool isReady() const {
|
||||
return isReadyState(state);
|
||||
|
||||
@@ -55,8 +55,8 @@ TileParseResult TileWorker::parse(const GeometryTile& geometryTile) {
|
||||
return partialParse ? TileData::State::partial : TileData::State::parsed;
|
||||
}
|
||||
|
||||
void TileWorker::redoPlacement(float angle, bool collisionDebug) {
|
||||
collision->reset(angle, 0);
|
||||
void TileWorker::redoPlacement(float angle, float pitch, bool collisionDebug) {
|
||||
collision->reset(angle, pitch);
|
||||
collision->setDebug(collisionDebug);
|
||||
for (auto i = layers.rbegin(); i != layers.rend(); i++) {
|
||||
auto bucket = getBucket(**i);
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
Bucket* getBucket(const StyleLayer&) const;
|
||||
|
||||
TileParseResult parse(const GeometryTile&);
|
||||
void redoPlacement(float angle, bool collisionDebug);
|
||||
void redoPlacement(float angle, float pitch, bool collisionDebug);
|
||||
|
||||
std::vector<util::ptr<StyleLayer>> layers;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ VectorTileData::VectorTileData(const TileID& id_,
|
||||
Style& style_,
|
||||
const SourceInfo& source_,
|
||||
float angle,
|
||||
float pitch,
|
||||
bool collisionDebug)
|
||||
: TileData(id_),
|
||||
worker(style_.workers),
|
||||
@@ -27,7 +28,7 @@ VectorTileData::VectorTileData(const TileID& id_,
|
||||
state,
|
||||
std::make_unique<CollisionTile>(id_.z, 4096,
|
||||
source_.tile_size * id.overscaling,
|
||||
angle, collisionDebug)),
|
||||
angle, pitch, collisionDebug)),
|
||||
source(source_),
|
||||
lastAngle(angle),
|
||||
currentAngle(angle) {
|
||||
@@ -98,11 +99,14 @@ Bucket* VectorTileData::getBucket(const StyleLayer& layer) {
|
||||
return tileWorker.getBucket(layer);
|
||||
}
|
||||
|
||||
void VectorTileData::redoPlacement(float angle, bool collisionDebug) {
|
||||
if (angle == currentAngle && collisionDebug == currentCollisionDebug)
|
||||
void VectorTileData::redoPlacement(float angle, float pitch, bool collisionDebug) {
|
||||
if (angle == currentAngle &&
|
||||
pitch == currentPitch &&
|
||||
collisionDebug == currentCollisionDebug)
|
||||
return;
|
||||
|
||||
lastAngle = angle;
|
||||
lastPitch = pitch;
|
||||
lastCollisionDebug = collisionDebug;
|
||||
|
||||
if (state != State::parsed || redoingPlacement)
|
||||
@@ -110,9 +114,10 @@ void VectorTileData::redoPlacement(float angle, bool collisionDebug) {
|
||||
|
||||
redoingPlacement = true;
|
||||
currentAngle = angle;
|
||||
currentPitch = pitch;
|
||||
currentCollisionDebug = collisionDebug;
|
||||
|
||||
workRequest = worker.redoPlacement(tileWorker, angle, collisionDebug, [this] {
|
||||
workRequest = worker.redoPlacement(tileWorker, angle, pitch, collisionDebug, [this] {
|
||||
for (const auto& layer : tileWorker.layers) {
|
||||
auto bucket = getBucket(*layer);
|
||||
if (bucket) {
|
||||
@@ -120,7 +125,7 @@ void VectorTileData::redoPlacement(float angle, bool collisionDebug) {
|
||||
}
|
||||
}
|
||||
redoingPlacement = false;
|
||||
redoPlacement(lastAngle, lastCollisionDebug);
|
||||
redoPlacement(lastAngle, lastPitch, lastCollisionDebug);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
Style&,
|
||||
const SourceInfo&,
|
||||
float angle_,
|
||||
float pitch_,
|
||||
bool collisionDebug_);
|
||||
~VectorTileData();
|
||||
|
||||
@@ -29,7 +30,7 @@ public:
|
||||
|
||||
bool reparse(std::function<void ()> callback);
|
||||
|
||||
void redoPlacement(float angle, bool collisionDebug) override;
|
||||
void redoPlacement(float angle, float pitch, bool collisionDebug) override;
|
||||
|
||||
void cancel() override;
|
||||
|
||||
@@ -43,6 +44,8 @@ private:
|
||||
std::string data;
|
||||
float lastAngle = 0;
|
||||
float currentAngle;
|
||||
float lastPitch = 0;
|
||||
float currentPitch;
|
||||
bool lastCollisionDebug = 0;
|
||||
bool currentCollisionDebug = 0;
|
||||
bool redoingPlacement = false;
|
||||
|
||||
@@ -511,7 +511,7 @@ void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
|
||||
|
||||
void SymbolBucket::addToDebugBuffers() {
|
||||
|
||||
const float yStretch = 1.0f;
|
||||
const float yStretch = collision.yStretch;
|
||||
const float angle = collision.angle;
|
||||
const float zoom = collision.zoom;
|
||||
float angle_sin = std::sin(-angle);
|
||||
|
||||
@@ -13,7 +13,7 @@ void CollisionTile::reset(const float _angle, const float pitch) {
|
||||
rotationMatrix = {{angle_cos, -angle_sin, angle_sin, angle_cos}};
|
||||
|
||||
// Stretch boxes in y direction to account for the map tilt.
|
||||
const float _yStretch = 1.0f / std::cos(pitch / 180 * M_PI);
|
||||
const float _yStretch = 1.0f / std::cos(pitch);
|
||||
|
||||
// The amount the map is squished depends on the y position.
|
||||
// Sort of account for this by making all boxes a bit bigger.
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace mbgl {
|
||||
class CollisionTile {
|
||||
|
||||
public:
|
||||
inline explicit CollisionTile(float _zoom, float tileExtent, float tileSize, float angle_, bool debug_) :
|
||||
zoom(_zoom), tilePixelRatio(tileExtent / tileSize), debug(debug_) { reset(angle_, 0); }
|
||||
inline explicit CollisionTile(float _zoom, float tileExtent, float tileSize, float angle_, float pitch_, bool debug_) :
|
||||
zoom(_zoom), tilePixelRatio(tileExtent / tileSize), debug(debug_) { reset(angle_, pitch_); }
|
||||
|
||||
void reset(const float angle, const float pitch);
|
||||
float placeFeature(const CollisionFeature &feature);
|
||||
@@ -51,6 +51,7 @@ class CollisionTile {
|
||||
|
||||
const float minScale = 0.5f;
|
||||
const float maxScale = 2.0f;
|
||||
float yStretch;
|
||||
|
||||
private:
|
||||
|
||||
@@ -58,7 +59,6 @@ class CollisionTile {
|
||||
|
||||
Tree tree;
|
||||
std::array<float, 4> rotationMatrix;
|
||||
float yStretch;
|
||||
bool debug;
|
||||
|
||||
};
|
||||
|
||||
@@ -46,8 +46,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void redoPlacement(TileWorker* worker, float angle, bool collisionDebug, std::function<void ()> callback) {
|
||||
worker->redoPlacement(angle, collisionDebug);
|
||||
void redoPlacement(TileWorker* worker, float angle, float pitch, bool collisionDebug, std::function<void ()> callback) {
|
||||
worker->redoPlacement(angle, pitch, collisionDebug);
|
||||
callback();
|
||||
}
|
||||
};
|
||||
@@ -76,9 +76,9 @@ std::unique_ptr<WorkRequest> Worker::parseLiveTile(TileWorker& worker, const Liv
|
||||
return threads[current]->invokeWithCallback(&Worker::Impl::parseLiveTile, callback, &worker, &tile);
|
||||
}
|
||||
|
||||
std::unique_ptr<WorkRequest> Worker::redoPlacement(TileWorker& worker, float angle, bool collisionDebug, std::function<void ()> callback) {
|
||||
std::unique_ptr<WorkRequest> Worker::redoPlacement(TileWorker& worker, float angle, float pitch, bool collisionDebug, std::function<void ()> callback) {
|
||||
current = (current + 1) % threads.size();
|
||||
return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, callback, &worker, angle, collisionDebug);
|
||||
return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, callback, &worker, angle, pitch, collisionDebug);
|
||||
}
|
||||
|
||||
} // end namespace mbgl
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
Request redoPlacement(
|
||||
TileWorker&,
|
||||
float angle,
|
||||
float pitch,
|
||||
bool collisionDebug,
|
||||
std::function<void ()> callback);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user