使用CGMutablePath创建路径会创建指向错误CGPoint的行 [英] Creating path using CGMutablePath creates line to wrong CGPoint

查看:83
本文介绍了使用CGMutablePath创建路径会创建指向错误CGPoint的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算在屏幕上用2D箭头显示AR对象的信息.所以我用projectPoint来获取对象在屏幕上的对应位置.我具有此功能,可以将节点的3D位置转换为2D,然后将CGPoint转换为显示信息文本.

I was planning to display information of AR object in screen with arrow in 2D. So I used projectPoint to get corresponding position of object in screen. I have this function to return convert 3D position of node to 2D and CGPoint to display info text in.

func getPoint(sceneView: ARSCNView) -> (CGPoint, CGPoint){
    let projectedPoint = sceneView.projectPoint(node.worldPosition)
    return (point, CGPoint(x: CGFloat(projectedPoint.x), y: CGFloat(projectedPoint.y)) )
}

并使用SpriteKit画线:

let (f,s) = parts[3].getPoint(sceneView: sceneView) 
line.removeFromParent()
let path = CGMutablePath()
path.move(to: f)
path.addLine(to: s)
line = SKShapeNode(path: path)
spriteScene.addChild(line)

这就是我得到的

我期望在节点(蓝色网格)中固定另一条线.
我缺少什么吗?还是projectPoint以其他方式起作用?

What I expect is another end of line to be fixed in node (blue mesh).
Is there something I am missing? Or does projectPoint works some other way?

似乎projectPoint返回正确的值,但是在创建路径path.addLine(to: s)时,此点移到了不同​​的位置.

edit: It seems projectPoint is returning correct value but while creating path path.addLine(to: s) this point is shifting to different position.

推荐答案

path.addLine(to: s)此处的y颠倒了,所以可以解决问题

path.addLine(to: s) s here had reversed y so this did the trick

let frame = self.sceneView.frame
let sInversed = CGPoint(x: from.x, y: frame.height - s.y)

path.addLine(to: sInversed)

SKScene的起源在屏幕的左下角而不是左上角.

Here origin of SKScene was in bottom left of screen instead of top left.

这篇关于使用CGMutablePath创建路径会创建指向错误CGPoint的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆