Placing Virtual Content
Use the following information to understand how to place and orient virtual content in a Shared AR experience.
Peer Poses
In an ARNetworking
session, all peers begin in their own coordinate systems, where the origin (0,0,0) is located where their device was when the ARSession
started running. Upon reaching stability, a peer’s pose will snap to be in the host’s coordinate system.
By default, all stable peers will broadcast their pose to all other peers. Pose broadcasting can be configured based on your application’s requirements.
using Niantic.ARDK.AR.Networking; IARNetworking arNetworking; // To enable arNetworking.EnablePoseBroadcasting(); // To disable arNetworking.DisablePoseBroadcasting(); // To configure how often poses are broadcast arNetworking.SetTargetPoseLatency(latency);
The latest available pose of each peer can be retrieved through the IARNetworking interface.
var allPeerPoses = arNetworking.LatestPeerPoses; var myPeerPose = arNetworking.ARSession.CurrentFrame.Camera.Transform;
Alternatively, peer pose updates, including those for the local device, can be subscribed to.
using Niantic.ARDK.Utilities; IARNetworking _arNetworking; Dictionary<IPeer, GameObject> _peerGameObjects; void SubscribeToPeerStateUpdates() { _arNetworking.PeerPoseReceived += OnPeerPoseReceived; } void OnPeerPoseReceived(PeerPoseReceivedArgs args) { var peer = args.Peer; var pose = args.Pose; // Use this information to attach a GameObject to a player, // have in-game characters look at a player, have an AI // shoot at a player, etc. var peerGameObject = _peerGameObjects[peer]; peerGameObject.transform.position = pose.ToPosition(); peerGameObject.transform.rotation = pose.ToRotation(); }