|
programming strings (the bendy type)
I've programmed this string for use in a game (realistic ammo belts and stuff).
The string in the program follows the mouse, the problem is that when you
move it to the right the rest of the string comes to rest one pixel to the left
of the cursor if you move the cusor back in line with the string the string remains
directly below as it should and when moving to the left the srtring comes to rest
directly below the cursor as it should. I just cant see why its happening and was hoping
someone here could help. Here's the string function.
Anyway if anyone can see whats going wrong it would be great if you could help me out
Edited by - pierspo on July 14, 2001 9:20:44 AM
yeah boy
Nice effect, there!
Is s[0].point an array of integers? I tested it assuming it was, and I found that this was the problem:
s[0].point.x += x_vect1;<br><br>That was rounding x_vect1 downwards rather than to the nearest integer. I replaced it with this line:<br><br>s[0].point.x += x_vect1 + 0.5;<br><br>And it worked just fine. Strangely, if I did the same thing with the y values, it made the effect even worse.<br><br>EDIT: added those spaces around the letter "i" because an i surrounded by square brackets indicates italicised text on this board.<br><br>Edited by - Beer Hunter on July 14, 2001 12:12:01 AM
Is s[0].point an array of integers? I tested it assuming it was, and I found that this was the problem:
s[0].point.x += x_vect1;<br><br>That was rounding x_vect1 downwards rather than to the nearest integer. I replaced it with this line:<br><br>s[0].point.x += x_vect1 + 0.5;<br><br>And it worked just fine. Strangely, if I did the same thing with the y values, it made the effect even worse.<br><br>EDIT: added those spaces around the letter "i" because an i surrounded by square brackets indicates italicised text on this board.<br><br>Edited by - Beer Hunter on July 14, 2001 12:12:01 AM
Unfortunately s[0].point is an array of floats so that is not the problem. I tried changing it to ints but the program just behaves really oddly, thanks for your help anyway. If its not too much trouble could you post your code with the ints so I can take a look.
yeah boy
If they''re floats then when you draw them you''re going to be casting to integers. Seeing as casting from a float to an int rounds down (I think), that would explain your problem... because it''s essentially what Beer Hunter was talking about, just at a later stage (i.e not when you assign the value, but when you blit the coordinate).
Insomnia
Insomnia
Insomnia
When you move the cursor right, say to x=56, then any point's x value might go:
55
55.9
55.99
55.999
55.9999
55.99999
But all of those will be rounded down to 55 when they are drawn... You need to either add 0.5 when converting to an integer, or if you're feeling bored, draw everything anti-aliased.
EDIT: To make the string act more like a real string, try changing the definition of s[0].point so that it has four float members (x, y, xv, yv), and then try this code out. I used a value of 15 for gravity and 5 for init_distance, by the way.
Edited by - Beer Hunter on July 15, 2001 9:47:42 PM
55
55.9
55.99
55.999
55.9999
55.99999
But all of those will be rounded down to 55 when they are drawn... You need to either add 0.5 when converting to an integer, or if you're feeling bored, draw everything anti-aliased.
EDIT: To make the string act more like a real string, try changing the definition of s[0].point so that it has four float members (x, y, xv, yv), and then try this code out. I used a value of 15 for gravity and 5 for init_distance, by the way.
|
Edited by - Beer Hunter on July 15, 2001 9:47:42 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement