Exemplo n.º 1
0
        private void PerformClampCameraActivity()
        {
            float cameraLeft  = mainCamera.AbsoluteLeftXEdgeAt(0);
            float cameraRight = mainCamera.AbsoluteRightXEdgeAt(0);

            float cameraTop    = mainCamera.AbsoluteTopYEdgeAt(0);
            float cameraBottom = mainCamera.AbsoluteBottomYEdgeAt(0);

            if (cameraLeft < cameraLeftXBound)
            {
                this.X += cameraLeftXBound - cameraLeft;
            }
            else if (cameraRight > cameraRightXBound)
            {
                this.X += cameraRightXBound - cameraRight;
            }

            if (cameraTop > cameraTopYBound)
            {
                this.Y += cameraTopYBound - cameraTop;
            }
            else if (cameraBottom < cameraBottomYBound)
            {
                this.Y += cameraBottomYBound - cameraBottom;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the desired coordinates according to the input.  The two
        /// values are expected to be percent values.  Due to FRB's unique
        /// coordinate system for normal objects (center of screen at start
        /// is 0,0), the percentage values provided may not perform as initally
        /// expected.  An X value of 50 will actually put the object approx
        /// 25% from the top of the screen and 75% from the bottom.
        /// </summary>
        /// <param name="x">The distance from the center to the edge of the
        /// screen in percentage form (e.g. 50 = half way to the right)</param>
        /// <param name="y">The distance from the center to the edge of the
        /// screen in percentage form (e.g. 50 = half way to the top)</param>
        /// <returns></returns>
        public static Vector2 percentToCoordSprite(float x, float y)
        {
            Camera camera = SpriteManager.Camera;
            float  right  = camera.AbsoluteRightXEdgeAt(0);
            float  left   = camera.AbsoluteLeftXEdgeAt(0);
            float  top    = camera.AbsoluteTopYEdgeAt(0);
            float  bottom = camera.AbsoluteBottomYEdgeAt(0);
            float  width  = Math.Abs(right - left);
            float  height = Math.Abs(bottom - top);

            Vector2 retVal = new Vector2();

            retVal.X = camera.X + (width / 2 * x / 100);
            retVal.Y = camera.Y + (height / 2 * y / 100);
            return(retVal);
        }
Exemplo n.º 3
0
        private void GetRenderingIndexValues(Camera camera, out int firstVertIndex, out int lastVertIndex, out int indexStart, out int numberOfTriangles)
        {
            firstVertIndex = 0;

            lastVertIndex = mVertices.Length;


            float tileWidth = mVertices[1].Position.X - mVertices[0].Position.X;

            if (mSortAxis == SortAxis.X)
            {
                float minX = camera.AbsoluteLeftXEdgeAt(this.Z);
                float maxX = camera.AbsoluteRightXEdgeAt(this.Z);

                minX -= this.X;
                maxX -= this.X;

                firstVertIndex = GetFirstAfterX(mVertices, minX - tileWidth);
                lastVertIndex  = GetFirstAfterX(mVertices, maxX) + 4;
            }
            else if (mSortAxis == SortAxis.Y)
            {
                float minY = camera.AbsoluteBottomYEdgeAt(this.Z);
                float maxY = camera.AbsoluteTopYEdgeAt(this.Z);

                minY -= this.Y;
                maxY -= this.Y;

                firstVertIndex = GetFirstAfterY(mVertices, minY - tileWidth);
                lastVertIndex  = GetFirstAfterY(mVertices, maxY) + 4;
            }

            lastVertIndex = System.Math.Min(lastVertIndex, mVertices.Length);

            indexStart = 0;// (firstVertIndex * 3) / 2;
            int indexEndExclusive = ((lastVertIndex - firstVertIndex) * 3) / 2;

            numberOfTriangles = (indexEndExclusive - indexStart) / 3;
        }
Exemplo n.º 4
0
        private void DrawWorld(Camera camera)
        {
            bool shouldExecute = true;

#if DEBUG
            shouldExecute = DebuggingVariables.RenderWithNoShaders == false;
#endif
            if (shouldExecute)
            {
                var destinationRectangle = camera.DestinationRectangle;

                // All render targets are sized to match the camera's destination rectangle, so we don't need to perform
                // any offsets to account for weird aspect ratios. In other words, the render target resolution matches the
                // desired aspect ratio, guaranteed, so we 0-out the offset values (X and Y). See explanation below on when destinationRectangle
                // is re-assigned.
                destinationRectangle.X = 0;
                destinationRectangle.Y = 0;

                Effect.Parameters["CameraHeight"].SetValue(Camera.Main.OrthogonalHeight);

                float rightX = camera.AbsoluteRightXEdgeAt(Viewer.Z);
                float leftX  = camera.AbsoluteLeftXEdgeAt(Viewer.Z);

                float bottomY = camera.AbsoluteBottomYEdgeAt(Viewer.Z);
                float topY    = camera.AbsoluteTopYEdgeAt(Viewer.Z);

                float ratioX = (Viewer.X - leftX) / (rightX - leftX);
                float ratioY = 1 - (Viewer.Y - bottomY) / (topY - bottomY);


                Effect.Parameters["ViewerX"].SetValue(ratioX);
                Effect.Parameters["ViewerY"].SetValue(ratioY);
                Effect.Parameters["CameraTop"].SetValue(topY);
                Effect.Parameters["DisplacementTextureOffset"].SetValue((float)TimeManager.CurrentTime / DisplacementVelocity);
                // divide by 2 to account for the focus being applied center-out
                Effect.Parameters["FocusArea"].SetValue(FocusedRatio / 2.0f);

                FlatRedBallServices.GraphicsDevice.Textures[1] = WavyTexture;
                FlatRedBallServices.GraphicsDevice.Textures[2] = DisplacementRenderTarget;

                Effect.CurrentTechnique = Effect.Techniques["DistanceBlurTechnique"];
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
                                  SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone,
                                  Effect);

                FlatRedBallServices.GraphicsDevice.SetRenderTarget(DisplacementRenderTarget);

                spriteBatch.Draw(WorldTexture, destinationRectangle, Color.White);
                FlatRedBallServices.GraphicsDevice.SetRenderTarget(null);

                spriteBatch.End();

                FlatRedBallServices.GraphicsDevice.Textures[1] = null;
                FlatRedBallServices.GraphicsDevice.Textures[2] = null;

                FlatRedBallServices.GraphicsDevice.SetRenderTarget(null);

                // This last draw call renders to the screen (note the render target is null), so the offsets do need to
                // be applied. We'll just re-assign destinationRectangle, without setting the X and Ys to 0:
                destinationRectangle = camera.DestinationRectangle;

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullNone);
                spriteBatch.Draw(DisplacementRenderTarget, destinationRectangle, Color.White);
                spriteBatch.End();
            }
        }