arkit node sitting to left or right of frustum

I want to put 2d arrows on the edge of the screen that point to a node off screen to show which way to turn the camera so it becomes visible,The node is a real world location represented by a map pin.

I wrote code to find if the node sits to the left or right of the frustum when not visible.


The way i am trying to do it is by getting a camera coordinate for the node, then -X is on left, +X on the right but it doesnt work as expected, any help really appreciated.


var deltaTime = TimeInterval()


public func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
        deltaTime = time - lastUpdateTime
        if deltaTime>1{


            if let annotation = annotationsByNode.first {


                let node = annotation.key.childNodes[0]


                if !renderer.isNode(node, insideFrustumOf: renderer.pointOfView!)
                {
                    print("Pin is not visible");
                }else {
                    print("Pin is visible");
                }
                let pnt = renderer.projectPoint(node.position)


                print("pos ", pnt.x)

                let dir = (isVisible) ? "visible" : ( (pin.x<0) ? "left" : "right")



            }
            lastUpdateTime = time
        }


    }

For a quick glance, there are some illogics in your code. Clearly using negative / positive X is not enough. Suppose two points A, B having positive X and you are looking at point B, if you want to turn your arrow by A, it is always turn to right (because of positive X), regardless A on the left or on the right of B. The situation will be worse when you move out of the origin point (0, 0, 0) and / or turn your device arround.


The correct way IMO:

- find out the direction of the device on 3D world (ARKit world)

- calculate angle between device's direction and the line from your device to that pin

- turn your arrows by above angle


Good luck

Do you have any sample code or psuedo code to achieve the above? I am just starting out in swift and arkit any help is appreciated. Just something that will point me right direction (pun i guess)

In my situation there is only one node A , it always get the first node. So there is no senario with two nodes A and B in my case.

I have just showed you the problem 😉

It means, if A is positive X, even your device looks into right side or left side of A, your arrow always points to the right.


atm I have a near-completed app with complecated code. Controlling direction's arrow is just a small part (you have to solve some harder problems anyways).


Considering to publish some open source btw.

I’m not sure I understand your answer. I’m not rotating an arrow , I am just showing an arrow on left or right of screen that points to a node. I think I need to do some trig that gives me the angle between the direction of the camera and the direction of the node

Did you end up solving this?

arkit node sitting to left or right of frustum
 
 
Q