Ejemplo n.º 1
0
        private void RenderSliceFromTarget(RenderDataForSlice renderData)
        {
            int _pixelsPerDegreeOfViewingAngleFromSourceBitmap = _target1.Width / _widthOfViewingArcInDegrees;
            var sourceRectangle1 = new Rectangle((int)(renderData.CollisionInfo.Value.PositionOnWall * ViewingField.Width), 0, _pixelsPerDegreeOfViewingAngleFromSourceBitmap, ViewingField.Height);

            Game1.SpriteBatch.Draw(_target1, renderData.DestinationRectangle, sourceRectangle1, Color.White);
        }
Ejemplo n.º 2
0
        private void CalculateRenderData()
        {
            float halfWidthOfViewingArcInDegrees          = _widthOfViewingArcInDegrees / 2;
            float absoluteAngleOfLeftMostPeripheralVision = Player.ViewingAngle - halfWidthOfViewingArcInDegrees;

            for (int pixel = 0; pixel < ViewingField.Width; pixel++)
            {
                var           realAngle         = absoluteAngleOfLeftMostPeripheralVision + degreePerPixel * pixel;
                var           angleFromCenter   = Math.Abs(Player.ViewingAngle - realAngle);
                CollisionInfo?collisionPosition = Tiles.GetCollisionPointImproved(Player.Position, realAngle, 100);

                if (!collisionPosition.HasValue)
                {
                    CompleteRenderData[pixel] = null;
                    continue;
                }
                var adjustedDistanceToCollision = collisionPosition.Value.DistanceToCollision * fisheyeCompensations[pixel];
                var destinationHeight           = ViewingField.Height / adjustedDistanceToCollision;

                float percentageOfWidth    = pixel / _widthOfViewingArcInDegrees;
                var   destinationRectangle = new Rectangle(pixel, (int)(Math.Floor((ViewingField.Height - destinationHeight) / 2)),
                                                           1, (int)destinationHeight);

                CompleteRenderData[pixel] = new RenderDataForSlice()
                {
                    CollisionInfo = collisionPosition.Value, DestinationRectangle = destinationRectangle
                };
            }
        }
Ejemplo n.º 3
0
        private void RenderWhiteSlice(RenderDataForSlice renderData)
        {
            var   sourceRectangle1 = new Rectangle(0, 0, 1, 1);
            float maxDistance      = 7;
            float opacity          = (1 - (float)(renderData.CollisionInfo.Value.DistanceToCollision / maxDistance));

            Game1.SpriteBatch.Draw(_white, renderData.DestinationRectangle, sourceRectangle1, Color.White * opacity);
        }
Ejemplo n.º 4
0
        private void RenderSliceForSynchronizedSlideShow(RenderDataForSlice renderData)
        {
            int textureIndex1 = _slideIndex;

            textureIndex1 %= CurrentTextureSet.Length;

            int textureIndex2 = (textureIndex1 + 1) % CurrentTextureSet.Length;

            RenderSliceForSlideShow(renderData, textureIndex1, textureIndex2);
        }
Ejemplo n.º 5
0
        private void RenderSliceForIndividualSlideShow(RenderDataForSlice renderData)
        {
            int textureIndex1 = renderData.CollisionInfo.Value.TileHitValue - 1 + _slideIndex;

            textureIndex1 %= CurrentTextureSet.Length;

            int textureIndex2 = (textureIndex1 + 1) % CurrentTextureSet.Length;

            RenderSliceForSlideShow(renderData, textureIndex1, textureIndex2);
        }
Ejemplo n.º 6
0
        private void RenderSlice(RenderDataForSlice renderData)
        {
            //TODO: find out whether sharper viewing angle  should result in thinner sourceRectangles
            //for optimal rendering?
            int textureIndex1 = renderData.CollisionInfo.Value.TileHitValue - 1;

            textureIndex1 %= CurrentTextureSet.Length;
            int _pixelsPerDegreeOfViewingAngleFromSourceBitmap = CurrentTextureSet[textureIndex1].CurrentTexture.Width / _widthOfViewingArcInDegrees;
            var sourceRectangle1 = new Rectangle((int)(renderData.CollisionInfo.Value.PositionOnWall * CurrentTextureSet[textureIndex1].CurrentTexture.Width), 0, _pixelsPerDegreeOfViewingAngleFromSourceBitmap, CurrentTextureSet[textureIndex1].CurrentTexture.Height);

            Game1.SpriteBatch.Draw(CurrentTextureSet[textureIndex1].CurrentTexture, renderData.DestinationRectangle, sourceRectangle1, Color.White);
        }
Ejemplo n.º 7
0
        private void RenderSliceWithDistanceBasedLighting(RenderDataForSlice renderData)
        {
            int textureIndex1 = renderData.CollisionInfo.Value.TileHitValue - 1;

            textureIndex1 %= CurrentTextureSet.Length;
            int   _pixelsPerDegreeOfViewingAngleFromSourceBitmap = CurrentTextureSet[textureIndex1].CurrentTexture.Width / _widthOfViewingArcInDegrees;
            var   sourceRectangle1 = new Rectangle((int)(renderData.CollisionInfo.Value.PositionOnWall * CurrentTextureSet[textureIndex1].CurrentTexture.Width), 0, _pixelsPerDegreeOfViewingAngleFromSourceBitmap, CurrentTextureSet[textureIndex1].CurrentTexture.Height);
            float maxDistance      = 7;
            float opacity          = 0;

            if (renderData.CollisionInfo.Value.DistanceToCollision < maxDistance)
            {
                opacity = 1 - (float)Math.Pow((float)(renderData.CollisionInfo.Value.DistanceToCollision / maxDistance), 2);
            }
            Game1.SpriteBatch.Draw(CurrentTextureSet[textureIndex1].CurrentTexture, renderData.DestinationRectangle, sourceRectangle1, Color.White * opacity);
        }
Ejemplo n.º 8
0
        private void RenderSliceForSlideShow(RenderDataForSlice renderData, int textureIndex1, int textureIndex2)
        {
            int _pixelsPerDegreeOfViewingAngleFromSourceBitmap1 = CurrentTextureSet[textureIndex1].CurrentTexture.Width / _widthOfViewingArcInDegrees;

            int _pixelsPerDegreeOfViewingAngleFromSourceBitmap2 = CurrentTextureSet[textureIndex2].CurrentTexture.Width / _widthOfViewingArcInDegrees;
            var sourceRectangle1 = new Rectangle((int)(renderData.CollisionInfo.Value.PositionOnWall * CurrentTextureSet[textureIndex1].CurrentTexture.Width), 0, _pixelsPerDegreeOfViewingAngleFromSourceBitmap1, CurrentTextureSet[textureIndex1].CurrentTexture.Height);
            var sourceRectangle2 = new Rectangle((int)(renderData.CollisionInfo.Value.PositionOnWall * CurrentTextureSet[textureIndex2].CurrentTexture.Width), 0, _pixelsPerDegreeOfViewingAngleFromSourceBitmap2, CurrentTextureSet[textureIndex2].CurrentTexture.Height);

            float transparency = _msForNextSlide / _msBetweenSlides;

            transparency = QuinticEaseInOut(transparency);
            float maxDistance = 7;
            float opacity     = (1 - (float)(renderData.CollisionInfo.Value.DistanceToCollision / maxDistance));

            Game1.SpriteBatch.Draw(CurrentTextureSet[textureIndex1].CurrentTexture, renderData.DestinationRectangle, sourceRectangle1, Color.White);
            Game1.SpriteBatch.Draw(CurrentTextureSet[textureIndex2].CurrentTexture, renderData.DestinationRectangle, sourceRectangle2, Color.White * (1 - transparency));
        }
Ejemplo n.º 9
0
        private void RenderSliceWithGlide(RenderDataForSlice renderData)
        {
            int textureIndex1 = renderData.CollisionInfo.Value.TileHitValue - 1;

            textureIndex1 %= CurrentTextureSet.Length;
            int       _pixelsPerDegreeOfViewingAngleFromSourceBitmap = CurrentTextureSet[textureIndex1].CurrentTexture.Width / _widthOfViewingArcInDegrees;
            var       currentTexture = CurrentTextureSet[textureIndex1].CurrentTexture;
            Rectangle source;
            float     offset = _msForNextSlide / _msBetweenSlides;

            offset = QuinticEaseInOut((float)Math.Abs(offset * 2 - 1));
            if (currentTexture.Width > currentTexture.Height)
            {
                float lengthToGlide = currentTexture.Width - currentTexture.Height;
                source = new Rectangle((int)(renderData.CollisionInfo.Value.PositionOnWall * currentTexture.Height + offset * lengthToGlide), 0, _pixelsPerDegreeOfViewingAngleFromSourceBitmap, currentTexture.Height);
            }
            else
            {
                float lengthToGlide = currentTexture.Height - currentTexture.Width;
                source = new Rectangle((int)(renderData.CollisionInfo.Value.PositionOnWall * currentTexture.Width), (int)(offset * lengthToGlide), _pixelsPerDegreeOfViewingAngleFromSourceBitmap, currentTexture.Width);
            }

            Game1.SpriteBatch.Draw(CurrentTextureSet[textureIndex1].CurrentTexture, renderData.DestinationRectangle, source, Color.White);
        }