-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

skaffman
  • 398,947
  • 96
  • 818
  • 769
garzanti
  • 2,162
  • 1
  • 22
  • 30
  • Why do you think you need a lookup table ? Why not just calculate the index from the range and current value ? – Paul R Aug 04 '10 at 07:49
  • The mini-slider consists of 9 images with which should change when the value increases or decreases. Indeed the imageId is an index growing. But the input range from the other module can be from 5 to 25, or from 0 to 7. At first sight I wanted to use the rule of three but is not ok, and the choice seems to be the lookup tables. – garzanti Aug 04 '10 at 08:00
  • Just to clarify what I understood: You are given a set of images that are to be shown sequentially (potentially in both directions, but no jumps). You are also given a range of integers that need not start with 0 and whose range can be greater than 9. How are the integers related to the images? What is it that you call "rule of three" that is not a solution? – David Rodríguez - dribeas Aug 04 '10 at 08:32
  • This is the rule of three I'm speaking: http://en.wikipedia.org/wiki/Cross-multiplication#Rule_of_Three I have 9 images each representing a o position on a slider (progressbar), image no 0 being the minimum and image no 9 being the maximum. I am also having a volume let's say that can take values from a minimum of 5 to a maximum of 25, and I want to associate a value from my volume scale with a value from the slider. – garzanti Aug 04 '10 at 09:15

2 Answers2

1

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
  • 58,735
  • 39
  • 131
  • 204
  • 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 Aug 04 '10 at 10:38
0

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
  • 9,413
  • 2
  • 44
  • 55