protected void SpawnObject(SceneARWorldObject worldObject, Camera worldCamera, Transform worldAnchor)
        {
            var gameObj = worldObject.GameObject;

            AttachGameObject(gameObj, worldAnchor);

            SetSpawnPosition(worldObject, worldCamera, worldAnchor);
        }
        public double GetDistance(SceneARWorldObject worldObject)
        {
            if (worldObject.GameObject != null)
            {
                var cam = GetCameraForObject(worldObject);

                return((worldObject.GameObject.transform.position -
                        cam.transform.position).magnitude);
            }

            return(0);
        }
 public virtual Camera GetCameraForObject(SceneARWorldObject worldObj)
 {
     return(GetCamera());
 }
 public void AddWorldObject(SceneARWorldObject worldObject)
 {
     m_sceneObjects.Add(worldObject, new SceneWorldObjectState(worldObject));
 }
 /// <summary>
 /// TODO: refactor this
 /// </summary>
 /// <param name="worldObject"></param>
 public void RemoveWorldObject(SceneARWorldObject worldObject)
 {
     m_sceneObjects.Remove(worldObject);
 }
 public SceneWorldObjectState(SceneARWorldObject worldObject)
 {
     WorldObject = worldObject;
 }
        /*
         * protected double GetWorldHeading(Transform anchor, Transform objTransform)
         * {
         *  var fwd = GetTransformForward(anchor, objTransform);
         *
         *  var z = Vector3.Dot(fwd, Vector3.forward);
         *
         *  return Math.Acos(z) * 180 / Math.PI;
         * }*/

        protected virtual void SetSpawnPosition(SceneARWorldObject worldObject, Camera worldCamera, Transform worldAnchor)
        {
            var gameObj = worldObject.GameObject;

            gameObj.transform.localScale    = Vector3.one;
            gameObj.transform.localRotation = Quaternion.identity;

            if (worldObject.Position is RelativeWorldPosition)
            {
                var relPos = worldObject.Position as RelativeWorldPosition;

                if (worldObject.AnchorObject != null)
                {
                    var y = (float)relPos.Elevation;
                    var x = (float)(relPos.Distance * Math.Sin(relPos.Angle));
                    var z = (float)(relPos.Distance * Math.Cos(relPos.Angle));

                    var offset = new Vector3(x, y, z);

                    var objPos = worldObject.AnchorObject.GameObject.transform.position + offset;

                    var cam = ARWorld.Instance.GetWorldObjectCamera(worldObject.AnchorObject);

                    var camRel = objPos - cam.transform.position;

                    objPos = worldCamera.transform.position + camRel;

                    //var anchorCamHdg = GetWorldHeading(cam.transform);

                    gameObj.transform.rotation = worldObject.GameObject.transform.rotation;
                    gameObj.transform.position = objPos;
                }
                else
                {
                    var hdg = GetWorldHeading(worldCamera.transform);

                    var angle  = hdg + relPos.Angle;
                    var rangle = angle * Mathf.Deg2Rad;

                    m_logger.Debug("Using relative position with angle={0} and cam hdg={1}",
                                   relPos.Angle, hdg);

                    var y = (float)relPos.Elevation;
                    var x = (float)(relPos.Distance * Math.Sin(rangle));
                    var z = (float)(relPos.Distance * Math.Cos(rangle));

                    var spawnPos = worldCamera.transform.position + new Vector3(x, y, z);

                    gameObj.transform.rotation = Quaternion.AngleAxis((float)angle, Vector3.up);

                    gameObj.transform.position = spawnPos;
                }
            }
            else if (worldObject.Position is FixedWorldPosition)
            {
                var fixPos = worldObject.Position as FixedWorldPosition;

                var y = (float)fixPos.Position.Y;
                var x = (float)fixPos.Position.X;
                var z = (float)fixPos.Position.Z;

                var spawnPos = new Vector3(x, y, z);

                gameObj.transform.localPosition = spawnPos;
            }
        }