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

Started by
-1 comments, last by chaosavy 12 years, 5 months ago
[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:

[color="#000000"]
float width =OgreFramework::getSingletonPtr()->m_pRenderWnd->getWidth(); //This gets me the resolution of the window
float height =OgreFramework::getSingletonPtr()->m_pRenderWnd->getHeight();

resolutionOffset.x=1.0f;
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:
[color="#000000"]
nodeOrientationBar->resetOrientation();
Ogre::Radian rRad = Common::getRoll(playerShip->getOrientation());
nodeOrientationBar->roll(rRad);



[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
Visit http://www.VoidDestroyer.com to check out my space sim project - Void Destroyer

This topic is closed to new replies.

Advertisement