As always I need your help. I need to draw a straight line from a start value (declared as SCNVector3) and connected to the position in the real world till the end point.
Can someone explain to me with some lines of code how can I do it? Thank you!
You'll need to implement:
touchesBegan,touchesMoved,touchesEnded,touchesCancelledfor your camera view controller. IntouchesBeganyou will need to makehitTestfor current ARFrame in theUITouchlocation. Then you'll have yourstartPositionand yourlastTouch, which is your startUITouch.Then you will need to add timer with
0.016_667interval (60Hz) which will update your last touch position withhitTestwhen you camera moves. Same you'll do intouchesMovedfunction. And intouchesMovedyou'll also update yourlastTouch. So at this point you'll have yourstartPositionandcurrentPosition, which isSCNVector3. And you can just redraw SCNCylinder (with 0.001m radius for example) for those positions if you need straight line.At last step in
touchesEndedyou'll fix your line, or iftouchesCancelledyou will remove it and clearlastTouch.UPD
If you need 2D line on the screen, then you'll need to use
projectPointfor your ARSceneView.3D line drawing
For drawing 3D line you could
SCNGeometryuse extension:Using: