This project is read-only.

Resolution matrix

Jan 22, 2012 at 12:08 AM
Edited Jan 22, 2012 at 12:09 AM

HI!

I am trying to implement different resolution support in my game.

 

I found a nice class online that gives me a matrix back after calculating the right scale.

http://www.david-amador.com/2010/03/xna-2d-independent-resolution-rendering/

 

Normally I can attach this matrix to the spritebatch.begin() method. But with krypton I can't do this. At least, not in the same way.

For instance, with farseer physics, all I do is this:

 

game.spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Resolution.getTransformationMatrix());

 

The method Resolution.getTransformationMatrix() takes care of the calculation.

Here is an image of how it looks now:

http://aggror.com/xna/kryptonfarseer.JPG

 

 

Could someone help with were I can place this matrix so that krypton lights and hulls are placed correctly? 

Thanks in advance.

Jan 25, 2012 at 4:51 PM

No ideas or suggestions?

Jan 26, 2012 at 4:33 PM

Did you enabled SpriteBatch compatibility for krypton?

 

Jan 27, 2012 at 1:26 PM

thanks for your reply.

What does spritebatch Compatibility do exactly? Sorry if this seems noobisch, but I am not really familiar with matrices etc.  If I enable spritebatch compatebility, the lights are no longer drawn. 

thanks for your help!

Jan 28, 2012 at 10:49 PM

        /// <summary>
        /// Returns the final, modified matrix used to render the lightmap.
        /// </summary>
        /// <returns></returns>
        private Matrix LightmapMatrixGet()
        {
            if (this.mSpriteBatchCompatabilityEnabled)
            {
                float xScale = (graphics.GraphicsDevice.Viewport.Width > 0) ? (1f / graphics.GraphicsDevice.Viewport.Width) : 0f;
                float yScale = (graphics.GraphicsDevice.Viewport.Height > 0) ? (-1f / graphics.GraphicsDevice.Viewport.Height) : 0f; <- this line

                // This is the default matrix used to render sprites via spritebatch
                var matrixSpriteBatch = new Matrix()
                {
                    M11 = xScale * 2f,
                    M22 = yScale * 2f,
                    M33 = 1f,
                    M44 = 1f,
                    M41 = -1f - xScale,
                    M42 = 1f - yScale,
                };

                // Return krypton's matrix, compensated for use with SpriteBatch
                return this.mWVP * matrixSpriteBatch;
            }
            else
            {
                // Return krypton's matrix
                return this.mWVP;
            }
        }

I'm not a master of matrices so I'm not entirely sure what it does (maybe compensates for spritebatch's projection matrix?) but try setting this to true and changing the cull mode to CullMode.None

Jan 30, 2012 at 5:48 PM

SpriteBatchCompatiblity mode basically just makes Krypton take the same matrix that SpriteBatch uses by default and multiply it by the matrix you supply... or... visa-versa (I'm not well-practiced in matricies either.. I just bend them to my will).

I'll see what I can come up with later to help with this.

Feb 3, 2012 at 10:26 AM

SpriteBatchCompatibilty doesn't seem work in my project. Or at least: The lights are no longer visible in the screen. 


Mar 30, 2012 at 9:08 PM

I haven't looked much at this problem again. However I am facing a point were I definitively can not skip this problem any more. Here is my current Code:

            //this.krypton.SpriteBatchCompatablityEnabled = true;
            //this.krypton.CullMode = CullMode.CullClockwiseFace;
            Matrix res = Resolution.getTransformationMatrix();
            Matrix world = Matrix.Identity;

            float xratio = game.virtualScreenWidth / game.screenWidth;
            float yratio = game.virtualScreenHeight / game.screenHeight;
            
            Matrix view = Matrix.CreateTranslation( 0, 0, 0);

            //Matrix projection = Matrix.CreateOrthographic(game.virtualScreenWidth, game.virtualScreenHeight, 0, 1);
            Matrix projection = Matrix.CreateOrthographic(game.screenWidth, game.screenHeight, 0, 1)
            Matrix wvp = (world * view * projection) *Resolution.getTransformationMatrix();

            // Assign the matrix and pre-render the lightmap.
            game.gameWorld.krypton.Matrix = wvp;
            game.gameWorld.krypton.LightMapPrepare();

            // Make sure we clear the backbuffer *after* Krypton is done pre-rendering
            game.GraphicsDevice.Clear(Color.White);

            //Draw the lights
            krypton.Draw(gameTime);

Apr 1, 2012 at 10:36 PM

So, compatibility mode definitely needs to be enabled, assuming your drawing with SpriteBatch. Now, you may also need to set the cull mode to none (or counter-clockwise... whatever is opposite of what it is currently).

Cull mode would be one reason why the lights weren't showing up.

Apr 6, 2012 at 4:03 PM

Unfortunately, trying al those options didn't work. Would you be interested to look at our code for a compensation? Thank you!

Apr 11, 2012 at 5:45 PM

Aggror,

Send me a private message, and we'll see what we can do about it. I'd be more than happy to accept compensation in the form of a donation, if you so choose. If it starts taking too much time, we'll discuss something more formal.