Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
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
add comment

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);
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.