views:

128

answers:

2

I have to implement small multimage graphic control, which in essence is an array of 9 images, shown one by one. The final goal is to act as minislider.

Now, this graphic control is going to receive various integer ranges: from 5 to 25 or from 0 to 7 or from -9 to 9.

If I am going to use proportion - "rule of three" I am afraid is not technically suistainable because it can be a source of errors. My guess is to use some lookup tables, but has anyone an good advice for approach?

Thnx

A: 

yes, a lookup table is a good solution

int lookup[9] = {5, 25, ... the other values };
int id1 = floor(slider);
int id2 = id1+1;
int texId1 = lookup[id1];
int texId2 = lookup[id2];
interpolate(texId1, texId2, slider - float(id1));
Calvin1602
.. but after re-reading your question I'm not sure anymore it's what you want
Calvin1602
+1  A: 

I'm not sure look up tables are required. You can get from your input value to an image index between 0 and 9 proportionally:

int ConvertToImageArrayIndex(int inputValue)
{
    int maxInputFromOtherModule = 25;
    int minInputFromOtherModule = 5;


    // +1 required so include both min and max input values in possible range.
    // + 0.5 required so that round to the nearest image instead of always rounding down.
    // 8.0 required to get to an output range of 9 possible indexes [0..8]

    int imageIndex = ( (float)((inputValue-minInputFromOtherModule) * 8.0) / (float)(maxInputFromOtherModule - minInputFromOtherModule + 1) ) + 0.5;

    return imageIndex;
}
Scott Langham
Yes... you're right. Initially I had thought for this approach too, but I was afraind of errors that could come from rounding the results.
garzanti