Jump to content
  • Advertisement
Sign in to follow this  

Math help: rotating a 2d sprite and maintaining widescreen perspective

This topic is 2923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color="#000000"]Hey guys, I'm building a 3d space sim. One of the hud elements is a "roll indicator" basically a circle - when the ship rotates this object rotates as well to show how the ship's rotation deviates from an imaginary "up" (imaginary in space, but its the positive Y axis in game terms). My artist pointed out that the 2d hud element was warped on widescreen resolutions - (its actually warped on any resolution not 1:1 ratio) so I though myself clever and figured out the ratio between the width and the height and multiplied that by the scale to get the warping fixed - or so I thought. When I roll the ship and the roll indicator rotates it becomes much more warped - a result of the previous offset and the roll combined.

Here's how I set the object's size (this is in screen space so it is 2d - though the node object is 3d so I set the last value to 1)
[color="#000000"]nodeOrientationBar->setScale(0.2, 0.2 ,1);

Yep it says set scale, but essencially this is size (20% of the screen) because we are in screen space.

[color="#000000"]This resulted in a warped effect that I was originally trying to fix,

To fix I did this:

float width =OgreFramework::getSingletonPtr()->m_pRenderWnd->getWidth(); //This gets me the resolution of the window
float height =OgreFramework::getSingletonPtr()->m_pRenderWnd->getHeight();

resolutionOffset.y = width/height;

nodeOrientationBar->setScale(0.2 * resolutionOffset.x, 0.2 * resolutionOffset.y,1);

This fixes the issue at 0 rotation...

[color="#000000"]So when I rotate the orientation bar I need to know the math to convert the resolution offset vector to the proper size so that I can properly set the scale.

This is how that's handled currently:
Ogre::Radian rRad = Common::getRoll(playerShip->getOrientation());

[color="#000000"]What i'm looking for is the formula to set the scale properly right after the roll step above. Any help is greatly appreciated (pretty crappy at math I am),

I need the sprite to retain proper dimensions so that it is a equally sized square no matter what resolution and rotation.

thank you

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!