mapbox / vision-ios-examples

Other
22 stars 9 forks source link

Where to call function present with distance property in ContainerViewController.swift #145

Closed xyzbilal closed 4 years ago

xyzbilal commented 4 years ago

Hi, I m trying to learn your examples and investigating and combining examples ech other to understand the logic. I am copying functions to other project that runs with VisionReplayManager While trying and investigating I stuck at the function that will show distance to object. because I could not find where this function is called and where distance comes from. Can you help me please how to and where to call this function to see distances of objects.

the function I m asking below is in ContainerViewController.swift

private func present(distance: Double, objectFrame frame: CGRect, canvasSize: CGSize) {
        distanceView.isHidden = false
        distanceLabel.isHidden = false

        let left = CGPoint(x: frame.minX, y: frame.maxY).convertForAspectRatioFill(from: canvasSize, to: view.bounds.size)
        let right = CGPoint(x: frame.maxX, y: frame.maxY).convertForAspectRatioFill(from: canvasSize, to: view.bounds.size)

        distanceView.update(left, right)
        distanceLabel.text = distanceFormatter.string(fromMeters: distance)
    }
chezzdev commented 4 years ago

Hey, @xyzbilal. If you'd like to know the distance to cars in front of you, I'd recommend using [WorldDescription]() object that you can retrieve from the appropriate method of VisionManagerDelegate. From the position of a particular WorldObject you can calculate the distance to that object.

If you still need to estimate the distance by converting from screen to world space, please check out our POI rendering tutorial which explains the concept of different coordinate systems and how to convert between them.

chezzdev commented 4 years ago

Closing the issue as stale. Feel free to reopen it or create a new issue with your feedback.