SCNNode ApplyTorque According To Forces

Assuming X-Axis is up-down; Y-Axis is left-right; Z-Axis is depth. (This seems strange, but has been my experience in ARKit. It just swaps the "normal" X-Axis and Y-Axis.

I have a SCNNode called node1 positioned at (0, 0, 0). It is of rectangular shape with a portrait layout.

The code below allows the node to follow the phone when I call the method lookNode1().

//Method to make node follow the camera when I call it.
@objc func lookNode1() {
    if(self.node1 != nil) {
        //Look at the camera
        self.node1.look(at: self.sceneView.pointOfView!.position)

        //I have to flip it 90 degrees because the node is created in a fancy way that I have to update for. 
        let startingOrientation = GLKQuaternion(self.node1.orientation)
        let node1LookingDirection = self.node1.parentUp
        let node1LookingDirectionInTargetNodesReference = self.node1.convertVector(node1LookingDirection,                                                                    from: self.sceneView.pointOfView?.parent!)

        let rotationAxis = GLKVector3(node1LookingDirectionInTargetNodesReference)

        let quaternion = GLKQuaternion(angle: Float(Double.pi/2), axis: rotationAxis)

        self.node1.orientation = SCNQuaternion((startingOrientation * quaternion).normalized())

extension SCNNode {
    /// The local unit Y axis (0, 1, 0) in parent space.
    var parentUp: SCNVector3 {

        let transform = self.transform
        return SCNVector3(transform.m21, transform.m22, transform.m23)

However, I have a problem that the Z-axis, relative to the phone, not the exact Z-axis, is not right. My question is, Imagine a sphere around node, How can I have it where the top of the rectangle always orients toward the North Pole?

My node1 never moves, it just rotates to follow the camera. But, I need the Z-axis, relative to the camera, is always in portrait mode. No matter if the camera is in landscape portrait, or variation thereof.

Rectangle Celestial Circle


I was thinking of applying some gravity on the A such that it always is on top, i.e., pointing towards the top of the Sphere surrounding the node. However, 1) Not sure how to apply that, and 2) not sure if it will work.

I know we have func applyTorque(_ torque: SCNVector4, asImpulse impulse: Bool) , and I could do self.node1.physicsBody.applyTorque(SCNVector4(0, 0, 1, someRotation), asImpluse: true)) however, I am not sure what that someRotation would be. How would I apply this with a gravity field from the North Pole (1, 0, 0) (being that X is up-down)? I.e., the image above.


0 Answers SCNNode ApplyTorque According To Forces