# XNA: How to Flip/Mirror a position over a custom vector?

I want to flip Horizontally my Sprite/Texture however the SpriteEffects.FlipHorizontally isn't cutting it for me as it just flips the texture in place.

I want to flip the texture over a specified Vector2/Vector3?

Thanks!

-

some quick resources i found:

http://forums.create.msdn.com/forums/p/80526/487062.aspx

C = A - (2 * B * (A dot B)) where A is original vector, B the mirror, C result.

edit: Sorry, I actually forgot what the actual question was. But yeah, you should be able to manipulate UV-values with that formula anyway.

This has the actual formula you wanted.

-
mmm does it work for Point2D? It doesn't seem to in the case where my point2D is (0,0) – Setheron Apr 25 '12 at 16:16
since A dot B would be 0 if A was (0,0) – Setheron Apr 25 '12 at 16:16
Ah, it's cause it reflects as if the vector was from the origin. But my vector isn't at the origin... – Setheron Apr 25 '12 at 16:22
mathworld.wolfram.com/Reflection.html – Toni Apr 25 '12 at 16:41
Sorry. Me brain too weak right now, so above you have actual reliable algorithm instead. – Toni Apr 25 '12 at 16:42

To do this you would most likely have to write a custom shader which provides a mechanism for flipping.

Create your shader and load it as an effect in xna. Then set it before doing any draw calls. You can load this shader through the content manager.

In your shader you will want to change the pixel shader. What you will want to do is mirror the texture coordinate supplied to the pixel shader in the vector. Also, remember to create a global variable, for the vector, which you can set in your xna code trough;

effect.parameter["name"].setValue(Val);
-
but my sprite already has a LocalTransformation? Why Can't I just modify his transformation to flip over the vector. I Just don't know the math – Setheron Apr 25 '12 at 16:07
Sorry, I thought you were wanting to flip the texture applied to the sprite, not the sprite itself. It was your mention of SpriteEffects.FlipHorizontally which confused me. This call is basically doing what I mentioned, but it's flipping the texture in a predefined vector rather than one you define. – OriginalDaemon Apr 25 '12 at 16:57