SceneKit: how can I place a 3D object from a 2D line?

Scene: I have two lines that are parallel to each other (in 2D) drawn on a UIImageView using UIBezierPath. Then I added a SceneView above the UIImageview to display my 3D object. Now I need to position my 3D object (which I created with SketchUp [.dae file]) according to the lines drawn using UIBezierPath and this must be done programmatically.

I am having trouble finding the correct formula for SceneNode position, rotation, eulerAngles, transform or rotation. Because I think these attributes should be calculated based on my strings.

I can convert 2D x, y coordinates to 3D coordinates using the max and min Bounding Box 3D object.

SCNVector3 min = SCNVector3Zero;
SCNVector3 max = SCNVector3Zero;
[mySceneView.scene.rootNode getBoundingBoxMin:&min max:&max];

float x = (pointA.x / CGRectGetMaxX(self.imageView.frame)) * max.x;
float y = ((CGRectGetMaxY(self.imageView.frame) - (CGRectGetMaxY(self.imageView.frame) - pointA.y)) / CGRectGetMaxY(self.imageView.frame)) * max.y;

      

However, I am having a hard time finding the z axis.

Here is my current output. enter image description here

and my expected output should be like this.

enter image description here

+3


source to share





All Articles