Example #1
0
        public static void SetupCameraInfo(Camera camera, float fov, float size, float nearClipFactor, float farClipFactor)
        {
            camera.fieldOfView = fov;
            float adjustedDistance = LookingGlassUtil.GetAdjustedDistance(fov, size);

            camera.nearClipPlane = adjustedDistance - nearClipFactor * size;
            camera.farClipPlane  = adjustedDistance + farClipFactor * size;

            camera.transform.position      = new Vector3(0, 0, -adjustedDistance);
            camera.transform.localRotation = Quaternion.identity;
        }
Example #2
0
        public static Vector4 GetVPMatrixOffsets(float aspect, float fov, float size, int view, int numViews)
        {
            float adjustedDistance = LookingGlassUtil.GetAdjustedDistance(fov, size);

            float verticalAngle   = 0.0f;
            float horizontalAngle = AngleAtView(view, numViews);

            float offsetX = adjustedDistance * Mathf.Tan(horizontalAngle * Mathf.Deg2Rad);
            float offsetY = adjustedDistance * Mathf.Tan(verticalAngle * Mathf.Deg2Rad);

            Vector4 result = new Vector4(offsetX, offsetY,
                                         offsetX / (size * aspect), offsetY / size);

            return(result);
        }
Example #3
0
        private void DebugSetup(Camera camera, MaterialPropertyBlock materialPropertyBlock)
        {
            int tileNum = drawInfo.tileX * drawInfo.tileY;

            Matrix4x4[] lookingView       = new Matrix4x4[tileNum];
            Matrix4x4[] lookingProjection = new Matrix4x4[tileNum];
            Matrix4x4[] lookingVp         = new Matrix4x4[tileNum];
            int         counter           = 0;

            for (int i = 0; i < drawInfo.tileY; ++i)
            {
                for (int j = 0; j < drawInfo.tileX; ++j)
                {
                    Matrix4x4 projMatrix = camera.projectionMatrix;
                    Matrix4x4 viewMatrix = camera.worldToCameraMatrix;

                    float adjustedDistance = LookingGlassUtil.GetAdjustedDistance(perCameraInfo.fov, perCameraInfo.size);

                    float verticalAngle   = 0.0f;
                    float horizontalAngle = LookingGlassUtil.AngleAtView(counter, tileNum);

                    float offsetX = adjustedDistance * Mathf.Tan(horizontalAngle * Mathf.Deg2Rad);
                    float offsetY = adjustedDistance * Mathf.Tan(verticalAngle * Mathf.Deg2Rad);

                    // view matrix
                    viewMatrix.m03 -= offsetX;
                    viewMatrix.m13 -= offsetY;

                    // proj matrix
                    projMatrix.m02 -= offsetX / (perCameraInfo.size * camera.aspect);
                    projMatrix.m12 -= offsetY / perCameraInfo.size;

                    lookingView[counter]       = viewMatrix;
                    lookingProjection[counter] = projMatrix;
                    lookingVp[counter]         = viewMatrix * projMatrix;
                    ++counter;
                }
            }
            materialPropertyBlock.SetMatrixArray("LookingView", lookingView);
            materialPropertyBlock.SetMatrixArray("LookingProjection", lookingProjection);
            materialPropertyBlock.SetMatrixArray("LookingVP", lookingVp);
        }