コード例 #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));
            }
コード例 #2
0
ファイル: So3Util.cs プロジェクト: secile/CardboardXamarin
        public static void sO3FromMu(Vector3d w, Matrix3x3d result)
        {
            double thetaSq = Vector3d.dot(w, w);
            double theta = Math.Sqrt(thetaSq);
            double kA, kB;

            if (thetaSq < 1.0E-08D)
            {
                kA = 1.0D - 0.16666667163372D * thetaSq;
                kB = 0.5D;
            }
            else
            {
                if (thetaSq < 1.0E-06D)
                {
                    kB = 0.5D - 0.0416666679084301D * thetaSq;
                    kA = 1.0D - thetaSq * 0.16666667163372D * (1.0D - 0.16666667163372D * thetaSq);
                }
                else
                {
                    double invTheta = 1.0D / theta;
                    kA = Math.Sin(theta) * invTheta;
                    kB = (1.0D - Math.Cos(theta)) * (invTheta * invTheta);
                }
            }
            rodriguesSo3Exp(w, kA, kB, result);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Arc.cs プロジェクト: willvin313/mobileapp
        public void OnDraw(Canvas canvas)
        {
            var startAngleInDegrees = Math.ToDegrees(startAngle);
            var endStrokeInDegrees  = Math.ToDegrees(endStroke);

            canvas.DrawArc(bounds, (float)startAngleInDegrees, (float)endStrokeInDegrees, false, paint);
        }
コード例 #5
0
ファイル: CompassImpl.cs プロジェクト: shinyorg/shiny
        void Calc(IObserver <CompassReading> ob)
        {
            if (this.lastMag == null || this.lastAccel == null)
            {
                return;
            }

            SensorManager.GetRotationMatrix(this.rMatrix, null, this.lastAccel.Values.ToArray(), this.lastMag.Values.ToArray());
            SensorManager.GetOrientation(this.rMatrix, this.orientation);
            var degrees = (Math.ToDegrees(this.orientation[0]) + 360) % 360;

            var accuracy = this.lastAccel.Accuracy switch
            {
                SensorStatus.AccuracyHigh => CompassAccuracy.High,
                SensorStatus.AccuracyLow => CompassAccuracy.Approximate,
                SensorStatus.Unreliable => CompassAccuracy.Unreliable,
                _ => CompassAccuracy.Unknown
            };

            // TODO: calculate true north
            ob.OnNext(new CompassReading(accuracy, degrees, null));

            // clear for fresh read
            this.lastMag   = null;
            this.lastAccel = null;
        }
    }
コード例 #6
0
 protected override void  onLoadingDrawableSet(Drawable imageDrawable)
 {
     if (null != imageDrawable)
     {
         mRotationPivotX = Math.Round(imageDrawable.IntrinsicWidth / 2f);
         mRotationPivotY = Math.Round(imageDrawable.IntrinsicHeight / 2f);
     }
 }
コード例 #7
0
        protected internal override void OnZap(int cell)
        {
            var terrainAffected = false;

            var localLevel = Level;

            var maxDistance = Distance();

            Ballistica.Distance = Math.Min(Ballistica.Distance, maxDistance);

            var chars = new List <Character>();

            for (var i = 1; i < Ballistica.Distance; i++)
            {
                var c = Ballistica.Trace[i];

                Character ch;
                if ((ch = Actor.FindChar(c)) != null)
                {
                    chars.Add(ch);
                }

                var terr = Dungeon.Level.map[c];
                switch (terr)
                {
                case Terrain.BARRICADE:
                case Terrain.DOOR:
                    levels.Level.Set(c, Terrain.EMBERS);
                    GameScene.UpdateMap(c);
                    terrainAffected = true;
                    break;

                case Terrain.HIGH_GRASS:
                    levels.Level.Set(c, Terrain.GRASS);
                    GameScene.UpdateMap(c);
                    terrainAffected = true;
                    break;
                }

                CellEmitter.Center(c).Burst(PurpleParticle.Burst, pdsharp.utils.Random.IntRange(1, 2));
            }

            if (terrainAffected)
            {
                Dungeon.Observe();
            }

            var lvl    = localLevel + chars.Count;
            var dmgMin = lvl;
            var dmgMax = 8 + lvl * lvl / 3;

            foreach (var ch in chars)
            {
                ch.Damage(pdsharp.utils.Random.NormalIntRange(dmgMin, dmgMax), this);
                ch.Sprite.CenterEmitter().Burst(PurpleParticle.Burst, pdsharp.utils.Random.IntRange(1, 2));
                ch.Sprite.Flash();
            }
        }
コード例 #8
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            _viewWidth  = MeasureSpec.GetSize(widthMeasureSpec);
            _viewHeight = MeasureSpec.GetSize(heightMeasureSpec);

            // Rescales image on rotation
            if (_oldMeasuredHeight == _viewWidth && _oldMeasuredHeight == _viewHeight || _viewWidth == 0 || _viewHeight == 0)
            {
                return;
            }

            _oldMeasuredHeight = _viewHeight;
            _oldMeasuredWidth  = _viewWidth;

            if (System.Math.Abs(_saveScale - 1) < Tolerance)
            {
                //Fit to screen.

                if (Drawable == null || Drawable.IntrinsicWidth == 0 || Drawable.IntrinsicHeight == 0)
                {
                    return;
                }

                var bmWidth  = Drawable.IntrinsicWidth;
                var bmHeight = Drawable.IntrinsicHeight;

                Debug.WriteLine($"bmWidth: {bmWidth } bmHeight : {bmHeight}");


                var scaleX = _viewWidth / (float)bmWidth;
                var scaleY = _viewHeight / (float)bmHeight;

                var scale = Math.Min(scaleX, scaleY);
                _matrix.SetScale(scale, scale);

                // Center the image
                var xspacedinges = scale * bmWidth;

                var redundantYSpace = _viewHeight - scale * bmHeight;
                var redundantXSpace = _viewWidth - xspacedinges;

                redundantYSpace /= 2;
                redundantXSpace /= 2;

                _matrix.PostTranslate(redundantXSpace, redundantYSpace);

                OrigWidth = _viewWidth - 2 * redundantXSpace;

                OrigHeight = _viewHeight - 2 * redundantYSpace;

                ImageMatrix = _matrix;
            }

            FixTrans();
        }
コード例 #9
0
        private int GetClippedWidth(int viewHolderWidth, float dX, int measured)
        {
            if (viewHolderWidth <= 0)
            {
                return(0);
            }

            return(Math.Min(measured, (int)Math.Ceil(Math.Abs(dX))));
        }
コード例 #10
0
            private float computeMinimum(float[] offsets)
            {
                float min = (1.0F / 1.0F);

                foreach (var o in offsets)
                {
                    min = Math.Min(o, min);
                }
                return(min);
            }
コード例 #11
0
        public void Update(double startTimeAngle, double endTimeAngle)
        {
            var startAngle    = (float)startTimeAngle;
            var endAngle      = (float)endTimeAngle;
            var diffAngle     = endAngle - startAngle + (endAngle < startAngle ? FullCircle : 0);
            var diffInDegrees = (float)Math.ToDegrees(diffAngle);

            hidden   = diffInDegrees < visibilityThresholdInDegrees;
            position = PointOnCircumference(pivotCenter, startAngle + diffAngle / 2f, distanceToPivot).ToPointF();
        }
コード例 #12
0
            private float computeMaximum(float[] offsets)
            {
                float max = (1.0F / -1.0F);

                foreach (var o in offsets)
                {
                    max = Math.Max(o, max);
                }
                return(max);
            }
コード例 #13
0
 private float[] computeOffsets(int start, float[] baseline)
 {
     for (int i = 0; i < SEGMENT_SIZE; i++)
     {
         float[] point     = (float[])mSensorData[start + i];
         float[] o         = { point[0] - baseline[0], point[1] - baseline[1], point[2] - baseline[2] };
         float   magnitude = (float)Math.Sqrt(o[0] * o[0] + o[1] * o[1] + o[2] * o[2]);
         mOffsets[i] = magnitude;
     }
     return(mOffsets);
 }
コード例 #14
0
        public /*synchronized*/ void setHeadingDegrees(double heading)
        {
            double currentHeading = getHeadingDegrees();
            double deltaHeading   = heading - currentHeading;
            double s = Math.Sin(deltaHeading / 180.0D * 3.141592653589793D);
            double c = Math.Cos(deltaHeading / 180.0D * 3.141592653589793D);

            double[][] deltaHeadingRotationVals = new double[][] { new[] { c, -s, 0.0D }, new[] { s, c, 0.0D }, new[] { 0.0D, 0.0D, 1.0D } };

            arrayAssign(deltaHeadingRotationVals, setHeadingDegreesTempM1);
            Matrix3x3d.mult(so3SensorFromWorld, setHeadingDegreesTempM1, so3SensorFromWorld);
        }
コード例 #15
0
        public bool OnTouch(View v, MotionEvent e)
        {
            _scaleDetector.OnTouchEvent(e);

            PointF curr = new PointF(e.GetX(), e.GetY());

            switch (e.Action)
            {
            case MotionEventActions.Down:

                _last.Set(curr);

                _start.Set(_last);

                _mode = Dragging;

                break;

            case MotionEventActions.Move:
                if (_mode == Dragging)
                {
                    float deltaX    = curr.X - _last.X;
                    float deltaY    = curr.Y - _last.Y;
                    float fixTransX = GetFixDragTrans(deltaX, _viewWidth, OrigWidth * _saveScale);
                    float fixTransY = GetFixDragTrans(deltaY, _viewHeight, OrigHeight * _saveScale);
                    Matrix.PostTranslate(fixTransX, fixTransY);
                    FixTrans();
                    _last.Set(curr.X, curr.Y);
                }

                break;

            case MotionEventActions.Up:
                _mode = None;
                var xDiff = (int)Math.Abs(curr.X - _start.X);
                var yDiff = (int)Math.Abs(curr.Y - _start.Y);
                if (xDiff < Clicking && yDiff < Clicking)
                {
                    PerformClick();
                }
                break;

            case MotionEventActions.PointerUp:
                _mode = None;
                break;
            }

            ImageMatrix = _matrix;

            Invalidate();

            return(true); // indicate event was handled
        }
コード例 #16
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);
        }
コード例 #17
0
ファイル: So3Util.cs プロジェクト: secile/CardboardXamarin
        public static void muFromSO3(Matrix3x3d so3, Vector3d result)
        {
            double cosAngle = (so3.get(0, 0) + so3.get(1, 1) + so3.get(2, 2) - 1.0D) * 0.5D;

            result.set((so3.get(2, 1) - so3.get(1, 2)) / 2.0D, (so3.get(0, 2) - so3.get(2, 0)) / 2.0D, (so3.get(1, 0) - so3.get(0, 1)) / 2.0D);

            double sinAngleAbs = result.length();

            if (cosAngle > M_SQRT1_2)
            {
                if (sinAngleAbs > 0.0D)
                {
                    result.scale(Math.Asin(sinAngleAbs) / sinAngleAbs);
                }
            }
            else if (cosAngle > -M_SQRT1_2)
            {
                double angle = Math.Acos(cosAngle);
                result.scale(angle / sinAngleAbs);
            }
            else
            {
                double angle = 3.141592653589793D - Math.Asin(sinAngleAbs);
                double d0    = so3.get(0, 0) - cosAngle;
                double d1    = so3.get(1, 1) - cosAngle;
                double d2    = so3.get(2, 2) - cosAngle;

                Vector3d r2 = muFromSO3R2;
                if ((d0 * d0 > d1 * d1) && (d0 * d0 > d2 * d2))
                {
                    r2.set(d0, (so3.get(1, 0) + so3.get(0, 1)) / 2.0D, (so3.get(0, 2) + so3.get(2, 0)) / 2.0D);
                }
                else if (d1 * d1 > d2 * d2)
                {
                    r2.set((so3.get(1, 0) + so3.get(0, 1)) / 2.0D, d1, (so3.get(2, 1) + so3.get(1, 2)) / 2.0D);
                }
                else
                {
                    r2.set((so3.get(0, 2) + so3.get(2, 0)) / 2.0D, (so3.get(2, 1) + so3.get(1, 2)) / 2.0D, d2);
                }

                if (Vector3d.dot(r2, result) < 0.0D)
                {
                    r2.scale(-1.0D);
                }
                r2.normalize();
                r2.scale(angle);
                result.set(r2);
            }
        }
コード例 #18
0
            public static IEnumerable <byte> Resample(byte[] samples, int fromSampleRate, int toSampleRate, int quality = 10)
            {
                int srcLength  = samples.Length;
                var destLength = (long)samples.Length * toSampleRate / fromSampleRate;
                var dx         = srcLength / destLength;

                // fmax : nyqist half of destination sampleRate
                // fmax / fsr = 0.5;
                var fmaxDivSR = 0.5;
                var r_g       = 2 * fmaxDivSR;

                // Quality is half the window width
                var wndWidth2 = quality;
                var wndWidth  = quality * 2;

                var    x = 0;
                int    i, j;
                double r_y;
                int    tau;
                double r_w;
                double r_a;
                double r_snc;

                for (i = 0; i < destLength; ++i)
                {
                    r_y = 0.0;
                    for (tau = -wndWidth2; tau < wndWidth2; ++tau)
                    {
                        // input sample index
                        j = x + tau;

                        // Hann Window. Scale and calculate sinc
                        r_w   = 0.5 - 0.5 * Math.Cos(2 * Math.Pi * (0.5 + (j - x) / wndWidth));
                        r_a   = 2 * Math.Pi * (j - x) * fmaxDivSR;
                        r_snc = 1.0;
                        if (r_a != 0)
                        {
                            r_snc = Math.Sin(r_a) / r_a;
                        }

                        if ((j >= 0) && (j < srcLength))
                        {
                            r_y += r_g * r_w * r_snc * samples[j];
                        }
                    }
                    yield return((byte)r_y);

                    x += (int)dx;
                }
            }
コード例 #19
0
        protected override void onPullImpl(float scaleOfLayout)
        {
            float angle;

            if (mRotateDrawableWhilePulling)
            {
                angle = scaleOfLayout * 90f;
            }
            else
            {
                angle = Math.Max(0f, Math.Min(180f, scaleOfLayout * 360f - 180f));
            }

            mHeaderImageMatrix.SetRotate(angle, mRotationPivotX, mRotationPivotY);
            mHeaderImage.ImageMatrix = mHeaderImageMatrix;
        }
コード例 #20
0
        //public static Task<Bitmap> DecodeBitmapAsync(string path,  int desiredWidth, int desiredHeight)
        // {
        //     return Task.Factory.StartNew(() => DecodeBitmap(path, desiredSize));
        // }

        public static Bitmap DecodeStream(Stream stream, int width, int height, int desiredWidth, int desiredHeight)
        {
            var sampleSize = 1;

            if (height > desiredHeight || width > desiredWidth)
            {
                var heightRatio = Math.Round(height / (float)desiredHeight);
                var widthRatio  = Math.Round(width / (float)desiredWidth);
                sampleSize = Math.Min(heightRatio, widthRatio);
            }
            var options = new BitmapFactory.Options {
                InSampleSize = sampleSize
            };

            return(BitmapFactory.DecodeStream(stream, null, options));
        }
コード例 #21
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());
        }
コード例 #22
0
        public float distortInverse(float radius)
        {
            float r0 = radius / 0.9F;
            float r1 = radius * 0.9F;

            float dr0 = radius - distort(r0);

            while (Math.Abs(r1 - r0) > 0.0001D)
            {
                float dr1 = radius - distort(r1);
                float r2  = r1 - dr1 * ((r1 - r0) / (dr1 - dr0));
                r0  = r1;
                r1  = r2;
                dr0 = dr1;
            }
            return(r1);
        }
コード例 #23
0
ファイル: MainActivity.cs プロジェクト: xracer007/ViroXamarin
            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();
                }
            }
コード例 #24
0
ファイル: CompassImpl.cs プロジェクト: gcardinale/shiny
        void Calc(IObserver <CompassReading> ob)
        {
            if (this.lastMag == null || this.lastAccel == null)
            {
                return;
            }

            SensorManager.GetRotationMatrix(this.rMatrix, null, this.lastAccel, this.lastMag);
            SensorManager.GetOrientation(this.rMatrix, this.orientation);
            var degrees = (Math.ToDegrees(this.orientation[0]) + 360) % 360;

            // TODO: get compass accuracy
            // TODO: calculate true north
            ob.OnNext(new CompassReading(CompassAccuracy.Approximate, degrees, null));

            // clear for fresh read
            this.lastMag   = null;
            this.lastAccel = null;
        }
コード例 #25
0
        private RemoteViews BuildUpdate(Context context, int[] appWidgetIds)
        {
            RemoteViews updateViews = new RemoteViews(context.PackageName, Resource.Layout.widget);

            Intent i = new Intent(context, typeof(AppWidget));

            i.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            i.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            PendingIntent pi = PendingIntent.GetBroadcast(context, 0, i, PendingIntentFlags.UpdateCurrent);

            updateViews.SetImageViewResource(Resource.Id.left_die, IMAGES[(int)(Math.Random() * 6)]);
            updateViews.SetOnClickPendingIntent(Resource.Id.left_die, pi);

            updateViews.SetImageViewResource(Resource.Id.right_die, IMAGES[(int)(Math.Random() * 6)]);
            updateViews.SetOnClickPendingIntent(Resource.Id.right_die, pi);

            updateViews.SetOnClickPendingIntent(Resource.Id.background, pi);

            return(updateViews);
        }
コード例 #26
0
ファイル: Vector3d.cs プロジェクト: secile/CardboardXamarin
        public static int largestAbsComponent(Vector3d v)
        {
            double xAbs = Math.Abs(v.x);
            double yAbs = Math.Abs(v.y);
            double zAbs = Math.Abs(v.z);

            if (xAbs > yAbs)
            {
                if (xAbs > zAbs)
                {
                    return(0);
                }
                return(2);
            }

            if (yAbs > zAbs)
            {
                return(1);
            }
            return(2);
        }
コード例 #27
0
        public override void OnChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX,
                                         float dY, int actionState, bool isCurrentlyActive)
        {
            var measuredsize = GetMeasuredSize(GetContainerArea(dX), viewHolder);

            if (measuredsize.width <= 0 || measuredsize.height <= 0)
            {
                return;
            }

            var clippedX = dX >= 0 ? Math.Min(dX, measuredsize.width) : Math.Max(dX, -measuredsize.width);

            if (actionState == ItemTouchHelper.ActionStateSwipe)
            {
                if (_currentSwipeState != SwipeState.Default)
                {
                    if (_currentSwipeState == SwipeState.LeftOpen)
                    {
                        clippedX = Math.Max(clippedX, measuredsize.width);
                    }
                    if (_currentSwipeState == SwipeState.RightOpen)
                    {
                        clippedX = Math.Min(clippedX, -measuredsize.width);
                    }

                    base.OnChildDraw(c, recyclerView, viewHolder, clippedX, dY, actionState, isCurrentlyActive);
                }
                else
                {
                    SetTouchListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
                }
            }

            if (_currentSwipeState == SwipeState.Default)
            {
                base.OnChildDraw(c, recyclerView, viewHolder, clippedX, dY, actionState, isCurrentlyActive);
            }

            DrawButtons(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive, _currentSwipeState, false);
        }
コード例 #28
0
        // Expand the FAB so that it takes up the whole screen.
        // The argument viewContentToDisplay will be displayed as content.
        // The view is automatically hidden when the user clicks back.
        public void ExpandFabToOverlayView(View viewContentToDisplay)
        {
            Activity.Window.AddFlags(WindowManagerFlags.Fullscreen);

            var fabOverlayView = Activity.FindViewById <ViewGroup>(Resource.Id.fab_overlay_content);

            fabOverlayView.RemoveAllViews();
            fabOverlayView.SetBackgroundColor(Activity.Fab.FabColor);
            fabOverlayView.Visibility = ViewStates.Visible;
            fabOverlayView.AddView(viewContentToDisplay);

            var cx = (Activity.Fab.Left + Activity.Fab.Right) / 2;
            var cy = (Activity.Fab.Top + Activity.Fab.Bottom) / 2;

            var finalRadius = Math.Max(fabOverlayView.Width, fabOverlayView.Height) * 1.5;

            var anim = XamarinViewAnimationUtils.CreateCircularReveal(fabOverlayView, cx, cy, 0, (float)finalRadius);

            anim.SetInterpolator(new AccelerateDecelerateInterpolator());
            anim.SetDuration(750);
            anim.Start();
        }
コード例 #29
0
        public void onProjectionChanged(HeadMountedDisplay hmd, EyeParams leftEye, EyeParams rightEye, float zNear, float zFar)
        {
            mHmd         = new HeadMountedDisplay(hmd);
            mLeftEyeFov  = new FieldOfView(leftEye.getFov());
            mRightEyeFov = new FieldOfView(rightEye.getFov());

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

            if (mProgramHolder == null)
            {
                mProgramHolder = createProgramHolder();
            }

            EyeViewport leftEyeViewport  = initViewportForEye(leftEye, 0.0F);
            EyeViewport rightEyeViewport = initViewportForEye(rightEye, leftEyeViewport.width);

            leftEye.getFov().toPerspectiveMatrix(zNear, zFar, leftEye.getTransform().GetPerspective(), 0);

            rightEye.getFov().toPerspectiveMatrix(zNear, zFar, rightEye.getTransform().GetPerspective(), 0);

            float textureWidthM   = leftEyeViewport.width + rightEyeViewport.width;
            float textureHeightM  = Math.Max(leftEyeViewport.height, rightEyeViewport.height);
            float xPxPerM         = screen.getWidth() / screen.getWidthMeters();
            float yPxPerM         = screen.getHeight() / screen.getHeightMeters();
            int   textureWidthPx  = Math.Round(textureWidthM * xPxPerM);
            int   textureHeightPx = Math.Round(textureHeightM * yPxPerM);

            float xEyeOffsetMScreen = screen.getWidthMeters() / 2.0F - cdp.getInterpupillaryDistance() / 2.0F;
            float yEyeOffsetMScreen = cdp.getVerticalDistanceToLensCenter() - screen.getBorderSizeMeters();

            mLeftEyeDistortionMesh = createDistortionMesh(leftEye, leftEyeViewport, textureWidthM, textureHeightM, xEyeOffsetMScreen, yEyeOffsetMScreen);

            xEyeOffsetMScreen       = screen.getWidthMeters() - xEyeOffsetMScreen;
            mRightEyeDistortionMesh = createDistortionMesh(rightEye, rightEyeViewport, textureWidthM, textureHeightM, xEyeOffsetMScreen, yEyeOffsetMScreen);

            setupRenderTextureAndRenderbuffer(textureWidthPx, textureHeightPx);
        }
コード例 #30
0
        public double getHeadingDegrees()
        {
            double x   = so3SensorFromWorld.get(2, 0);
            double y   = so3SensorFromWorld.get(2, 1);
            double mag = Math.Sqrt(x * x + y * y);

            if (mag < 0.1D)
            {
                return(0.0D);
            }

            double heading = -90.0D - Math.Atan2(y, x) / 3.141592653589793D * 180.0D;

            if (heading < 0.0D)
            {
                heading += 360.0D;
            }
            if (heading >= 360.0D)
            {
                heading -= 360.0D;
            }
            return(heading);
        }