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
,touchesCancelled
for your camera view controller. IntouchesBegan
you will need to makehitTest
for current ARFrame in theUITouch
location. Then you'll have yourstartPosition
and yourlastTouch
, which is your startUITouch
.Then you will need to add timer with
0.016_667
interval (60Hz) which will update your last touch position withhitTest
when you camera moves. Same you'll do intouchesMoved
function. And intouchesMoved
you'll also update yourlastTouch
. So at this point you'll have yourstartPosition
andcurrentPosition
, 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
touchesEnded
you'll fix your line, or iftouchesCancelled
you will remove it and clearlastTouch
.UPD
If you need 2D line on the screen, then you'll need to use
projectPoint
for your ARSceneView.3D line drawing
For drawing 3D line you could
SCNGeometry
use extension:Using: