Need help please.
by Sam Guffey · in Torque Game Engine · 12/30/2003 (2:18 am) · 5 replies
I have a consoleMethod that calls setStormCloudAlpha below, it checks first to see if my new alphaValue and the current alphaValue do not match, then it sets "mStormCloudUpdate" to true. In sky::render() I am checking to see if mStormCloudUpdate is true and if so run updateNewCloudAlpha. Its runs though the process of fading in or out the cloudLayer I have assigned. Once the procces is complete, (when StormCloudAlpha == NewCloudAlpha) at prints out the warning telling me that it is complete as seen below. Here is where the problem is...
As you can see I am testing to see if mStormCloudUpdate is true in setStormCloudAlpha, if it is then print out that I must wait.
So now I see that its completed the cycle, I go to fade the cloud back out but it keeps telling me that the cycle is not complete.. Why is it not excepting that I placed "mStormCloudUpdate = false;" when it finishes?
Yes I added a new mask, placed all info in pack and unpack. Am I just calling the setMaskBits wrong or what? Any input into this would be greatfull.
As you can see I am testing to see if mStormCloudUpdate is true in setStormCloudAlpha, if it is then print out that I must wait.
So now I see that its completed the cycle, I go to fade the cloud back out but it keeps telling me that the cycle is not complete.. Why is it not excepting that I placed "mStormCloudUpdate = false;" when it finishes?
Yes I added a new mask, placed all info in pack and unpack. Am I just calling the setMaskBits wrong or what? Any input into this would be greatfull.
void Sky::updateNewCloudAlpha()
{
Point2F a, b, c;
a.set(mStormCloudAlpha, 0);
b.set(mNewCloudAlpha, 0);
c.interpolate(a, b, 1.0);
mStormCloudAlpha = (F32)c.len();
if(mStormCloudAlpha == mNewCloudAlpha) {
mStormCloudUpdate = false;
Con::warnf("updateNewCloudAlpha() is complete");
}
setMaskBits(StormCloudAlphaMask);
}
void Sky::setStormCloudAlpha(F32 alpha)
{
if(mStormCloudUpdate)
{
Con::errorf("Cloud update in progress, please wait..");
return;
}
if(alpha != mStormCloudAlpha) {
mStormCloudUpdate = true;
mNewCloudAlpha = alpha;
}
setMaskBits(StormCloudAlphaMask);
}About the author
#2
Fixed that 0.9999 prob but I still dont get a reset of mStormCloudUpdate which is the main problem..
12/30/2003 (10:29 am)
Hmm, oddly its only going up to 0.99999 and no further. Why will it not interpolate to 1.0?Fixed that 0.9999 prob but I still dont get a reset of mStormCloudUpdate which is the main problem..
#3
So, the prob is that (mStormCloudAlpha == mNewCloudAlpha) will probably never, ever be true... and mStormCloudUpdate wont get set false.
When you ineterpolate something, you have to threshold the target value. Decide how close is close enough to be "there".
try:
( mStormCloudAlpha - mNewCloudAlpha <= zThreshold )
( alpha - mStormCloudAlpha > zThreshold )
where zThreshold is a good val for your app.
12/30/2003 (10:57 am)
Because of the way floating point numbers are stored, you'll almost never get the F32 results of some math to exactly equal some other F32. There is a lot of floating point error in there, that you just have to live with, or read the IEEE spec & do the math, to predict.So, the prob is that (mStormCloudAlpha == mNewCloudAlpha) will probably never, ever be true... and mStormCloudUpdate wont get set false.
When you ineterpolate something, you have to threshold the target value. Decide how close is close enough to be "there".
try:
( mStormCloudAlpha - mNewCloudAlpha <= zThreshold )
( alpha - mStormCloudAlpha > zThreshold )
where zThreshold is a good val for your app.
#4
Am I using the setMaskBits call correctly? Initially when the game starts im getting packUpdate called with the correct mask, also when I call setStormCloudAlpha the new mNewCloudAlpha is getting set fine but in updateNewCloudAlpha the mStormCloudAlpha var is not being saved after the function has finished thus the next time I run this function it thinks the alpha is at its "startup" value of 0.1 yet I have already faded it in to 0.9
12/30/2003 (12:29 pm)
Thanks Ben and Paul, I have one more question..Am I using the setMaskBits call correctly? Initially when the game starts im getting packUpdate called with the correct mask, also when I call setStormCloudAlpha the new mNewCloudAlpha is getting set fine but in updateNewCloudAlpha the mStormCloudAlpha var is not being saved after the function has finished thus the next time I run this function it thinks the alpha is at its "startup" value of 0.1 yet I have already faded it in to 0.9
#5
12/31/2003 (6:04 pm)
Let me get a bump on this thread for the new year!
Associate Kyle Carter