I'm having this problem on some game I'm coding which I think it's just math and has nothing to do with coding, that's why I'm posting it here and I'm going to simplify the problem without describing anything related to the actual code. In case you want to take a look, please see this question on Stack Overflow: http://stackoverflow.com/questions/5822740/how-to-correctly-get-the-terrain-height-at-point-x-z-in-a-scaled-terrain
Let's say I want to draw a line on screen, with width
w. To draw this line I need to do it in steps,
sw, by default 1 unit steps. But I do allow this width to be scaled to any other value. After selecting the new width,
dw, the new step needs to be calculated and I do it like this:
sw = dw / w. With this, the line is properly scaled and I can draw it just fine.
Now, for a given
x of that line I need to do some other calculations. Since I allowed the line to be scaled and it's not the original width. I need to calculate the real
nx, before anything else. I just need to work on the step value calculated before, like this:
nx = x / sw.
This will give me exactly the right
nx value I'm looking for. Everything's working so far.
Now, my real problem is when I need to introduce a little change to the step calculation. Instead of calculating the step like I said before (
sw = dw / w) I need to calculate it like this:
sw = dw / (w - 1).
The problem I'm actually having is in the next step. Given
x, how do I correctly calculate
nx as I did before? Math is not my strong suite and I tried many things that I would think were right but it was mostly trial and error. Suffice to say, nothing worked.