Recommendations? How to: Flip/Mirror screen without disturbing the HUD

Started by
6 comments, last by Evil Steve 15 years, 1 month ago
Hi Guys I've been looking into ways of flipping the screen or mirroring the screen during play (as an effect)... I'm not 100% sure how to do it, but it's probably something to do with the projection matrix. I don't want to flip the hud (if at all possible) but definitely want to flip the screen (the final boss in our game has the ability to flip/mirror the screen to confuse the player). I don't want to mess with doing this at the sprite batch level, if at all possible. I'd like to be able to render the render target and then do the mirroring/flipping (if possible). Please recommend (if possible) how I might do this. Thank you and greetings, Chad
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]
Advertisement
I can't even compute 1+1 right now, but wouldn't you just swap left and right for your projection matrix (assuming you use a perspective)?
Also you could do all kind of nice effects by rendering to a texture first...
And I suppose your HUD uses a separate projection.
Quote:Original post by Rewdew
I can't even compute 1+1 right now, but wouldn't you just swap left and right for your projection matrix (assuming you use a perspective)?
Also you could do all kind of nice effects by rendering to a texture first...
And I suppose your HUD uses a separate projection.


Hi Rewdew,

It does seem like a pretty basic task, but I ask because I don't really have control of the HUD for the game.

I think we're actually using the same projection matrix.

This is a 2D game, though.

I'm thinking Matrix.CreateOrthographic * some scaling matrix might do it, but I'm not sure.

I think I could do something like multiply the projection matrix by whatever will flip/mirror it, and then switch it back before drawing the hud.

I'm just not quite sure.


Thanks


Chad
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]
Okay, here's what I have for trying to get things at least rotated around the center of the screen.

Problem is, it doesn't seem to be working. It seems to be trying to rotate around some outer point I can't find.


Assume ZoomPercentage = 1.0f (zoom code works; rotate code doesn't seem to)


            int w = GameManager.Instance.GraphicsDevice.Viewport.Width;            int h = GameManager.Instance.GraphicsDevice.Viewport.Height;            float x = (float)(w / 2) - (((1f / ZoomPercentage) * (float)w) / 2.0f);            float y = (float)(h / 2) - (((1f / ZoomPercentage) * (float)h) / 2.0f);            Transform = Matrix.Identity *                Matrix.CreateTranslation(0, 0, 0) *                 Matrix.CreateRotationZ(0) *                Matrix.CreateTranslation(-x,-y,0) *                Matrix.CreateScale(new Vector3(ZoomPercentage, ZoomPercentage, 0)) *                Matrix.CreateRotationZ(MathHelper.ToRadians(45));


There's probably some trig in there, but I'm unsure where to apply it.
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]
I think the problem with the previous code is that it's taking the width and height (extents) of the sprite batch, and rotating around that (the Translation matrix is sent to SpriteBatch.Draw)

I'm just trying to rotate the viewing rectangle, without messing with the sprite batch.


Chad
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]
All right, I was able to get close to solving this using a RenderTarget.

My only concern now is being able to get everything to render to a specific portion of the render target, so that I can spin the render target about an axis.

I mean, I can flip the screen horizontally and vertically now... I would just like to be able to offset the rendertarget so all the rendering takes place in the center of it, or something.

Thanks again,


Chad
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]
Quote:Original post by Verg
All right, I was able to get close to solving this using a RenderTarget.

My only concern now is being able to get everything to render to a specific portion of the render target, so that I can spin the render target about an axis.

I mean, I can flip the screen horizontally and vertically now... I would just like to be able to offset the rendertarget so all the rendering takes place in the center of it, or something.

Thanks again,


Chad


and a flipped view matrix would be the right one for this task.
Quote:Original post by FeverGames
and a flipped view matrix would be the right one for this task.
Indeed. It's my understanding that SpriteBatch uses it's own transform matrices. You just need to multiply your world, view or projection matrices by a scaling matrix of (-1, 1, 1) to mirror the screen, or (1, -1, 1) to flip it.

This topic is closed to new replies.

Advertisement