Arigarasuthan
Arigarasuthan

Reputation: 373

How to place a 3d object center position of the camera in ar-core?

I have working and analysing sample hello_ar_java project in android.I want to place a 3d object in a center position of the camera in android.i'm expecting answers android only and i dont want unity answes because i don't know unity.

Upvotes: 0

Views: 2325

Answers (3)

preswa
preswa

Reputation: 11

To place the object in the camera position,

`Frame frame = arSceneView.getArFrame();
float x = frame.getCamera().getPose().qx() ;
float y = frame.getCamera().getPose().qy();
float z = frame.getCamera().getPose().qz() ;
Node andy = new Node();
andy.setParent(arSceneView.getScene().getCamera());
andy.setLocalPosition(new Vector3(position.x, position.y, position.z));
andy.setRenderable(arrowRenderable); // your rendebrable object name`


or instead of `andy.setLocalPosition(new Vector3(position.x, position.y, position.z));`

just give 
`andy.setLocalPosition(new Vector3(0f,0,-1f)); // it will place the object in center camera`

Upvotes: 1

Teja Konjeti
Teja Konjeti

Reputation: 343

The point the camera starts is THE origin. So, just place your object at the origin, and everything should be fine. If you want the object to move with the camera, you should have the camera's transform as the parent of your object's transform.

Upvotes: 0

nerk
nerk

Reputation: 602

I can't help you with the java code, but I have done this in Unity and I imagine the concept is the same. What you want to do is create a point in space (a Vector3) that is always in front of the camera. This point will move with the camera and always be in front of it. Then, you want to spawn (instantiate) your object(s) at that Vector3. Let me know if that helps.

Upvotes: 0

Related Questions