Tushar Kumar Rai
Tushar Kumar Rai

Reputation: 33

Can lines be drawn in ARcore without touching the screen?

I have to draw an app similar to Just A Line AR App but in my app,lines should be rendered as camera position is changed and should not require tapping/holding on the screen. How can it be achieved?

Upvotes: 0

Views: 545

Answers (1)

Mick
Mick

Reputation: 25491

I assume you mean you want your line to be anchored in the scene - i.e. the points on the line follow the centre of the camera view as you move the device around.

Assuming this you can:

  • at the start place an anchor some distance in front of the center of the camera, for example 1M in front.
  • scheduled a job to repeat at some interval, e.g. 500ms and:
  • place a new anchor, again 1M in front of the camera
  • add the new anchor to a collection or list of anchors
  • draw a line between the previous anchor and the current anchor in the list

This code will place an anchor in front of the camera:

//Add an Anchor and a renderable in front of the camera       
Session session = arFragment.getArSceneView().getSession();
float[] pos = { 0, 0, -1 };
float[] rotation = { 0, 0, 0, 1 };
Anchor anchor =  session.createAnchor(new Pose(pos, rotation));
anchorNode = new AnchorNode(anchor);
anchorNode.setRenderable(andyRenderable);
anchorNode.setParent(arFragment.getArSceneView().getScene());

Upvotes: 1

Related Questions