相关疑难解决方法(0)

如何正确使用iOS(Swift)SceneKit SCNSceneRenderer unprojectPoint

我正在使用iOS上的SceneKit开发一些代码,在我的代码中我想确定全局z平面上的x和y坐标,其中z是0.0,x和y是通过点击手势确定的.我的设置如下:

    override func viewDidLoad() {
    super.viewDidLoad()

    // create a new scene
    let scene = SCNScene()

    // create and add a camera to the scene
    let cameraNode = SCNNode()
    let camera = SCNCamera()
    cameraNode.camera = camera
    scene.rootNode.addChildNode(cameraNode)
    // place the camera
    cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)

    // create and add an ambient light to the scene
    let ambientLightNode = SCNNode()
    ambientLightNode.light = SCNLight()
    ambientLightNode.light.type = SCNLightTypeAmbient
    ambientLightNode.light.color = UIColor.darkGrayColor()
    scene.rootNode.addChildNode(ambientLightNode)

    let triangleNode = SCNNode()
    triangleNode.geometry = defineTriangle();
    scene.rootNode.addChildNode(triangleNode) …
Run Code Online (Sandbox Code Playgroud)

3d ios scenekit swift

17
推荐指数
1
解决办法
8293
查看次数

如何使用SceneKit的unprojectPoint将2D点转换为3D而没有深度值?

是否可以使用SceneKit的unprojectPoint将2D点转换为3D而不具有深度值?我只需要在XZ平面上找到3D位置.Y可以始终为0或任何值,因为我没有使用它.

我正在尝试为iOS 8 Beta做这个.

我有类似于JavaScript和Three.js(WebGL)的东西,如下所示:

function getMouse3D(x, y) {
    var pos = new THREE.Vector3(0, 0, 0);
    var pMouse = new THREE.Vector3(
        (x / renderer.domElement.width) * 2 - 1,
       -(y / renderer.domElement.height) * 2 + 1,
       1
    );
    //
    projector.unprojectVector(pMouse, camera);

    var cam = camera.position;
    var m = pMouse.y / ( pMouse.y - cam.y );

    pos.x = pMouse.x + ( cam.x - pMouse.x ) * m;
    pos.z = pMouse.z + ( cam.z - pMouse.z ) * m;

    return pos; …
Run Code Online (Sandbox Code Playgroud)

3d ios scenekit

5
推荐指数
1
解决办法
3611
查看次数

标签 统计

3d ×2

ios ×2

scenekit ×2

swift ×1