0 Replies
      Latest reply on Feb 13, 2020 3:01 PM by rad.bobby
      rad.bobby Level 1 Level 1 (0 points)

        I cannot tell if I have found a bug in simdRotate() or if I simply don't understand pivots very well.  When I have a node and I change the pivot position of that node (or angle), then the routine SCNNode.simdRotate(by: simd_quatf, aroundTarget: simd_float3) doesn't seem to work the way I would expect.  The following mac Playground illustrates my problem/question:

        import SceneKit
        import PlaygroundSupport
        // Make a new SCNView that responds to mouse events
        class TstView: SCNView {
            var cone: SCNNode? = nil
            override func mouseDown(with event: NSEvent) {
                cone?.simdRotate(by: simd_quatf(angle: 0.0, axis: SIMD3<Float>(0.0,1.0,0.0)), aroundTarget: simd_float3(0.0,0.0,0.0))
        // Simple cone
        let geo = SCNCone(topRadius: 3.0, bottomRadius: 0.0, height: 5.0)
        let cone = SCNNode(geometry: geo)
        // Make the pivot point the apex of the cone
        cone.simdPivot = simd_float4x4(SCNMatrix4MakeTranslation(0.0, -2.5, 0.0))
        // make a Sphere to show the 0,0,0 point
        let sphere = SCNSphere(radius: 0.2)
        let centerNode = SCNNode(geometry: sphere)
        let scene = SCNScene()
        // Add my nodes
        // Starting point for the cone
        cone.simdPosition = SIMD3<Float>(-15.0, 0.0, 0.0)
        let view = TstView(frame: CGRect(x: 10.0, y: 10.0, width: 800.0, height: 800.0))
        // Make the cone accessable in TstView
        view.cone = cone
        view.autoenablesDefaultLighting = true
        view.backgroundColor = NSColor.cyan
        view.scene = scene
        // start a live preview of that view
        PlaygroundPage.current.liveView = view


        When you click the moust on the liveView, the cone starts walking forward!?  Even though my angle of rotation is 0.0 radians.  If you comment out line 20. ( the cone.simdPivot = ... line), then it works as I expect.  Am I not understanding something here? Even with a modified pivot, I would think a rotation of 0 shouldn't change anything.  Thanks for your help,