quote:
Original post by billybob
you mean like ((int)(y + x) * width)?
Yes.
quote:
Original post by billybob
you mean like ((int)(y + x) * width)?
quote:
And please lets stay in the queston not the reason, i would in any case, like to know is it bossible.
quote:
Original post by ZipsterAnd please lets stay in the queston not the reason, i would in any case, like to know is it bossible.
quote:
Original post by ParadigmShift
Let me guess what you''re trying to do, and anticipate the answer:
You have two floats x and y, which are coordinates in the unit plane (x and y are between 0 and 1) which you want to scale by the size of your square array, denoted by width. So you want:
array2d[ (int)(x*width) ][ (int)(y*width) ]
which in a 1-D array would be
array1d[ (int)(x*width) + (int)(y*width)*width ]
The problem with using floats in (x+y*width) is that the decimal part of the y component becomes a horizontal shift, which you don''t want.
The only other possible way to make the algorithm more "accurate" is to round to the nearest integer, instead of simple truncation.
Tom
// this array holds the world cellsint World[SomeNumber];// for and example here, bomb hits to a 1,56 | 5,76 in world coordinatesfloat hitx=1.56;float hity=1.76;//So what i to do is calculate were the bomb hitted.World[int(hitx * map_width + hity)] = SomeThingUnUseful;//Ok that forks some how but its not accurate enough!
int iHitX = (int)(hitx);
int iHitY = (int)(hity);
World[ (iHitY * MAP_WIDTH) + iHitX ] = Something;
quote:
Original post by Zipster
I see. What you would want to do is truncate the hit coordinates. You can then plug in those numbers into the array as integers.int iHitX = (int)(hitx);
int iHitY = (int)(hity);
Then iHitx and iHitY become your array coordinates. That''s as accurate as you can get it, because that''s the resolution of your world array.World[ (iHitY * MAP_WIDTH) + iHitX ] = Something;
...is the correct logic.
Hope that helps. If you want to increase the resolution of your world array, I could post some info on how to work with that.
quote:
Original post by python_regious
Are you talking about casting to an int just truncating the floats?
If you want to round to the nearest int, just add 0.5 to the floats before casting...
Death of one is a tragedy, death of a million is just a statistic.![]()