0
\$\begingroup\$

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!

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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.

http://en.wikipedia.org/wiki/Reflection_(mathematics)

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

edit2: http://mathworld.wolfram.com/Reflection.html

This has the actual formula you wanted.

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

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);
\$\endgroup\$
2
  • \$\begingroup\$ 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 \$\endgroup\$
    – Setheron
    Apr 25, 2012 at 16:07
  • \$\begingroup\$ 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. \$\endgroup\$ Apr 25, 2012 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .