コード例 #1
0
    public void ReinitalizeCamera(float horizontalViewAngle)
    {
        if (m_camera == null)
        {
            Debug.LogError("Camera component is found.");
            return;
        }
        m_camera.fieldOfView   = Camera.HorizontalToVerticalFieldOfView(horizontalViewAngle, m_camera.aspect);
        m_focalLength          = 1.0f / (2.0f * Mathf.Tan(horizontalViewAngle * Mathf.Deg2Rad * 0.5f));
        m_cameraImageTransform = cameraImage.GetComponent <RectTransform>();
        float pixelFocalLength      = (float)(m_webCamTexture.width) * m_focalLength;
        bool  successInitialization = SonarLib.InitializeTrackingSystemForPinhole(1, m_webCamTexture.width, m_webCamTexture.height,
                                                                                  new Vector2(pixelFocalLength, pixelFocalLength),
                                                                                  new Vector2(m_webCamTexture.width * 0.5f, m_webCamTexture.height * 0.5f));

        if (!successInitialization)
        {
            Debug.LogError("Sonar reinitialization fail.");
        }
    }
コード例 #2
0
    void Start()
    {
        m_webCamTexture     = new WebCamTexture(WebCamTexture.devices[0].name, 640, 480);
        cameraImage.texture = m_webCamTexture;
        m_webCamTexture.Play();
        m_camera = GetComponent <Camera>();
        m_cameraImageTransform = cameraImage.GetComponent <RectTransform>();
        m_focalLength          = (float)(m_webCamTexture.width);
        if (m_camera == null)
        {
            Debug.LogError("Camera component is found.");
        }
        else
        {
#if UNITY_ANDROID
            m_camera.fieldOfView = Camera.HorizontalToVerticalFieldOfView(65, m_camera.aspect);;
#endif
            float horizontalFieldOfView = Camera.VerticalToHorizontalFieldOfView(m_camera.fieldOfView, m_camera.aspect);
            m_focalLength = 1.0f / (2.0f * Mathf.Tan(horizontalFieldOfView * Mathf.Deg2Rad * 0.5f));
        }
        m_cameraImageTransform = cameraImage.GetComponent <RectTransform>();
        float pixelFocalLength      = (float)(m_webCamTexture.width) * m_focalLength;
        bool  successInitialization = SonarLib.InitializeTrackingSystemForPinhole(1, m_webCamTexture.width, m_webCamTexture.height,
                                                                                  new Vector2(pixelFocalLength, pixelFocalLength),
                                                                                  new Vector2(m_webCamTexture.width * 0.5f, m_webCamTexture.height * 0.5f));
        if (!successInitialization)
        {
            Debug.LogError("Sonar initialization fail.");
        }

        /*var cameraImageTransform = cameraImage.GetComponent<RectTransform>();
         * if (webCamTexture.width > webCamTexture.height)
         * {
         *  cameraImageTransform.localScale = new Vector3(1.0f, (float)(webCamTexture.width) / (float)(webCamTexture.height), 1.0f);
         * }
         * else
         * {
         *  cameraImageTransform.localScale = new Vector3((float)(webCamTexture.height) / (float)(webCamTexture.width), 1.0f, 1.0f);
         * }*/
    }