Exemplo n.º 1
0
            private void UpdateFieldOfView(FieldOfView leftEyeFov, FieldOfView rightEyeFov)
            {
                CardboardDeviceParams cdp        = mHmd.getCardboard();
                ScreenParams          screen     = mHmd.getScreen();
                Distortion            distortion = cdp.getDistortion();

                float idealFovAngle = (float)Math.ToDegrees(Math.Atan2(cdp.getLensDiameter() / 2.0F, cdp.getEyeToLensDistance()));

                float eyeToScreenDist = cdp.getEyeToLensDistance() + cdp.getScreenToLensDistance();

                float outerDist = (screen.getWidthMeters() - cdp.getInterpupillaryDistance()) / 2.0F;

                float innerDist  = cdp.getInterpupillaryDistance() / 2.0F;
                float bottomDist = cdp.getVerticalDistanceToLensCenter() - screen.getBorderSizeMeters();

                float topDist = screen.getHeightMeters() + screen.getBorderSizeMeters() - cdp.getVerticalDistanceToLensCenter();

                float outerAngle = (float)Math.ToDegrees(Math.Atan2(distortion.distort(outerDist), eyeToScreenDist));

                float innerAngle = (float)Math.ToDegrees(Math.Atan2(distortion.distort(innerDist), eyeToScreenDist));

                float bottomAngle = (float)Math.ToDegrees(Math.Atan2(distortion.distort(bottomDist), eyeToScreenDist));

                float topAngle = (float)Math.ToDegrees(Math.Atan2(distortion.distort(topDist), eyeToScreenDist));

                leftEyeFov.setLeft(Math.Min(outerAngle, idealFovAngle));
                leftEyeFov.setRight(Math.Min(innerAngle, idealFovAngle));
                leftEyeFov.setBottom(Math.Min(bottomAngle, idealFovAngle));
                leftEyeFov.setTop(Math.Min(topAngle, idealFovAngle));

                rightEyeFov.setLeft(Math.Min(innerAngle, idealFovAngle));
                rightEyeFov.setRight(Math.Min(outerAngle, idealFovAngle));
                rightEyeFov.setBottom(Math.Min(bottomAngle, idealFovAngle));
                rightEyeFov.setTop(Math.Min(topAngle, idealFovAngle));
            }
        public CardboardDeviceParams()
        {
            mVendor  = DEFAULT_VENDOR;
            mModel   = DEFAULT_MODEL;
            mVersion = DEFAULT_VERSION;

            mInterpupillaryDistance       = DEFAULT_INTERPUPILLARY_DISTANCE;
            mVerticalDistanceToLensCenter = DEFAULT_VERTICAL_DISTANCE_TO_LENS_CENTER;
            mLensDiameter         = DEFAULT_LENS_DIAMETER;
            mScreenToLensDistance = DEFAULT_SCREEN_TO_LENS_DISTANCE;
            mEyeToLensDistance    = DEFAULT_EYE_TO_LENS_DISTANCE;

            mVisibleViewportSize = DEFAULT_VISIBLE_VIEWPORT_MAX_SIZE;
            mFovY = DEFAULT_FOV_Y;

            mDistortion = new Distortion();
        }
        public CardboardDeviceParams(CardboardDeviceParams @params)
        {
            mNfcTagContents = @params.mNfcTagContents;

            mVendor  = @params.mVendor;
            mModel   = @params.mModel;
            mVersion = @params.mVersion;

            mInterpupillaryDistance       = @params.mInterpupillaryDistance;
            mVerticalDistanceToLensCenter = @params.mVerticalDistanceToLensCenter;
            mLensDiameter         = @params.mLensDiameter;
            mScreenToLensDistance = @params.mScreenToLensDistance;
            mEyeToLensDistance    = @params.mEyeToLensDistance;

            mVisibleViewportSize = @params.mVisibleViewportSize;
            mFovY = @params.mFovY;

            mDistortion = new Distortion(@params.mDistortion);
        }
Exemplo n.º 4
0
        public bool equals(Object other)
        {
            if (other == null)
            {
                return(false);
            }

            if (other == this)
            {
                return(true);
            }

            if (!(other is Distortion))
            {
                return(false);
            }

            Distortion o = (Distortion)other;

            return((mCoefficients[0] == o.mCoefficients[0]) && (mCoefficients[1] == o.mCoefficients[1]));
        }
Exemplo n.º 5
0
 public Distortion(Distortion other)
 {
     mCoefficients    = new float[2];
     mCoefficients[0] = other.mCoefficients[0];
     mCoefficients[1] = other.mCoefficients[1];
 }
Exemplo n.º 6
0
            public DistortionMesh(EyeParams eye, Distortion distortion, float screenWidthM, float screenHeightM, float xEyeOffsetMScreen, float yEyeOffsetMScreen, float textureWidthM, float textureHeightM, float xEyeOffsetMTexture, float yEyeOffsetMTexture, float viewportXMTexture, float viewportYMTexture, float viewportWidthMTexture, float viewportHeightMTexture)
            {
                float mPerUScreen  = screenWidthM;
                float mPerVScreen  = screenHeightM;
                float mPerUTexture = textureWidthM;
                float mPerVTexture = textureHeightM;

                float[] vertexData   = new float[8000];
                int     vertexOffset = 0;

                for (int row = 0; row < 40; row++)
                {
                    for (int col = 0; col < 40; col++)
                    {
                        float uTexture = col / 39.0F * (viewportWidthMTexture / textureWidthM) + viewportXMTexture / textureWidthM;

                        float vTexture = row / 39.0F * (viewportHeightMTexture / textureHeightM) + viewportYMTexture / textureHeightM;

                        float xTexture    = uTexture * mPerUTexture;
                        float yTexture    = vTexture * mPerVTexture;
                        float xTextureEye = xTexture - xEyeOffsetMTexture;
                        float yTextureEye = yTexture - yEyeOffsetMTexture;
                        float rTexture    = (float)Math.Sqrt(xTextureEye * xTextureEye + yTextureEye * yTextureEye);

                        float textureToScreen = rTexture > 0.0F ? distortion.distortInverse(rTexture) / rTexture : 1.0F;

                        float xScreen = xTextureEye * textureToScreen + xEyeOffsetMScreen;
                        float yScreen = yTextureEye * textureToScreen + yEyeOffsetMScreen;
                        float uScreen = xScreen / mPerUScreen;
                        float vScreen = yScreen / mPerVScreen;
                        float vignetteSizeMTexture = 0.002F / textureToScreen;

                        float dxTexture = xTexture - DistortionRenderer.clamp(xTexture, viewportXMTexture + vignetteSizeMTexture, viewportXMTexture + viewportWidthMTexture - vignetteSizeMTexture);

                        float dyTexture = yTexture - DistortionRenderer.clamp(yTexture, viewportYMTexture + vignetteSizeMTexture, viewportYMTexture + viewportHeightMTexture - vignetteSizeMTexture);

                        float drTexture = (float)Math.Sqrt(dxTexture * dxTexture + dyTexture * dyTexture);

                        float vignette = 1.0F - DistortionRenderer.clamp(drTexture / vignetteSizeMTexture, 0.0F, 1.0F);

                        vertexData[(vertexOffset + 0)] = (2.0F * uScreen - 1.0F);
                        vertexData[(vertexOffset + 1)] = (2.0F * vScreen - 1.0F);
                        vertexData[(vertexOffset + 2)] = vignette;
                        vertexData[(vertexOffset + 3)] = uTexture;
                        vertexData[(vertexOffset + 4)] = vTexture;

                        vertexOffset += 5;
                    }
                }

                nIndices = 3158;
                int[] indexData   = new int[nIndices];
                int   indexOffset = 0;

                vertexOffset = 0;
                for (int row = 0; row < 39; row++)
                {
                    if (row > 0)
                    {
                        indexData[indexOffset] = indexData[(indexOffset - 1)];
                        indexOffset++;
                    }
                    for (int col = 0; col < 40; col++)
                    {
                        if (col > 0)
                        {
                            if (row % 2 == 0)
                            {
                                vertexOffset++;
                            }
                            else
                            {
                                vertexOffset--;
                            }
                        }
                        indexData[(indexOffset++)] = vertexOffset;
                        indexData[(indexOffset++)] = (vertexOffset + 40);
                    }
                    vertexOffset += 40;
                }

                FloatBuffer vertexBuffer = ByteBuffer.AllocateDirect(vertexData.Length * 4).Order(ByteOrder.NativeOrder()).AsFloatBuffer();

                vertexBuffer.Put(vertexData).Position(0);

                IntBuffer indexBuffer = ByteBuffer.AllocateDirect(indexData.Length * 4).Order(ByteOrder.NativeOrder()).AsIntBuffer();

                indexBuffer.Put(indexData).Position(0);

                int[] bufferIds = new int[2];
                GLES20.GlGenBuffers(2, bufferIds, 0);
                mArrayBufferId   = bufferIds[0];
                mElementBufferId = bufferIds[1];

                GLES20.GlBindBuffer(34962, mArrayBufferId);
                GLES20.GlBufferData(34962, vertexData.Length * 4, vertexBuffer, 35044);

                GLES20.GlBindBuffer(34963, mElementBufferId);
                GLES20.GlBufferData(34963, indexData.Length * 4, indexBuffer, 35044);

                GLES20.GlBindBuffer(34962, 0);
                GLES20.GlBindBuffer(34963, 0);
            }
Exemplo n.º 7
0
 private float computeDistortionScale(Distortion distortion, float screenWidthM, float interpupillaryDistanceM)
 {
     return(distortion.distortionFactor((screenWidthM / 2.0F - interpupillaryDistanceM / 2.0F) / (screenWidthM / 4.0F)));
 }