Sign in to follow this  
WinRad

Float to pixel - Width

Recommended Posts

Hello again guys, First of all the part one to this question was answered in another thread - "How to convert an object's world coordinates into screen space coordinates?". This question is a bit different though obviously... "How can I figure out the width of a point sprite if I know its size and its center?". So basically I have a point sprite and using the technqiue mentioned in the part 1 of this thread figured out the sprite's center's position on the screen, but I need to create a bounding box around it. So since I know the size which is 0.3f I should be able to work out the bounding box by doing something like -> SpriteCentreLeft = Centre - 0.3f; Or something like that, but I have no idea on what to do! Please help out. Thanks!

Share this post


Link to post
Share on other sites
Well you said you already worked out how to get the screen-space position from a world-space position, right? Well all you need to do to find out the screen-space width is to convert two world-space points to screen space and calculate the width. So let's assume you have a function that takes world-space and outputs screen-space, called "WorldSpaceToScreenSpace":


spriteCenterSS = WorldSpaceToScreenSpace(spriteCenterWS);
spriteRightEdgeSS = WorldSpaceToScreenSpace(spriteCenterWS + 0.3f);
spriteWidthSS = spriteRightEdgeSS.x - spriteCenterSS.x;

Share this post


Link to post
Share on other sites
Wow I feel so stupid... I already tried something similar but it didn't work, but I really thought it should have worked --->

WorldCentreSS = WorldSpaceToScreenSpace(WorldCentreWS);
WorldCentrePlusWidthSS = WorldSpaceToScreenSpace(WorldCentrePlusWidthWS);
WidthSS = WorldCentrePlusWidthSS - WorldCentreSS;

OPTIONAL: What's wrong with that?

RESOLVED.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this