Need advice on ACS math

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Need advice on ACS math

Post by skadoomer »

I have a situation where I'm trying to do selective rounding, but need some advice on how to approach this. Here is the breakdown:

I have a graphic I want to move on the screen from xy (256.0, 128.0) to (190.0, 128.0) in 35 steps. The formula now is (a-b /steps), which produces quite a big decimal remainder. Because using SetHudSize is a requirement for this, I can't rely on decimal places. So when browsing the tutorial section of zdoom, the %= assigner caught my eye. I've never seen it used and have no idea if it is even supported, but it fits the current solution I have.

The way I see it, I can run a loop that keeps adding the remainder (if it can indeed be separated with the modulus Assigner) to its-self until the value goes over 1.0, then use the number of iterations it too to monitor the main variable. As the graphic moves along the steps, if the step number goes over the remainder iteration value, an extra 1 is added in to compensate for rendering errors. Not ideal, but it should look better than just dropping the remainder all together, which is what is happening now. In short, the code would look something like this:

Code: Select all

While(Somedecimil < 1.0)
{
 rem_itr++;
 Somedecimill += Somedecimil;
}

...

if(steps == rem_itr)
{
Xval += 1; 
rem_itr += rem_itr;
}


Now, will this work? Does anybody else have any other solutions that might fit here? And, does the %= assignment exist and work the way I'm describing here?
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Need advice on ACS math

Post by randi »

This should work:

Code: Select all

#define NUM_STEPS 35

for (int step = 0; step < NUM_STEPS; ++step)
{
    int x = 256.0 + (256.0 - 190.0) * step / (NUM_STEPS - 1);
    // You now have a fixed point number with decimals between 256.0 and 190.0.
    // Chop them off by using these as the coordinates for hudmessage:
    hudmessage(..., x & 0xFFFF0000, 128.0, ...);
} 
Locked

Return to “Editing (Archive)”