使用 CGMutablePath 创建路径会创建到错误 CGPoint 的行

编程入门 行业动态 更新时间:2024-10-15 10:15:24
本文介绍了使用 CGMutablePath 创建路径会创建到错误 CGPoint 的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我打算用二维箭头在屏幕上显示 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?

edit:似乎 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) 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 的行

本文发布于:2023-11-24 12:44:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   错误   CGMutablePath   CGPoint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!