watsoncj wrote on Dec 17th, 2005, 7:36am:I've been looking at example_06_02. I've seen this variable "float pct" in a few other examples. What does this name stand for What is it doing
thanks!
sorry for the delay, I don't get an email when there is a response...
pct is a number which goes from 0 to 1, this could be anything, but as a rule for myself, it represent a value of 0 to 1. for example, you could convert mouse position in x to a pct,
float pct = mousex / width;
in this case pct is a number which represent how close the objects are. this is based on their actual distance (dist) devided by the whole (in this case 30.0f). As the distance gets closer (the object get closer to touching each other) this number gets closer to 0. I inverted it, by subtracting it from 1...
float pct = 1 - (dist/radius);
when dist is close to radius, ie 28, the number is small
1 - ( 28 / 30 )
when dist is close to zero, the number is larger
1 - ( 3 / 30 )
I use this number (pct) to scale the forces on these two objects, when they are closer, apply more force, when they are further away, apply less force.
hope that helps - feel free to ask some more if it's not clear....
- zach