ios - Scene Kit: projectPoint calculated is displaced -


i trying draw frame on sphere on parent view of scene, reason points converted scnscene.projectpoint method displaced.

to make simple, created sphere @ center of scene 2 radius. sphere attached root node, top left corner on world coordinates @ (-2,-2,0) point.

here complete code:

func spherewithframe(){      var v1 = scnvector3(x: 0,y: 0,z: 0)     var v2 = scnvector3(x: 0,y: 0,z: 0)      let topsphere = scnsphere(radius: 2.0)     topsphere.firstmaterial!.diffuse.contents = uicolor.greencolor()       let topspherenode = scnnode(geometry: topsphere)     topspherenode.position = scnvector3make(0, 0, 0)     scene.rootnode.addchildnode(topspherenode)      topspherenode.getboundingboxmin(&v1, max: &v2)      //world coordinates     let v1w =  topspherenode.convertposition(v1, tonode: scene.rootnode)     let v2w =  topspherenode.convertposition(v2, tonode: scene.rootnode)      //projected coordinates     let v1p = scnview.projectpoint(v1w)     let v2p = scnview.projectpoint(v2w)      //frame rectangle     var rect = cgrectmake(cgfloat(v1p.x), cgfloat(v2p.y), cgfloat(v2p.x - v1p.x), cgfloat(v1p.y - v2p.y))     let rectview = uiview(frame: rect)     rectview.alpha = 0.3     rectview.backgroundcolor = uicolor.bluecolor()     scnview.addsubview(rectview)      println("v1 \(v1.tostring()), v2\(v2.tostring())")     println("v1w \(v1w.tostring()), v2w\(v2w.tostring())")     println("v1p \(v1p.tostring()), v2w\(v2p.tostring())")     println("rect\(rect)")  } 

the console:

v1 x:-2.0,y:-2.0,z:-2.0, v2x:2.0,y:2.0,z:2.0 v1w x:-2.0,y:-2.0,z:-2.0, v2wx:2.0,y:2.0,z:2.0 v1p x:90.718,y:309.282,z:0.925926, v2wx:263.923,y:136.077,z:0.883838 rect(90.718, 136.077, 173.205, 173.205) 

the result on screen rectangle little right should be. the result on screen

i try follow post " how find mouse point in scene using scenekit?". getting wrong?

have set z 0 on both world coordinates:

v1w.z = 0 v2w.z = 0 

explaining things help


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -