private IOrientationManager SetUp()
        {
            var orientations = new Dictionary <string, IOrientation>();


            var north = new PlutoRover.Orientation("N");
            var east  = new PlutoRover.Orientation("E");
            var west  = new PlutoRover.Orientation("W");
            var south = new PlutoRover.Orientation("S");

            north.Left  = west;
            north.Right = east;

            east.Left  = north;
            east.Right = south;

            south.Left  = east;
            south.Right = west;

            west.Left  = south;
            west.Right = north;

            orientations.Add(north.Name, north);
            orientations.Add(east.Name, east);
            orientations.Add(west.Name, west);
            orientations.Add(south.Name, south);

            IOrientationManager orientationManager = new OrientationManager(north, orientations);

            return(orientationManager);
        }
    void Start()
    {
        gameObject.AddComponent("OrientationManager");
        orientationManager = gameObject.GetComponent<OrientationManager>();
        CoherentUISystem system = Object.FindObjectOfType(typeof (CoherentUISystem)) as CoherentUISystem;
        if (system != null)
        {
            if (system.camera == null)
                system.m_MainCamera = GameObject.FindGameObjectWithTag("MainCamera").camera;
        }

        _view = this.GetComponent<CoherentUIView>();
        _view.OnViewCreated += new UnityViewListener.CoherentUI_OnViewCreated(this.OnViewReady);

        _view.Listener.ReadyForBindings += (frameId, path, isMainFrame) =>
        {
            _view.View.BindCall("GoToDestination", (System.Action<string>)GoToDestination);
            _view.View.BindCall("IsFacebookSignedIn", (System.Action)IsFacebookSignedIn);
            _view.View.BindCall("FacebookSignOut", (System.Action)FacebookSignOut);
            _view.View.BindCall("StoreFacebook", (System.Action<string, string, string, string>)StoreFacebook);
            _view.View.BindCall("GetInvitationCount", (System.Action)GetInvitationCount);
        };

        _view.OnViewCreated += (view) => view.InterceptURLRequests(true);
        _view.Listener.URLRequest += OnURLRequestHandler;

        LocalAppURL = _view.Page;

        _userManager = Object.FindObjectOfType(typeof(UserManager)) as UserManager;
        _viewReady = false;
    }
        public void CoordToWorldMapping()
        {
            OrientationManager.SetOrientation(Orientation.North);

            Vector2Int coord1 = new Vector2Int(74, -23);
            Vector2Int coord2 = new Vector2Int(-33, 13);
            Vector2Int coord3 = new Vector2Int(93, 0);

            Vector2 expectedWorldPos1 = new Vector2(
                -98 * Settings.TILE_WIDTH_HALF,
                -51 * Settings.TILE_HEIGHT_HALF);

            Assert.AreEqual(TileTransformer.CoordToWorld(coord1), expectedWorldPos1);
            Assert.AreEqual(TileTransformer.CoordToWorld(coord1.x, coord1.y), expectedWorldPos1);
            Assert.AreEqual(TileTransformer.CoordToWorld((float)coord1.x, (float)coord1.y), expectedWorldPos1);

            Vector2 expectedWorldPos2 = new Vector2(
                45 * Settings.TILE_WIDTH_HALF,
                20 * Settings.TILE_HEIGHT_HALF);

            Assert.AreEqual(TileTransformer.CoordToWorld(coord2), expectedWorldPos2);
            Assert.AreEqual(TileTransformer.CoordToWorld(coord2.x, coord2.y), expectedWorldPos2);
            Assert.AreEqual(TileTransformer.CoordToWorld((float)coord2.x, (float)coord2.y), expectedWorldPos2);

            Vector2 expectedWorldPos3 = new Vector2(
                -94 * Settings.TILE_WIDTH_HALF,
                -93 * Settings.TILE_HEIGHT_HALF);

            Assert.AreEqual(TileTransformer.CoordToWorld(coord3), expectedWorldPos3);
            Assert.AreEqual(TileTransformer.CoordToWorld(coord3.x, coord3.y), expectedWorldPos3);
            Assert.AreEqual(TileTransformer.CoordToWorld((float)coord3.x, (float)coord3.y), expectedWorldPos3);
        }
        public TileSpriteObserver()
        {
            tileHolder = new GameObject("Tiles");

            gameobjects = new Dictionary <ITile, GameObject> ();

            OrientationManager.RegisterObserver(this);
        }
 public void OnApplicationQuit()
 {
     if (subscribedToOrientationManager)
     {
         OrientationManager.UnregisterObserver(this);
         subscribedToOrientationManager = false;
     }
 }
    void Awake()
    {
        s_instance = FindObjectOfType(typeof(OrientationManager)) as OrientationManager;

        SetLockRotation(true);

        OrientationChanged();
    }
Exemple #7
0
        public FurnitureSpriteObserver()
        {
            furnitureHolder = new GameObject("Furniture");

            gameobjects = new Dictionary <ITile, GameObject>();

            OrientationManager.RegisterObserver(this);
        }
        public WallSpriteObserver()
        {
            wallHolder = new GameObject("Walls");

            gameobjects = new Dictionary <IWall, GameObject> ();

            OrientationManager.RegisterObserver(this);

            deferredCaller = GameObject.FindObjectOfType <DeferredCaller>();
        }
Exemple #9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.AddDefaultEventPic);
                Toolbar  toolbar       = (Toolbar)FindViewById(Resource.Id.toolbar);
                TextView toolbar_title = (TextView)this.FindViewById(Resource.Id.toolbar_title);
                SetSupportActionBar(toolbar);
                SupportActionBar.Title = "";
                toolbar_title.Text     = "Take a picture";
                orientationManager     = new OrientationManager(this, SensorDelay.Normal, this);
                if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
                {
                    Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                    Window.SetStatusBarColor(new Android.Graphics.Color(Android.Support.V4.Content.ContextCompat.GetColor(this, Resource.Color.primaryDark)));
                }

                EventID                    = Intent.GetLongExtra("strCapture", 0);
                EventCreatorID             = Intent.GetLongExtra("strCreatorId", 0);
                IsDefault                  = Intent.GetBooleanExtra("strIsDefaultEvent", false);
                camera_preview             = FindViewById <FrameLayout>(Resource.Id.camera_previewE);
                btnPhotos                  = FindViewById <Button>(Resource.Id.btnPhotosE);
                btnCamera                  = FindViewById <Button>(Resource.Id.btnCameraE);
                btnCapture                 = FindViewById <ImageButton>(Resource.Id.ivImageCapturebtnE);
                ivGalleryPhotoVideoUpload  = FindViewById <ImageButton>(Resource.Id.ivImageCaptureGalleryUploadE);
                btnSwitchCamera            = FindViewById <ImageButton>(Resource.Id.btnSwitchCameraE);
                btnFlash                   = FindViewById <ImageButton>(Resource.Id.btnFlashE);
                ivImageCaptureCameraUpload = FindViewById <ImageButton>(Resource.Id.ivImageCaptureCameraUploadE);
                rvCamera                   = FindViewById <RelativeLayout>(Resource.Id.rvCameraViewE);
                rvGalleryView              = FindViewById <RelativeLayout>(Resource.Id.rvGalleryViewE);
                ivSelectedImage            = FindViewById <ImageView>(Resource.Id.ivSelectedImageE);
                llCaptureView              = FindViewById <LinearLayout>(Resource.Id.llCaptureViewE);
                btnPhotos.SetTextColor(Color.Rgb(217, 217, 217));
                btnCamera.SetTextColor(Color.Rgb(0, 208, 150));
                btnPhotos.Click                 += BtnPhotos_Click;
                btnCamera.Click                 += BtnCamera_Click;
                btnCapture.Click                += BtnCapture_Click;
                btnSwitchCamera.Click           += BtnSwitchCamera_Click;
                btnFlash.Click                  += BtnFlash_Click;
                ivGalleryPhotoVideoUpload.Click += IvGalleryPhotoVideoUpload_Click;
                if (EventID == 0)
                {
                    AlertBox.Create("Error", "Error occurred!", this);
                    return;
                }

                SupportActionBar.SetDisplayHomeAsUpEnabled(true);
                SupportActionBar.SetHomeButtonEnabled(true);
            }
            catch (Java.Lang.Exception ex)
            {
                new CrashReportAsync("ImageCapture", "OnCreate", ex.Message + ex.StackTrace).Execute();
            }
        }
Exemple #10
0
        public void FloatRotationsKeepDecimals()
        {
            Vector2 coord1 = new Vector2(39.4f, 12.2f);

            Assert.AreEqual(TileTransformer.RotateCoord(coord1), new Vector2(39.4f, 12.2f));
            Assert.AreEqual(TileTransformer.InverseRotateCoord(coord1), new Vector2(39.4f, 12.2f));

            OrientationManager.SetOrientation(Orientation.West);
            Assert.AreEqual(TileTransformer.RotateCoord(coord1), new Vector2(12.2f, -39.4f));
            Assert.AreEqual(TileTransformer.InverseRotateCoord(coord1), new Vector2(-12.2f, 39.4f));
        }
        public void Init(int levelWidth, int levelHeight)
        {
            xDiff = (levelHeight / 2f) - 0.5f;
            yDiff = (levelWidth / 4f) - 0.25f;

            if (!subscribedToOrientationManager)
            {
                OrientationManager.RegisterObserver(this);
                subscribedToOrientationManager = true;
            }
        }
        public void WorldToCoordRotates()
        {
            OrientationManager.SetOrientation(Orientation.North);

            Vector2Int coords = new Vector2Int(13, -33);
            Vector2    world  = TileTransformer.CoordToWorld(coords) + new Vector2(Settings.TILE_WIDTH_HALF / 2f, 0f);

            Vector2Int invertedCoords = TileTransformer.WorldToCoord(world);

            OrientationManager.SetOrientation(Orientation.West);
            Assert.AreEqual(TileTransformer.InverseRotateCoord(invertedCoords), TileTransformer.WorldToCoord(world));
        }
Exemple #13
0
        public void RegularRotationBehaviour()
        {
            Vector2Int coord = new Vector2Int(34, -21);

            OrientationManager.SetOrientation(Orientation.East);
            Assert.AreEqual(TileTransformer.RotateCoord(coord), new Vector2Int(21, 34));

            OrientationManager.SetOrientation(Orientation.West);
            Assert.AreEqual(TileTransformer.RotateCoord(coord), new Vector2Int(-21, -34));

            OrientationManager.SetOrientation(Orientation.South);
            Assert.AreEqual(TileTransformer.RotateCoord(coord), new Vector2Int(-34, 21));
        }
Exemple #14
0
        public void InverseRotationBehaviour()
        {
            Vector2Int coord = new Vector2Int(-45, -23);

            OrientationManager.SetOrientation(Orientation.East);
            Assert.AreEqual(TileTransformer.InverseRotateCoord(coord), new Vector2Int(-23, 45));

            OrientationManager.SetOrientation(Orientation.West);
            Assert.AreEqual(TileTransformer.InverseRotateCoord(coord), new Vector2Int(23, -45));

            OrientationManager.SetOrientation(Orientation.South);
            Assert.AreEqual(TileTransformer.InverseRotateCoord(coord), new Vector2Int(45, 23));
        }
Exemple #15
0
        void Update()
        {
            // Wall Randomization
            if (Input.GetKeyDown(KeyCode.R))
            {
                level.RandomizeWalls();
            }

            // Wall Clipping
            if (Input.GetKeyDown(KeyCode.P))
            {
                coreLevelController.GetWallSpriteObserver().CurrentClipping = WallSpriteObserver.ClippingMode.FULL_CLIPPING;
            }
            if (Input.GetKeyDown(KeyCode.O))
            {
                coreLevelController.GetWallSpriteObserver().CurrentClipping = WallSpriteObserver.ClippingMode.NO_CLIP;
            }
            if (Input.GetKeyDown(KeyCode.I))
            {
                coreLevelController.GetWallSpriteObserver().CurrentClipping = WallSpriteObserver.ClippingMode.FRONT_CLIPPING;
            }

            // Orientation Rotation
            if (Input.GetKeyDown(KeyCode.E))
            {
                OrientationManager.RotateClockwise();
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                OrientationManager.RotateCounterClockwise();
            }

            // Debug character
            if (Input.GetKeyDown(KeyCode.N))
            {
                model.characters.Character characterM = new model.characters.Character(level, 6, 6);

                GameObject character = new GameObject("Character");
                characters.DefaultCharacterController dcc = character.AddComponent <characters.DefaultCharacterController>();
                dcc.Init(characterM);
            }

            // Debug save
            if (Input.GetKeyDown(KeyCode.S))
            {
                LevelSerializer ls = new LevelSerializer();
                level.Save(new DefaultLevelSerializer());
            }
        }
Exemple #16
0
        public void NorthRotationIsIdentity()
        {
            OrientationManager.SetOrientation(Orientation.North);

            Vector2Int coord1 = new Vector2Int(73, 12);
            Vector2Int coord2 = new Vector2Int(-89, 22);
            Vector2Int coord3 = new Vector2Int(10, -4);

            Assert.AreEqual(coord1, TileTransformer.RotateCoord(coord1));
            Assert.AreEqual(coord2, TileTransformer.RotateCoord(coord2));
            Assert.AreEqual(coord3, TileTransformer.RotateCoord(coord3));

            Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(coord1));
            Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(coord2));
            Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(coord3));
        }
    void Start()
    {
        gameObject.AddComponent("OrientationManager");
        orientationManager = gameObject.GetComponent<OrientationManager>();
        _view = this.GetComponent<CoherentUIView>();
        _view.OnViewCreated += new UnityViewListener.CoherentUI_OnViewCreated(this.OnViewReady);

        _view.Listener.ReadyForBindings += (frameId, path, isMainFrame) =>
        {
            _view.View.BindCall("GoToDestination", (System.Action<string>) GoToDestination);
            _view.View.BindCall("CheckLoginInformation", (System.Action<string, string, bool>) CheckLoginInformation);
            _view.View.BindCall("SignOut", (System.Action) SignOut);
            _view.View.BindCall("RequestToLogin", (System.Action) RequestToLogin);
        };

        _userManager = Object.FindObjectOfType(typeof(UserManager)) as UserManager;
        _viewReady = false;
    }
        public void WorldToCoordRounds()
        {
            OrientationManager.SetOrientation(Orientation.North);

            Vector2Int coords1 = new Vector2Int(42, 0);
            Vector2Int coords2 = new Vector2Int(-11, -63);
            Vector2Int coords3 = new Vector2Int(-52, 53);

            Vector2 world1 = TileTransformer.CoordToWorld(coords1) +
                             new Vector2(Settings.TILE_WIDTH / 6f, Settings.TILE_HEIGHT / 9f);

            Vector2 world2 = TileTransformer.CoordToWorld(coords2) +
                             new Vector2(Settings.TILE_WIDTH / 3f, 0f);

            // This test adds a big offset so the coords change.
            Vector2 world3 = TileTransformer.CoordToWorld(coords3) +
                             new Vector2(Settings.TILE_WIDTH_HALF, Settings.TILE_HEIGHT * 0.9f);

            Assert.AreEqual(coords1, TileTransformer.WorldToCoord(world1));
            Assert.AreEqual(coords2, TileTransformer.WorldToCoord(world2));
            Assert.AreEqual(coords3, TileTransformer.WorldToCoord(world3) + Vector2Int.one);
        }
Exemple #19
0
    /// <summary>
    /// Set camera FOV.
    /// </summary>
    private void SetCameraFieldOfView()
    {
        float deviceHorizontalFieldOfView = 0;
        float deviceVerticalFieldOfView   = 0;

        UpdateCameraFieldOfView(ref deviceHorizontalFieldOfView, ref deviceVerticalFieldOfView);
        ScreenOrientation orientation = OrientationManager.GetScreenOrientation();

        float cameraFOV = 1.0f;

        if (orientation == ScreenOrientation.LandscapeLeft ||
            orientation == ScreenOrientation.LandscapeRight)
        {
            cameraFOV = deviceVerticalFieldOfView;
        }
        else if (orientation == ScreenOrientation.PortraitUpsideDown ||
                 orientation == ScreenOrientation.Portrait)
        {
            cameraFOV = deviceHorizontalFieldOfView;
        }
        camera.fieldOfView = cameraFOV;
    }
        public void CoordToWorldRotates()
        {
            OrientationManager.SetOrientation(Orientation.North);
            Vector2Int originalCoord = new Vector2Int(77, 23);
            Vector2    originalWorld = TileTransformer.CoordToWorld(originalCoord);

            OrientationManager.SetOrientation(Orientation.East);
            Vector2Int eastCoord             = TileTransformer.RotateCoord(originalCoord);
            Vector2    eastWorldFromOriginal = TileTransformer.CoordToWorld(originalCoord);

            OrientationManager.SetOrientation(Orientation.West);
            Vector2Int westCoord             = TileTransformer.RotateCoord(originalCoord);
            Vector2    westWorldFromOriginal = TileTransformer.CoordToWorld(originalCoord);

            OrientationManager.SetOrientation(Orientation.South);
            Vector2Int southCoord             = TileTransformer.RotateCoord(originalCoord);
            Vector2    southWorldFromOriginal = TileTransformer.CoordToWorld(originalCoord);

            OrientationManager.SetOrientation(Orientation.North);

            Assert.AreEqual(TileTransformer.CoordToWorld(eastCoord), eastWorldFromOriginal);
            Assert.AreEqual(TileTransformer.CoordToWorld(westCoord), westWorldFromOriginal);
            Assert.AreEqual(TileTransformer.CoordToWorld(southCoord), southWorldFromOriginal);
        }
 public void StopObserving()
 {
     OrientationManager.UnregisterObserver(this);
 }
Exemple #22
0
        public void TileRotationIsInvertible()
        {
            Vector2Int coord1 = new Vector2Int(13, 32);
            Vector2Int coord2 = new Vector2Int(-42, 78);
            Vector2Int coord3 = new Vector2Int(-81, -70);

            // North
            OrientationManager.SetOrientation(Orientation.North);

            Vector2Int rotated1 = TileTransformer.RotateCoord(coord1);
            Vector2Int rotated2 = TileTransformer.RotateCoord(coord2);
            Vector2Int rotated3 = TileTransformer.RotateCoord(coord3);

            Vector2Int inverseRotated1 = TileTransformer.InverseRotateCoord(coord1);
            Vector2Int inverseRotated2 = TileTransformer.InverseRotateCoord(coord2);
            Vector2Int inverseRotated3 = TileTransformer.InverseRotateCoord(coord3);

            Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(rotated1));
            Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(rotated2));
            Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(rotated3));

            Assert.AreEqual(coord1, TileTransformer.RotateCoord(inverseRotated1));
            Assert.AreEqual(coord2, TileTransformer.RotateCoord(inverseRotated2));
            Assert.AreEqual(coord3, TileTransformer.RotateCoord(inverseRotated3));

            // East
            OrientationManager.SetOrientation(Orientation.East);

            rotated1 = TileTransformer.RotateCoord(coord1);
            rotated2 = TileTransformer.RotateCoord(coord2);
            rotated3 = TileTransformer.RotateCoord(coord3);

            inverseRotated1 = TileTransformer.InverseRotateCoord(coord1);
            inverseRotated2 = TileTransformer.InverseRotateCoord(coord2);
            inverseRotated3 = TileTransformer.InverseRotateCoord(coord3);

            Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(rotated1));
            Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(rotated2));
            Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(rotated3));

            Assert.AreEqual(coord1, TileTransformer.RotateCoord(inverseRotated1));
            Assert.AreEqual(coord2, TileTransformer.RotateCoord(inverseRotated2));
            Assert.AreEqual(coord3, TileTransformer.RotateCoord(inverseRotated3));

            // West
            OrientationManager.SetOrientation(Orientation.West);

            rotated1 = TileTransformer.RotateCoord(coord1);
            rotated2 = TileTransformer.RotateCoord(coord2);
            rotated3 = TileTransformer.RotateCoord(coord3);

            inverseRotated1 = TileTransformer.InverseRotateCoord(coord1);
            inverseRotated2 = TileTransformer.InverseRotateCoord(coord2);
            inverseRotated3 = TileTransformer.InverseRotateCoord(coord3);

            Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(rotated1));
            Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(rotated2));
            Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(rotated3));

            Assert.AreEqual(coord1, TileTransformer.RotateCoord(inverseRotated1));
            Assert.AreEqual(coord2, TileTransformer.RotateCoord(inverseRotated2));
            Assert.AreEqual(coord3, TileTransformer.RotateCoord(inverseRotated3));

            // South
            OrientationManager.SetOrientation(Orientation.South);

            rotated1 = TileTransformer.RotateCoord(coord1);
            rotated2 = TileTransformer.RotateCoord(coord2);
            rotated3 = TileTransformer.RotateCoord(coord3);

            inverseRotated1 = TileTransformer.InverseRotateCoord(coord1);
            inverseRotated2 = TileTransformer.InverseRotateCoord(coord2);
            inverseRotated3 = TileTransformer.InverseRotateCoord(coord3);

            Assert.AreEqual(coord1, TileTransformer.InverseRotateCoord(rotated1));
            Assert.AreEqual(coord2, TileTransformer.InverseRotateCoord(rotated2));
            Assert.AreEqual(coord3, TileTransformer.InverseRotateCoord(rotated3));

            Assert.AreEqual(coord1, TileTransformer.RotateCoord(inverseRotated1));
            Assert.AreEqual(coord2, TileTransformer.RotateCoord(inverseRotated2));
            Assert.AreEqual(coord3, TileTransformer.RotateCoord(inverseRotated3));
        }
 /// @endcond
 /// <summary>
 /// Rotate color camera render material's UV based on the color camera orientation and current activity orientation.
 /// </summary>
 /// <param name="uv">Input UV.</param>
 /// <param name="colorCamerRDisplay">Combined rotation index with color camera sensor and activity rotation.</param>
 /// <returns>Converted UV in Vector2.</returns>
 private static Vector2 _GetUnityUvBasedOnRotation(Vector2 uv, OrientationManager.Rotation colorCamerRDisplay)
 {
     switch (colorCamerRDisplay)
     {
     case OrientationManager.Rotation.ROTATION_270: 
         return new Vector2(1 - uv.y, 1 - uv.x);
     case OrientationManager.Rotation.ROTATION_180:
         return new Vector2(1 - uv.x, 0 + uv.y);
     case OrientationManager.Rotation.ROTATION_90:
         return new Vector2(0 + uv.y, 0 + uv.x);
     default:
         return new Vector2(0 + uv.x, 1 - uv.y);
     }
 }
    /// <summary>
    /// Update AR screen material with camera texture size data 
    /// (and distortion parameters if using distortion post-process filter).
    /// </summary>
    /// <param name="uOffset">U texcoord offset.</param>
    /// <param name="vOffset">V texcoord offset.</param>
    /// <param name="colorCameraRDisplay">Rotation of the display with respect to the color camera.</param> 
    private static void _MaterialUpdateForIntrinsics(
        float uOffset, float vOffset, OrientationManager.Rotation colorCameraRDisplay)
    {
        TangoApplication tangoApplication = GameObject.FindObjectOfType<TangoApplication>();
        Vector2[] uvs = new Vector2[4];
        uvs[0] = new Vector2(0 + uOffset, 0 + vOffset);
        uvs[1] = new Vector2(0 + uOffset, 1 - vOffset);
        uvs[2] = new Vector2(1 - uOffset, 0 + vOffset);
        uvs[3] = new Vector2(1 - uOffset, 1 - vOffset);

        for (int i = 0; i < 4; ++i)
        {
            uvs[i] = _GetUnityUvBasedOnRotation(uvs[i], colorCameraRDisplay);
        }
        
        VideoOverlayProvider.SetARScreenUVs(uvs);
    }
    /// <summary>
    /// Update AR screen rendering and attached Camera's projection matrix.
    /// </summary>
    /// <param name="displayRotation">Activity (screen) rotation.</param>
    /// <param name="colorCameraRotation">Color camera sensor rotation.</param>
    private void _SetRenderAndCamera(OrientationManager.Rotation displayRotation,
                                     OrientationManager.Rotation colorCameraRotation)
    {
        float cameraRatio = (float)Screen.width / (float)Screen.height;
        float cameraWidth = (float)Screen.width;
        float cameraHeight = (float)Screen.height;
        bool needToFlipCameraRatio = false;

        // Here we are computing if current display orientation is landscape or portrait.
        // AndroidHelper.GetAndroidDefaultOrientation() returns 1 if deivce default orientation is in portrait,
        // returns 2 if device default orientation is landscape. Adding device default orientation with
        // how much the display is rotation from default orientation will get us the result of current display
        // orientation. (landscape vs. portrait)
        bool isLandscape = (AndroidHelper.GetDefaultOrientation() + (int)displayRotation) % 2 == 0;

#if !UNITY_EDITOR
        // In most of the time, we don't need to flip the camera width and height. However, in some cases Unity camera
        // only updates couple of frames after the display changed callback from Android, thus we need to flip the width
        // and height in this case.
        //
        // This does not happen in the editor, because the emulated device does not ever rotate.
        needToFlipCameraRatio = (!isLandscape & (cameraRatio > 1.0f)) || (isLandscape & (cameraRatio < 1.0f));

        if (needToFlipCameraRatio)
        {
            cameraRatio = 1.0f / cameraRatio;
            float tmp = cameraWidth;
            cameraWidth = cameraHeight;
            cameraHeight = tmp;
        }
#endif

        TangoCameraIntrinsics alignedIntrinsics = new TangoCameraIntrinsics();
        TangoCameraIntrinsics intrinsics = new TangoCameraIntrinsics();
        VideoOverlayProvider.GetDeviceOientationAlignedIntrinsics(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR,
                                                                  alignedIntrinsics);
        VideoOverlayProvider.GetIntrinsics(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR,
                                           intrinsics);

        if (alignedIntrinsics.width != 0 && alignedIntrinsics.height != 0)
        {
            // The camera to which this script is attached is an Augmented Reality camera.  The color camera
            // image must fill that camera's viewport.  That means we must clip the color camera image to make
            // its ratio the same as the Unity camera.  If we don't do this the color camera image will be
            // stretched non-uniformly, making a circle into an ellipse.
            float widthRatio = (float)cameraWidth / (float)alignedIntrinsics.width;
            float heightRatio = (float)cameraHeight / (float)alignedIntrinsics.height;

            if (widthRatio >= heightRatio)
            {
                m_uOffset = 0;
                m_vOffset = (1 - (heightRatio / widthRatio)) / 2;
            }
            else
            {
                m_uOffset = (1 - (widthRatio / heightRatio)) / 2;
                m_vOffset = 0;
            }

            // Note that here we are passing in non-inverted intrinsics, because the YUV conversion is still operating
            // on native buffer layout.
            OrientationManager.Rotation rotation = TangoSupport.RotateFromAToB(displayRotation, colorCameraRotation);
            _MaterialUpdateForIntrinsics(m_uOffset, m_vOffset, rotation);
            _CameraUpdateForIntrinsics(m_camera, alignedIntrinsics, m_uOffset, m_vOffset);
            if (m_arCameraPostProcess != null)
            {
                m_arCameraPostProcess.SetupIntrinsic(intrinsics);
            }
        }
        else
        {
            Debug.LogError("AR Camera intrinsic is not valid.");
        }
    }
 /// <summary>
 /// Called when device orientation is changed.
 /// </summary>
 /// <param name="displayRotation">Orientation of current activity. Index enum is same same as Android screen
 /// rotation standard.</param>
 /// <param name="colorCameraRotation">Orientation of current color camera sensor. Index enum is same as Android
 /// camera rotation standard.</param>
 private void _OnDisplayChanged(OrientationManager.Rotation displayRotation,
                                OrientationManager.Rotation colorCameraRotation)
 {
     _SetRenderAndCamera(displayRotation, colorCameraRotation);
 }
Exemple #27
0
 public void Setup()
 {
     OrientationManager.SetOrientation(Orientation.North);
 }
Exemple #28
0
 public OnChangedListener(OrientationManager.IOnChangedListener callback)
 {
     _callback = callback;
 }
Exemple #29
0
 public void OnLocationChanged(OrientationManager orientationManager)
 {
     _callback.OnLocationChanged(orientationManager);
 }
Exemple #30
0
 public void OnAccuracyChanged(OrientationManager orientationManager)
 {
     _callback.OnAccuracyChanged(orientationManager);
 }
    void Start()
    {
        // register the chambers and bullets
        for ( int i=0; i < 8; i++ ){
            chambers.Add(new ChamberStates());
            Transform chamber = GameObject.Find("Chamber"+i).transform;
            GameObject tempLive = chamber.FindChild("LiveBullet").gameObject;
            liveBullets.Add(tempLive);
            GameObject tempSpent = chamber.FindChild("SpentBullet").gameObject;
            spentBullets.Add(tempSpent);
        }

        om = gameObject.GetComponent<OrientationManager>();

        if ( !isTutorial ){
            if ( !openPlay ){
                guiManager.displayLevelModal();
            } else {
                //begin();
            }
        } else {
            // tutorial step 0
            // ROTATION
            string descriptiontext = "Rotate Your Device Open and Close the Revolver Cylinder";
            string buttonText = "CHECK  IT  OUT!";
            Sprite img = Resources.LoadAll<Sprite>("Art/Source/rss_tutorial")[0];;
            ModalLayouts layout = ModalLayouts.TwoColumnModal;
            guiManager.customModal(
                    descriptiontext,
                    buttonText,
                    img,
                    layout
                );
        }

        hammerState = HammerStates.Rest;
    }