添加" SCNNode"到ScreenView到相机的当前视图

时间:2017-10-20 04:39:56

标签: ios xamarin.ios arkit scnnode arscnview

我有一个图像,我试图添加到Screenview ARSCNView会话的当前相机位置。无论我做什么,它似乎把图像放在手机摄像头的当前位置后面,我必须将它移回去看它。我有以下代码:

var currentFrame = SceneView.Session.CurrentFrame;

if (currentFrame == null) return;

var threeVector = new SCNVector3(currentFrame.Camera.Transform.Column3.X + 0.005f, 
       currentFrame.Camera.Transform.Column3.Y - 0.02f, 
       currentFrame.Camera.Transform.Column3.Z - 0.05f);

var scaleFactor = imgToAdd.Size.Width / 0.05;
float width = float.Parse((imgToAdd.Size.Width / scaleFactor).ToString());
float height = float.Parse((imgToAdd.Size.Height / scaleFactor).ToString());

var box = new SCNPlane {
    Width = width,
    Height = height
};

var cubeNode = new SCNNode {
    Position = threeVector,
    Geometry = box
};
var mat = new SCNMaterial();
mat.Diffuse.Contents = imgToAdd;
mat.LocksAmbientWithDiffuse = true;
cubeNode.Geometry.Materials = new[] { mat };
SceneView.Scene.RootNode.AddChildNode(cubeNode);

只是尝试执行您现在在应用商店中看到的ARKit绘制应用的简单概念。所以imgToAdd是用户已经放到屏幕上的涂鸦的快照,并且在从潦草的视图创建图像之后,该事件被触发了。

我需要改变什么才能让它与手机上相机的当前视图对齐?

0 个答案:

没有答案
相关问题