How to use iOS (Swift) SceneKit SCNSceneRenderer unprojectPoint properly

Typical depth buffers in a 3D graphics pipeline are not linear. Perspective division causes depths in normalized device coordinates to be on a different scale. (See also here.) So the z-coordinate you’re feeding into unprojectPoint isn’t actually the one you want. How, then, to find the normalized-depth coordinate matching a plane in world space? Well, … Read more

Converting 3D position to 2d screen position [r69!]

I’ve written for my project the following function; it receives an THREE.Object3D instance and a camera as a parameters and returns the position on the screen. function toScreenPosition(obj, camera) { var vector = new THREE.Vector3(); var widthHalf = 0.5*renderer.context.canvas.width; var heightHalf = 0.5*renderer.context.canvas.height; obj.updateMatrixWorld(); vector.setFromMatrixPosition(obj.matrixWorld); vector.project(camera); vector.x = ( vector.x * widthHalf ) + widthHalf; … Read more

Three.js – Orthographic camera

The pattern for instantiating an orthographic camera in three.js is: var camera = new THREE.OrthographicCamera( width / – 2, width / 2, height / 2, height / – 2, near, far ); where width and height are the width and height of the camera’s cuboid-shaped frustum measured in world-space units. near and far are the … Read more