Skip to content

Commit

Permalink
Merge pull request mapbox#12 from pot2mayo/seung/add-anchor-distance
Browse files Browse the repository at this point in the history
Seung/add anchor distance
  • Loading branch information
pot2mayo authored Oct 2, 2019
2 parents 3721b27 + 484d940 commit 24908bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
17 changes: 5 additions & 12 deletions MapboxARKit/AnnotationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ open class AnnotationManager: NSObject {
public private(set) var annotationsByNode = [SCNNode: Annotation]()
public var delegate: AnnotationManagerDelegate?
public var originLocation: CLLocation?
private var nodesAddedDirectlyByAnchor: [ARAnchor: SCNNode] = [:]

public init(session: ARSession) {
self.session = session
Expand Down Expand Up @@ -112,15 +111,13 @@ open class AnnotationManager: NSObject {
}
}

public func addNodeDirectly(nodeToAdd: SCNNode, anchor: ARAnchor) {
nodesAddedDirectlyByAnchor[anchor] = nodeToAdd
session?.add(anchor: anchor)
public func setAnchorDistance(max: Float?, min: Float?) {
if max != nil { MBARAnchor.ANCHOR_DISTANCE_MAX = max! }
if min != nil { MBARAnchor.ANCHOR_DISTANCE_MIN = min! }
}

public func removeDirectlyAddedNodes() {
for (key, _) in nodesAddedDirectlyByAnchor {
session?.remove(anchor: key)
}
public func getAnchorDistance() -> (max: Float, min: Float) {
return (max: MBARAnchor.ANCHOR_DISTANCE_MAX, min: MBARAnchor.ANCHOR_DISTANCE_MIN)
}
}

Expand Down Expand Up @@ -152,10 +149,6 @@ extension AnnotationManager: ARSCNViewDelegate {

node.addChildNode(newNode)
annotationsByNode[newNode] = annotation
} else {
if nodesAddedDirectlyByAnchor.isEmpty == false && nodesAddedDirectlyByAnchor[anchor] != nil {
node.addChildNode(nodesAddedDirectlyByAnchor[anchor]!)
}
}

// TODO: let delegate provide a node for a non-MBARAnchor
Expand Down
12 changes: 7 additions & 5 deletions MapboxARKit/MBARAnchor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import Turf

public class MBARAnchor: ARAnchor {

public var calloutString: String?
// To controll the max & min size of the node
public static var ANCHOR_DISTANCE_MAX:Float = 300
public static var ANCHOR_DISTANCE_MIN:Float = 50

public convenience init(originLocation: CLLocation, location: CLLocation) {
let transform = matrix_identity_float4x4.transformMatrix(originLocation: originLocation, location: location)
Expand All @@ -22,12 +24,12 @@ internal extension simd_float4x4 {
var distance = Float(location.distance(from: originLocation))

// Workaround to set the minum size of the node. Enforce the distance if distance is over than 200m
if distance > 300 {
distance = 300
if distance > MBARAnchor.ANCHOR_DISTANCE_MAX {
distance = MBARAnchor.ANCHOR_DISTANCE_MAX
}

if distance < 50 {
distance = 50
if distance < MBARAnchor.ANCHOR_DISTANCE_MIN {
distance = MBARAnchor.ANCHOR_DISTANCE_MIN
}

let bearing = GLKMathDegreesToRadians(Float(originLocation.coordinate.direction(to: location.coordinate)))
Expand Down

0 comments on commit 24908bb

Please sign in to comment.