Ejemplo n.º 1
0
        private static void DetermineOffsetDifference(Camera camera, LayerCameraSettings settingsToUse, out int differenceX, out int differenceY)
        {
            int desiredCenterX = camera.DestinationRectangle.Width / 2;
            int actualCenterX  = (int)((settingsToUse.LeftDestination + settingsToUse.RightDestination) / 2);

            differenceX = actualCenterX - desiredCenterX;

            if (settingsToUse.RightDestination != settingsToUse.LeftDestination)
            {
                float xDifferenceMultipier = settingsToUse.OrthogonalWidth / (settingsToUse.RightDestination - settingsToUse.LeftDestination);
                differenceX = (int)(differenceX * xDifferenceMultipier);
            }
            else
            {
                differenceX = 0;
            }

            int desiredCenterY = camera.DestinationRectangle.Height / 2;
            int actualCenterY  = (int)((settingsToUse.BottomDestination + settingsToUse.TopDestination) / 2);

            differenceY = actualCenterY - desiredCenterY;

            if (settingsToUse.TopDestination != settingsToUse.BottomDestination)
            {
                float yDifferenceMultipier = settingsToUse.OrthogonalHeight / (settingsToUse.BottomDestination - settingsToUse.TopDestination);
                differenceY = (int)(differenceY * yDifferenceMultipier);
            }
            else
            {
                differenceY = 0;
            }
        }
Ejemplo n.º 2
0
        public void UsePixelCoordinates()
        {
            if (LayerCameraSettings == null)
            {
                LayerCameraSettings = new LayerCameraSettings();
            }

            if (mCameraBelongingTo != null)
            {
                LayerCameraSettings.UsePixelCoordinates(mCameraBelongingTo);
            }
            else
            {
                LayerCameraSettings.UsePixelCoordinates(SpriteManager.Camera);
            }
        }
Ejemplo n.º 3
0
        //public void SetCamera(Camera camera, SetCameraOptions options)
        //{

        //}



        public void ApplyValuesToCamera(Camera camera, SetCameraOptions options, LayerCameraSettings lastToModify, RenderTarget2D renderTarget = null)
        {
            var viewport = camera.GetViewport(this, renderTarget);

            Renderer.GraphicsDevice.Viewport = viewport;

            camera.Orthogonal       = Orthogonal;
            camera.OrthogonalHeight = OrthogonalHeight;
            camera.OrthogonalWidth  = OrthogonalWidth;


            if (lastToModify == null)
            {
                // January 11, 2014
                // We used to only do
                // offsets if the Layer
                // was both orthogonal and
                // if its orthogonal width and
                // height matched the destination.
                // Baron runs on multiple resolutions
                // and introduced situations where the
                // ortho width/height may not match the
                // destination rectangles because we may
                // scale everything up on larrger resolutions.
                // In that situation we still want to have the layers
                // offset properly.
//                bool offsetOrthogonal = Orthogonal && OrthogonalWidth == RightDestination - LeftDestination &&
//                      OrthogonalHeight == BottomDestination - TopDestination;

                bool offsetOrthogonal = Orthogonal;

                // But don't do this if we're on a render target, because render targets render full-screen:
                if (offsetOrthogonal && renderTarget == null)
                {
                    int differenceX;
                    int differenceY;
                    DetermineOffsetDifference(camera, this, out differenceX, out differenceY);

                    camera.X += differenceX;
                    camera.Y -= differenceY;
                }
            }
            else
            {
                bool offsetOrthogonal = lastToModify.Orthogonal;

                // Undo what we did before
                if (offsetOrthogonal && renderTarget == null)
                {
                    int differenceX;
                    int differenceY;
                    DetermineOffsetDifference(camera, lastToModify, out differenceX, out differenceY);

                    camera.X -= differenceX;
                    camera.Y += differenceY;
                }
            }

            if (options == SetCameraOptions.ApplyMatrix)
            {
                // This will set the matrix and individual values...
                camera.RotationMatrix = storedRotationMatrix;
                // ...now set individual values to make sure they dont change:
                camera.mRotationX = storedRotationX;
                camera.mRotationY = storedRotationY;
                camera.mRotationZ = storedRotationZ;


                camera.UpVector = mOldUpVector;
            }
            else
            {
                if (ExtraRotationZ != 0)
                {
                    camera.RotationMatrix *= Matrix.CreateFromAxisAngle(camera.RotationMatrix.Backward, ExtraRotationZ);
                }
                camera.UpVector = camera.RotationMatrix.Up;
            }

            if (this.OffsetParent != null)
            {
                camera.Position -= this.OffsetParent.Position;
            }


            // Set FieldOfView last so it updates the matrices

            camera.FieldOfView = FieldOfView;
        }