Skip to main content
GameDev.net gamedev.net
🔒 Locked

Float to pixel - Width

Started by WinRad Aug 17, 2008 at 4:26 PM 3 replies 1.2k views
Original Post
WinRad
WinRad
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!
Ebola0001
Ebola0001
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
Quando Omni Flunkus MoritatiWhen All Else Fails, Play Dead!
WinRad
WinRad
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!
MJP
MJP
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;
WinRad
WinRad
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.