0
votes

i'm new with Arkit and Xamarin enviroment. I need help about the translation of SCNNode in scene using PanGesture. I have used this guide to start my fist approach with PanGesture. Guide

After that....

I used the help code, but I noticed that, as in the example, when I move an object in the scene it ONLY follows the X, Y axes. In short, if the Cartesian axes of the ARkit scene are framed, with the Z of the camera pointing at the observer, everything works. If the camera position is changed (the phone moves), how can I obtain the translation delta within the 3D space?

if (sender.State == UIGestureRecognizerState.Changed)
        {
            var translate = sender.TranslationInView(areaPanned);

            // Only allow movement vertically or horizontally [OK, but how can i obtain the XYZ value of delta in scene from XY of Viewport?]
            node.LocalTranslate(new SCNVector3((float)translate.X / 10000f, (float)-translate.Y / 10000, 0.0f));
        }

Following the opengl standard I thought of such a solution: [Pseudo code]

scale/offset from 0...1 to -1...1 coordinate space

 var vS = new Coordinate(this.Scene.CurrentViewport.X, this.Scene.CurrentViewport.Y, 1.0);
    var vWH = new Coordinate(this.Scene.CurrentViewport.Width, this.Scene.CurrentViewport.Height, 1.0);
    var scrrenpos = new Coordinate(translate.X, -translate.Y, 1.0);
    var normalized = (scrrenpos - vS) / vWH;

After that i need matrix:

 var inversePM = (projection * modelView).inverse

where:

=> projection from ARCAmera.ProjectionMatrix

=> modelView from ARCamera.Transform

To finish:

var result = normalized * inversePM;

if I set the SCNNode position with this value nothing works :(

Thanks

1

1 Answers

0
votes

Problem solved! here Swift code to translate in c#... works fine!