# 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 on other sites
well if the point sprite is 0.6f wide in world space, just generate a point in the upper left and lower right in world space, then transform those points as discussed in the other thread

##### Share on other sites
Sorry I don't know what you mean, I'm gonna need an example :(. Also I don't remember being tought how to work out an object's size in pixels.

Thanks!

##### 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 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982121

• 22
• 9
• 9
• 13
• 11