Example #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));
            }
        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();
            }
        }
        private int GetClippedWidth(int viewHolderWidth, float dX, int measured)
        {
            if (viewHolderWidth <= 0)
            {
                return(0);
            }

            return(Math.Min(measured, (int)Math.Ceil(Math.Abs(dX))));
        }
Example #4
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();
        }
Example #5
0
            private float computeMinimum(float[] offsets)
            {
                float min = (1.0F / 1.0F);

                foreach (var o in offsets)
                {
                    min = Math.Min(o, min);
                }
                return(min);
            }
        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;
        }
Example #7
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));
        }
        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);
        }
Example #9
0
        public static Bitmap DecodeBitmap(string path, int desiredWidth, int desiredHeight)
        {
            var options = new BitmapFactory.Options {
                InJustDecodeBounds = true
            };

            BitmapFactory.DecodeFile(path, options);

            var height = options.OutHeight;
            var width  = options.OutWidth;

            var sampleSize = 1;

            if (height > desiredHeight || width > desiredWidth)
            {
                var heightRatio = (int)Math.Round((float)height / (float)desiredHeight);
                var widthRatio  = (int)Math.Round((float)width / (float)desiredWidth);
                sampleSize = Math.Min(heightRatio, widthRatio);
            }
            options = new BitmapFactory.Options {
                InSampleSize = sampleSize
            };
            return(BitmapFactory.DecodeFile(path, options));
        }
 protected internal override void Fx(int cell, ICallback callback)
 {
     cell = Ballistica.Trace[Math.Min(Ballistica.Distance, Distance()) - 1];
     CurUser.Sprite.Parent.Add(new DeathRay(CurUser.Sprite.Center(), DungeonTilemap.TileCenterToWorld(cell)));
     callback.Call();
 }
 private static float clamp(float val, float min, float max)
 {
     return(Math.Max(min, Math.Min(max, val)));
 }