Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Roof Top Pew Wee

Simple casting question.

This topic is 6072 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

I feel embarassed to bother my fellow forum browsers with this question, but unbelievebaly enough, it has stumped me. here''s teh code: float xLeftover = ((cursorPosition.x - windowRect1.left) % G.bitmapWidth[0])/G.bitmapWidth[0]; What I''m doing here is in a windowed program I''m making, the screen displays tiled graphics. So the first part makes the cursor position in terms of the window. Then I find out how many pixels into the tile the cursor is, and finally divide that by the width of the tile. That way I can tell if the cursor is on the left or right side of the tile. However, xLeftover always seems to be 0, and all of the variables work fine independantly. They happen to be all ints, so I''m guessing that it''s a casting problem. If anyone could help here, I''d be most grateful. And please keep the rude remarks to a minimum --Vic--

Share this post


Link to post
Share on other sites
Advertisement
How about this:
float xLeftover = (float)((cursorPosition.x - windowRect1.left) % G.bitmapWidth[0])/G.bitmapWidth[0];

Share this post


Link to post
Share on other sites
Well, I figured it out right after I posted the problem, remembering back to a problem I missed in my CS class. When you divide by an integer, you get an integer out. So the solution is:

float xLeftover = ((cursorPosition.x - windowRect1.left) % G.bitmapWidth[0])/(float)G.bitmapWidth[0];

Casting the last G.bitmapWidth[0] to a float does it.

--Vic--

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!