protected override void RetrieveDataAsync()
        {
            RTPacket packet = connection.Protocol.GetRTPacket();

            cameras = packet.Get2DMarkerData();

            if (cameras != null)
            {
                for (int i = 0; i < cameras.Count; i++)
                {
                    int id = i + 1;
                    if (CameraManager.Cameras.ContainsKey(id))
                    {
                        Camera       camera       = cameras[i];
                        CameraScreen cameraScreen = CameraManager.Cameras[id]?.Screen;

                        // NOTE: There is a chance that the packet does not contain data for the currently selected
                        // camera if that is the case simply catch the exception and log it then keep streaming as usual.
                        try
                        {
                            if (cameraScreen != null)
                            {
                                Urho.Application.InvokeOnMain(() => cameraScreen.MarkerData = camera);
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("MarkerStream:" + e.Message);
                            Debugger.Break();
                        }
                    }
                }
            }
        }
 private void DestroyCheck()
 {
     if (CameraScreen.ObjectIsBehindCamera(transform))
     {
         Destroy(gameObject);
     }
 }
Example #3
0
 private void CheckDestroy()
 {
     if (CameraScreen.ObjectIsAboveCamera(_transform))
     {
         SelfDestruct();
     }
 }
Example #4
0
 void Awake()
 {
     current      = this;
     cameraPos    = Camera.main.transform.position;
     screenSize.x = Vector2.Distance(Camera.main.ScreenToWorldPoint(new Vector2(0, 0)), Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, 0))) * 0.5f;
     screenSize.y = Vector2.Distance(Camera.main.ScreenToWorldPoint(new Vector2(0, 0)), Camera.main.ScreenToWorldPoint(new Vector2(0, Screen.height))) * 0.5f;
 }
Example #5
0
 private void DestoyOnOutOfScreen()
 {
     if (CameraScreen.ObjectIsBehindCamera(_transform) || CameraScreen.ObjectIsUnderCamera(_transform))
     {
         gameObject.SetActive(false);
     }
 }
Example #6
0
 void Update()
 {
     if (tag == "Wall" && CameraScreen.ObjectIsBehindCamera(transform))
     {
         Destroy(gameObject);
     }
 }
 public void EnableCamera()
 {
     CameraScreen.SetActive(true);
     cameraSphere.SetActive(false);
     enabledCapture = true;
     cameraScreen.transform.parent        = HandParent;
     CameraScreen.transform.localPosition = screenPos;
     CameraScreen.transform.localRotation = Quaternion.Euler(new Vector3(90, 0, 0));
 }
Example #8
0
    // Update is called once per frame
    void FixedUpdate()
    {
        transform.Rotate(0, 0, 1 * _rotationSpeed);

        if (CameraScreen.ObjectIsBehindCamera(transform))
        {
            Destroy(gameObject);
        }
    }
Example #9
0
    private void InitInstance()
    {
        bool isAlone = !(Instance != null && Instance != this);

        Assert.IsTrue(isAlone);

        Instance = this;
        // TODO:: change all other InitInstances to the same kind
    }
Example #10
0
        /// <summary>
        /// Generates camera screens to use inside an Urho context based on the
        /// ImageCameras recieved from the QTM host.
        /// </summary>
        /// <returns></returns>
        public static bool GenerateCameras()
        {
            CurrentCamera = null;
            Cameras       = new Dictionary <int, Camera>();
            CameraScreen.ResetScreenCounter();

            // Get Camera Settings
            List <SettingsGeneralCameraSystem> cameraSettingsList = SettingsService.GetCameraSettings();

            // Get Image Settings
            List <ImageCamera> imageCameraSettingsList = SettingsService.GetImageCameraSettings();

            // Iterate over image settings list and create camera objects
            foreach (ImageCamera imageCameraSettings in imageCameraSettingsList)
            {
                SettingsGeneralCameraSystem cameraSettings = cameraSettingsList
                                                             .Where(c => c.CameraId == imageCameraSettings.CameraID)
                                                             .First();

                if (!imageCameraSettings.Enabled && cameraSettings.Mode != CameraMode.ModeMarker)
                {
                    SettingsService.SetCameraMode(imageCameraSettings.CameraID, cameraSettings.Mode);
                }

                ImageResolution imageResolution = new ImageResolution(imageCameraSettings.Width / 2, imageCameraSettings.Height / 2);

                // Create camera object and add it to dictionary
                Camera camera = new Camera(imageCameraSettings.CameraID, cameraSettings, imageResolution);
                Cameras.Add(camera.ID, camera);

                // Make sure that the current settings are reflected in the state of the application
                // The state of the QTM host should always have precedence unless expliciltly told to
                // change settings
                if (CurrentCamera == null)
                {
                    CurrentCamera = camera;
                }
            }

            // Load and run profiler
            CameraProfiler cameraProfiler = new CameraProfiler(Cameras, "CameraProfiles.json");

            cameraProfiler.Run();

            // Dispose of it once it's done
            cameraProfiler.Dispose();
            cameraProfiler = null;

            return(true);
        }
Example #11
0
        public override void SetCameraScreenPosition(CameraScreen screen, DeviceOrientations orientation)
        {
            float heightOffset;

            if (orientation == DeviceOrientations.Landscape)
            {
                Columns      = 3;
                heightOffset = 0;
            }
            else
            {
                Columns      = 2;
                heightOffset = 1.25f;
            }

            min = 0;

            // Prevent the camera from being zoomed when in grid view
            if (Camera.Zoom > 1)
            {
                Camera.Zoom = 1;
            }

            if (Camera.Node.Position.X != 0 || Camera.Node.Position.Y > 0)
            {
                Camera.Node.SetPosition2D(new Vector2(0, 0));
            }

            float margin = 5;

            // Calculate the distance where the camera screen width is half the width of the frustrum
            float distance = (float)DataOperations.GetDistanceForFrustrumWidth(screen.Width * Columns + margin, Camera.AspectRatio, Camera.Fov);

            float halfHeight = distance * Camera.HalfViewSize;
            float halfWidth  = halfHeight * Camera.AspectRatio;

            cellHeight = screen.Height > cellHeight ? screen.Height : cellHeight;

            float screenPosition = Math.Abs(((screen.position - 1) % Columns) - (Columns - 1));

            float x = -halfWidth + (((Columns - 1) - screenPosition)) * halfWidth * 2 / Columns + halfWidth / Columns;
            float y = halfHeight - screen.Height / 2 - (float)Math.Floor((double)(screen.position - 1) / (float)Columns) * (cellHeight + margin / 2) - margin / 2;

            newMin = y + screen.Height * heightOffset;
            min    = newMin < min ? newMin : min;

            // We need a small offset or the will not be seen by the camera
            screen.Node.SetWorldPosition(new Vector3(x, y, distance));
        }
Example #12
0
    public virtual void FixedUpdate()
    {
        if (_isHit)
        {
            Color c = spriteRenderer.color;
            c.a = 0.5f;

            spriteRenderer.color = c;
        }

        if (CameraScreen.ObjectIsBehindCamera(transform) && transform.parent == null)
        {
            Destroy(gameObject);
        }
    }
Example #13
0
        private void MoveFloors()
        {
            foreach (GameObject floor in _floors)
            {
                if (CameraScreen.ObjectIsBehindCamera(floor.transform))
                {
                    if (_allowDescending && DescentChance())
                    {
                        Descent();
                    }

                    floor.transform.position = new Vector3(
                        (_floors.OrderByDescending(f => f.transform.position.x).First().transform.position.x + CameraScreen.width),
                        _currentYFloor,
                        floor.transform.position.z
                        );
                }
            }
        }
Example #14
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if ((currentBehaviour == laserEnum.Down && transform.position.y <= lowPos.y) ||
            currentBehaviour == laserEnum.Up && transform.position.y >= highPos.y)
        {
            if (isChangingColor)
            {
                foreach (Transform child in transform)
                {
                    child.GetComponent <Laser>().ChangeColor();
                }
            }

            lastBehaviour    = currentBehaviour;
            currentBehaviour = laserEnum.Idle;
        }
        else if (currentBehaviour == laserEnum.Down)
        {
            transform.position += Vector3.down * speed;
        }
        else if (currentBehaviour == laserEnum.Up)
        {
            transform.position += Vector3.up * speed;
        }
        else if (currentBehaviour == laserEnum.Idle)
        {
            if ((Mathf.Floor(transform.eulerAngles.z) >= lastRotation + 90) || (Mathf.Floor(transform.eulerAngles.z) == 0 && lastRotation >= 270f))
            {
                ChangeBehaviour();
            }
            else
            {
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(transform.eulerAngles.x,
                                                                                          transform.eulerAngles.y, transform.eulerAngles.z + 90), 1f * Time.deltaTime);
            }
        }

        if (CameraScreen.ObjectIsBehindCamera(transform))
        {
            Destroy(gameObject);
        }
    }
Example #15
0
    public void UpdateMouseInputs()
    {
        float dt = FrameController.DT();

        UpdateMousePosition();

        if (isPaperHeld || (rcCarScript != null && rcCarScript.isMouseHeld)) // Lock input until paper is put down
        {
            if (Input.GetTriggered(0, "MouseLClick") == 1.0f)
            {
                if (rcCarScript != null && rcCarScript.isMouseHeld)
                {
                    rcCarScript.isMouseHeld = false;
                }
                else
                {
                    pickedInteractable.OnTriggered();
                    isPaperHeld = false;
                }
            }
        }
        else
        {
            // Apply raycast of ocuPlayer's mouse to find any interactable object every frame (when mouse is not clicked)
            Vector3 ocuCamToMouse = (Vector3)gameObject.transform.position - (Vector3)ocuCam.transform.position;

            // Quick Hack to fix offset
            // Vector3 xAxis = ocuCam.transform.GetRightVector();
            // Vector3 yAxis = ocuCam.transform.GetUpVector();
            // ocuCamToMouse += xAxis * 0.055f;
            // ocuCamToMouse += yAxis * 0.12f;

            ocuCamToMouse.Normalize();
            if (Input.GetHeld(0, "MouseLClick") == 0.0f)
            {
                pickedObject = PhysicEngine.getInstance().RayCast3DWithTag(ocuCam.transform.position, ocuCamToMouse, 10000.0f, Common.tagForInteractables);

                pickedInteractable = null;
                // Check if mouse is over a valid camInMap
                if (pickedObject != null)
                {
                    pickedInteractable = GetScriptClass <InteractableObjectBaseClass>(pickedObject, false);
                    if (pickedInteractable != null)
                    {
                        pickedInteractable.OnMouseOver();

// The logic for ray casting through the camera screen into world objects
                        CameraScreen pickedScreen = pickedInteractable as CameraScreen;
                        if (pickedScreen != null && camScript.gameObjectParentedTo != null &&
                            camScript.gameObjectParentedTo != Common.GetNoiseStatic())
                        {
                            CTransform screenTrans = pickedScreen.gameObject.transform;
                            Vector3    screenPos   = screenTrans.position;
                            Vector3    rightVect   = screenTrans.GetRightVector();
                            Vector3    upVect      = screenTrans.GetUpVector();
                            Vector3    normal      = screenTrans.GetForwardVector();
                            Vector3    screenScale = screenTrans.GetScale();

                            Vector3 pointOnScreen = new Vector3();
                            MMath.RayToPlaneIntersection(normal, screenPos, ocuCamToMouse, ocuCam.transform.position, ref pointOnScreen);
                            Vector3 screenToPoint = pointOnScreen - screenPos;
                            float   xAmt          = -Vector3.Dot(screenToPoint, rightVect); // the camera screen's x is negative (to the left)
                            float   yAmt          = Vector3.Dot(screenToPoint, upVect);
                            float   xScaleOfModel = screenScale.X * 0.5f;                   // Reflect actual camera screen width in pixel units (quad is just nice 1 scale == 1 unit)
                            float   yScaleOfModel = screenScale.Y * 0.5f;
                            xAmt /= xScaleOfModel;                                          // [-0.5, 0.5]
                            yAmt /= yScaleOfModel;

                            float nearZ        = ocuCameraScreen.GetNearZ();
                            float screenWidth  = ocuCameraScreen.GetNearWindowWidth();
                            float screenHeight = ocuCameraScreen.GetNearWindowHeight();
                            xAmt *= screenWidth; // [-0.5, 0.5] -> [-w/2, w/2]
                            yAmt *= screenHeight;
                            // Use the x, y and z values through the actual camera look at directions
                            Vector3 innerCameraVect = xAmt * (Vector3)camScript.gameObjectParentedTo.transform.GetRightVector() +
                                                      yAmt * (Vector3)camScript.gameObjectParentedTo.transform.GetUpVector() +
                                                      nearZ * (Vector3)camScript.gameObjectParentedTo.transform.GetForwardVector();
                            innerCameraVect.Normalize();

                            Vector3 cameraPos = camScript.gameObjectParentedTo.transform.position +
                                                0.5f * innerCameraVect; // Move in front, so it does not ray cast to the screen itself

                            GameObject cameraInteractable = PhysicEngine.getInstance().RayCast3DWithTag(cameraPos, innerCameraVect, 10000.0f, "camInteract");
                            if (cameraInteractable != null)
                            {
                                // If there is an interactable objec through the screen, check if there is ANY object infront of it
                                GameObject nearestObj = PhysicEngine.getInstance().RayCast3D(cameraPos, innerCameraVect, 10000.0f);
                                if (nearestObj == cameraInteractable)
                                {
                                    pickedInteractable = GetScriptClass <InteractableObjectBaseClass>(cameraInteractable, false);
                                    if (pickedInteractable != null)
                                    {
                                        pickedInteractable.OnMouseOver();
                                    }
                                }
                                else // There is something blocking
                                {
                                    Logger.Log("nearer Obj found: " + nearestObj.GetName());
                                }
                            }
                        }
                    }
                }
                // If prev interactable changed or is lost, call it's mouseOverOff
                if (prevPickedInteractable != pickedInteractable)
                {
                    if (prevPickedInteractable != null)
                    {
                        prevPickedInteractable.OnMouseOverOff();
                        if (Input.GetReleased(0, "MouseLClick") == 1.0f)
                        {
                            prevPickedInteractable.OnReleased();
                        }
                    }
                    prevPickedInteractable = pickedInteractable;
                }
            } // End of if not mouse held

            if (Input.GetTriggered(0, "MouseLClick") == 1.0f)
            {
                if (pickedInteractable != null)
                {
                    pickedInteractable.OnTriggered();

                    // If picked up paper, lock the input
                    Paper pickedPaper = pickedInteractable as Paper;
                    if (pickedPaper != null)
                    {
                        if (pickedPaper.GetIsHeldUp())
                        {
                            isPaperHeld = true;
                        }
                    }
                }
            }
            if (Input.GetHeld(0, "MouseLClick") == 1.0f)
            {
                if (pickedInteractable != null)
                {
                    pickedInteractable.OnHeldMouse(mCurrMouseMovement.X, mCurrMouseMovement.Y);
                }
            }
            if (Input.GetReleased(0, "MouseLClick") == 1.0f)
            {
                if (pickedInteractable != null)
                {
                    pickedInteractable.OnReleased();
                }
            }
        }
    }
Example #16
0
 void Start()
 {
     activeScreen = CameraScreen.GetScreenForObject(this.gameObject);
     if(activeScreen == null)
         Debug.LogWarning("No activeScreen found on GUIPlane: " + gameObject.name);
     updateTextureFactor();
 }
Example #17
0
 /// <summary>
 /// Generates a screen for a camera instance
 /// </summary>
 /// <param name="node"></param>
 public void GenerateScreen(Urho.Node node)
 {
     Screen = new CameraScreen(this, node);
 }
Example #18
0
 void Awake()
 {
     numberPanels = new List<Panel>();
     Points = string.Empty;
     activeScreen = CameraScreen.GetScreenForObject(this.gameObject);
 }