Пример #1
0
        private EyeViewport initViewportForEye(EyeParams eye, float xOffsetM)
        {
            ScreenParams          screen = mHmd.getScreen();
            CardboardDeviceParams cdp    = mHmd.getCardboard();

            float eyeToScreenDistanceM = cdp.getEyeToLensDistance() + cdp.getScreenToLensDistance();
            float leftM = (float)Math.Tan(Math.ToRadians(eye.getFov().getLeft())) * eyeToScreenDistanceM;

            float rightM = (float)Math.Tan(Math.ToRadians(eye.getFov().getRight())) * eyeToScreenDistanceM;

            float bottomM = (float)Math.Tan(Math.ToRadians(eye.getFov().getBottom())) * eyeToScreenDistanceM;

            float topM = (float)Math.Tan(Math.ToRadians(eye.getFov().getTop())) * eyeToScreenDistanceM;

            EyeViewport vp = new EyeViewport();

            vp.x      = xOffsetM;
            vp.y      = 0.0F;
            vp.width  = (leftM + rightM);
            vp.height = (bottomM + topM);
            vp.eyeX   = (leftM + xOffsetM);
            vp.eyeY   = bottomM;

            float xPxPerM = screen.getWidth() / screen.getWidthMeters();
            float yPxPerM = screen.getHeight() / screen.getHeightMeters();

            eye.getViewport().x      = Math.Round(vp.x * xPxPerM);
            eye.getViewport().y      = Math.Round(vp.y * xPxPerM);
            eye.getViewport().width  = Math.Round(vp.width * xPxPerM);
            eye.getViewport().height = Math.Round(vp.height * xPxPerM);

            return(vp);
        }
Пример #2
0
        public void toPerspectiveMatrix(float near, float far, float[] perspective, int offset)
        {
            if (offset + 16 > perspective.Length)
            {
                throw new Java.Lang.IllegalArgumentException("Not enough space to write the result");
            }

            float l = (float)-Math.Tan(Math.ToRadians(mLeft)) * near;
            float r = (float)Math.Tan(Math.ToRadians(mRight)) * near;
            float b = (float)-Math.Tan(Math.ToRadians(mBottom)) * near;
            float t = (float)Math.Tan(Math.ToRadians(mTop)) * near;

            Matrix.FrustumM(perspective, offset, l, r, b, t, near, far);
        }
Пример #3
0
        //get the distance to the closest stop matematicaly
        private double DistFrom(double latStart, double lngStart, double latEnd, double lngEnd)
        {
            double earthRadius = 3958.75;
            double dLat        = Math.ToRadians(latEnd - latStart);
            double dLng        = Math.ToRadians(lngEnd - lngStart);
            double a           = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                                 Math.Cos(Math.ToRadians(latStart)) * Math.Cos(Math.ToRadians(latEnd)) *
                                 Math.Sin(dLng / 2) * Math.Sin(dLng / 2);
            double c    = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            double dist = earthRadius * c;

            int meterConversion = 1609;

            //using Java.Lang.Double
            return(new JLD(dist * meterConversion).DoubleValue());
        }
Пример #4
0
            public void OnAnchorFound(ARAnchor arAnchor, ARNode arNode)
            {
                // Spawn a visual plane if a PlaneAnchor was found
                if (arAnchor.GetType() == ARAnchor.Type.Plane)
                {
                    var planeAnchor = (ARPlaneAnchor)arAnchor;

                    // Create the visual geometry representing this plane
                    var dimensions = planeAnchor.Extent;
                    var plane      = new ViroCore.Surface(1, 1)
                    {
                        Width = dimensions.X, Height = dimensions.Z
                    };

                    // Set a default material for this plane.
                    var material = new Material {
                        DiffuseColor = Color.ParseColor("#BF000000")
                    };
                    plane.Materials = new List <Material>()
                    {
                        material
                    };

                    // Attach it to the node
                    var planeNode = new Node {
                        Geometry = plane
                    };
                    planeNode.SetRotation(new Vector(-Math.ToRadians(90.0), 0, 0));
                    planeNode.SetPosition(planeAnchor.Center);

                    // Attach this planeNode to the anchor's arNode
                    arNode.AddChildNode(planeNode);
                    surfaces.Add(arAnchor.AnchorId, planeNode);

                    // Attach click listeners to be notified upon a plane onClick.
                    planeNode.Click += (s, e) =>
                    {
                        foreach (var listener in mPlaneClickListeners)
                        {
                            listener.OnClick(e.P0, e.P1, e.P2);
                        }
                    };
                    HideIsTrackingLayoutUi();
                }
            }
Пример #5
0
            public void OnDrawFrame(IGL10 gl)
            {
                if ((mShuttingDown) || (mInvalidSurfaceSize))
                {
                    return;
                }

                ScreenParams          screen = mHmd.getScreen();
                CardboardDeviceParams cdp    = mHmd.getCardboard();

                mView.mHeadTracker.getLastHeadView(mHeadTransform.getHeadView(), 0);

                float halfInterpupillaryDistance = cdp.getInterpupillaryDistance() * 0.5F;

                if (mVRMode)
                {
                    Android.Opengl.Matrix.SetIdentityM(mLeftEyeTranslate, 0);
                    Android.Opengl.Matrix.SetIdentityM(mRightEyeTranslate, 0);

                    Android.Opengl.Matrix.TranslateM(mLeftEyeTranslate, 0, halfInterpupillaryDistance, 0.0F, 0.0F);

                    Android.Opengl.Matrix.TranslateM(mRightEyeTranslate, 0, -halfInterpupillaryDistance, 0.0F, 0.0F);

                    Android.Opengl.Matrix.MultiplyMM(mLeftEye.getTransform().GetEyeView(), 0, mLeftEyeTranslate, 0, mHeadTransform.getHeadView(), 0);

                    Android.Opengl.Matrix.MultiplyMM(mRightEye.getTransform().GetEyeView(), 0, mRightEyeTranslate, 0, mHeadTransform.getHeadView(), 0);
                }
                else
                {
                    //Java.Lang.JavaSystem.Arraycopy(mHeadTransform.getHeadView(), 0, mMonocular.getTransform().GetEyeView(), 0, mHeadTransform.getHeadView().Length);
                    Array.Copy(mHeadTransform.getHeadView(), 0, mMonocular.getTransform().GetEyeView(), 0, mHeadTransform.getHeadView().Length);
                }

                if (mProjectionChanged)
                {
                    mMonocular.getViewport().setViewport(0, 0, screen.getWidth(), screen.getHeight());

                    if (!mVRMode)
                    {
                        float aspectRatio = screen.getWidth() / screen.getHeight();
                        Android.Opengl.Matrix.PerspectiveM(mMonocular.getTransform().GetPerspective(), 0, cdp.getFovY(), aspectRatio, mZNear, mZFar);
                    }
                    else if (mDistortionCorrectionEnabled)
                    {
                        UpdateFieldOfView(mLeftEye.getFov(), mRightEye.getFov());
                        mView.mDistortionRenderer.onProjectionChanged(mHmd, mLeftEye, mRightEye, mZNear, mZFar);
                    }
                    else
                    {
                        float distEyeToScreen = cdp.getVisibleViewportSize() / 2.0F / (float)Math.Tan(Math.ToRadians(cdp.getFovY()) / 2.0D);

                        float left   = screen.getWidthMeters() / 2.0F - halfInterpupillaryDistance;
                        float right  = halfInterpupillaryDistance;
                        float bottom = cdp.getVerticalDistanceToLensCenter() - screen.getBorderSizeMeters();

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

                        FieldOfView leftEyeFov = mLeftEye.getFov();
                        leftEyeFov.setLeft((float)Math.ToDegrees(Math.Atan2(left, distEyeToScreen)));

                        leftEyeFov.setRight((float)Math.ToDegrees(Math.Atan2(right, distEyeToScreen)));

                        leftEyeFov.setBottom((float)Math.ToDegrees(Math.Atan2(bottom, distEyeToScreen)));

                        leftEyeFov.setTop((float)Math.ToDegrees(Math.Atan2(top, distEyeToScreen)));

                        FieldOfView rightEyeFov = mRightEye.getFov();
                        rightEyeFov.setLeft(leftEyeFov.getRight());
                        rightEyeFov.setRight(leftEyeFov.getLeft());
                        rightEyeFov.setBottom(leftEyeFov.getBottom());
                        rightEyeFov.setTop(leftEyeFov.getTop());

                        leftEyeFov.toPerspectiveMatrix(mZNear, mZFar, mLeftEye.getTransform().GetPerspective(), 0);

                        rightEyeFov.toPerspectiveMatrix(mZNear, mZFar, mRightEye.getTransform().GetPerspective(), 0);

                        mLeftEye.getViewport().setViewport(0, 0, screen.getWidth() / 2, screen.getHeight());

                        mRightEye.getViewport().setViewport(screen.getWidth() / 2, 0, screen.getWidth() / 2, screen.getHeight());
                    }

                    mProjectionChanged = false;
                }

                if (mVRMode)
                {
                    if (mDistortionCorrectionEnabled)
                    {
                        mView.mDistortionRenderer.beforeDrawFrame();

                        if (mDistortionCorrectionScale == 1.0F)
                        {
                            mRenderer.OnDrawFrame(mHeadTransform, mLeftEye, mRightEye);
                        }
                        else
                        {
                            int leftX       = mLeftEye.getViewport().x;
                            int leftY       = mLeftEye.getViewport().y;
                            int leftWidth   = mLeftEye.getViewport().width;
                            int leftHeight  = mLeftEye.getViewport().height;
                            int rightX      = mRightEye.getViewport().x;
                            int rightY      = mRightEye.getViewport().y;
                            int rightWidth  = mRightEye.getViewport().width;
                            int rightHeight = mRightEye.getViewport().height;

                            mLeftEye.getViewport().setViewport((int)(leftX * mDistortionCorrectionScale), (int)(leftY * mDistortionCorrectionScale), (int)(leftWidth * mDistortionCorrectionScale), (int)(leftHeight * mDistortionCorrectionScale));

                            mRightEye.getViewport().setViewport((int)(rightX * mDistortionCorrectionScale), (int)(rightY * mDistortionCorrectionScale), (int)(rightWidth * mDistortionCorrectionScale), (int)(rightHeight * mDistortionCorrectionScale));

                            mRenderer.OnDrawFrame(mHeadTransform, mLeftEye, mRightEye);

                            mLeftEye.getViewport().setViewport(leftX, leftY, leftWidth, leftHeight);

                            mRightEye.getViewport().setViewport(rightX, rightY, rightWidth, rightHeight);
                        }

                        mView.mDistortionRenderer.afterDrawFrame();
                    }
                    else
                    {
                        mRenderer.OnDrawFrame(mHeadTransform, mLeftEye, mRightEye);
                    }
                }
                else
                {
                    mRenderer.OnDrawFrame(mHeadTransform, mMonocular, null);
                }

                mRenderer.OnFinishFrame(mMonocular.getViewport());
            }