•      Sign In
• Create Account

## Rotating axis-aligned image by 90 degrees

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

1 reply to this topic

### #1Servant of the Lord  Members

33511
Like
0Likes
Like

Posted 15 December 2013 - 04:05 PM

I'm using SFML, but it just wraps OpenGL fairly closely in this area, so this is really an OpenGL question.

My textures are axis-aligned. If I wanted to rotate them 90 degrees, without using a the typical OpenGL fixed-function rotation functions and without using shaders or manipulating matrices, would it make more sense to do it by rotating the position of the vertices or by rotating the texture coordinates?

My code currently looks like this:
//The pre-transform position and size:
float widthBeforeTransform = static_cast<float>(subRect.width);
float heightBeforeTransform = static_cast<float>(subRect.height);
vertices[0].position = sf::Vector2f(0, 0); //<< Should I rotate these?
vertices[1].position = sf::Vector2f(0, heightBeforeTransform);
vertices[2].position = sf::Vector2f(widthBeforeTransform, heightBeforeTransform);
vertices[3].position = sf::Vector2f(widthBeforeTransform, 0);

//Calculate the texture coordinates:
float left   = static_cast<float>(subRect.left);
float right  = left + subRect.width;
float top    = static_cast<float>(subRect.top);
float bottom = top + subRect.height;

//If we're mirroring, swap the texture coordinates vertically and/or horizontally.
if(flipVertically) std::swap(top, bottom);
if(flipHorizontally) std::swap(left, right);

//Set the texture coordinates:
vertices[0].texCoords = sf::Vector2f(left, top); [font='Helvetica Neue', Arial, Verdana, sans-serif]//<< Or should I rotate these?[/font]
vertices[1].texCoords = sf::Vector2f(left, bottom);
vertices[2].texCoords = sf::Vector2f(right, bottom);
vertices[3].texCoords = sf::Vector2f(right, top);

It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

### #2Paradigm Shifter  Members

5832
Like
1Likes
Like

Posted 15 December 2013 - 04:33 PM

Change the positions, that will work correctly if the texture is not square.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.