简体   繁体   English

定义 SCNNode 的位置

[英]Define position for SCNNode

I create the SCNBox based on the SCNVector3 .我创建了SCNBox基础上, SCNVector3 But I don't understand the concept of the creation.但我不明白创造的概念。

For 2D rectangle, the x and y represent the rectangle top right corner.对于 2D 矩形, xy表示矩形右上角。 For ARKit 3D SCNBox , what is the x, y and z represent for?对于 ARKit 3D SCNBoxx、yz代表什么? Is that represent the center of the SCNBox ?那是代表SCNBox的中心吗?

When you're setting position of your SCNNode , you're initializating SCNVector3 which describing node's position.当您设置SCNNode位置时,您正在初始化描述节点位置的SCNVector3

You have to define position of node's center point in relation to the position of the parent ( center point is not necessarily in the center of your custom node, but if you have basic nodes with geometry like SCNBox or SCNSphere , center point is in the center)您必须定义节点中心点相对于父节点位置的位置(中心点不一定在自定义节点的中心,但如果您有具有SCNBoxSCNSphere等几何形状的基本节点,中心点在中心)

A simple example can be adding node with geometry SCNBox to rootNode of sceneView 's scene which you get when you in Xcode create new Augmented Reality App .一个简单的例子可以添加带有几何节点SCNBoxrootNodesceneViewscene ,你得到,当你在Xcode中创建新的增强现实应用程序

let cube = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
let material = SCNMaterial()
material.diffuse.contents = UIColor.red
cube.materials = [material]
let node = SCNNode()
node.position = SCNVector3(x: 0, y: 0, z: -0.5)
node.geometry = cube
sceneView.scene.rootNode.addChildNode(node)

在此处输入图片说明

As you can see, to initialize SCNVector3 you have to define x, y and z positions of node's center point .如您所见,要初始化SCNVector3您必须定义节点中心点的x、yz位置。 Note that units are in meters.请注意,单位以米为单位。

I created (very nice) picture with x,y and z axises which should help you to understand how to position your SCNNode :我用x、yz 轴创建了(非常好的)图片,这应该可以帮助您了解如何定位SCNNode

...origin is origin of the node's parent's coordinate system when node is added. ...origin 是添加节点时节点父级坐标系的原点。 Image origin of AR world simplified as position of the center of ARSCNView AR世界的图像原点简化为ARSCNView的中心位置

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM