TMachna
TMachna

Reputation: 289

OpenGL Gl.glColor3f How to color with one parametr?

I have some question about visualization in OpenGL. I have points in 3D space, each point also have one extraValue, which represent diffrent values, eg temperature, pressure and so on. User chooses one of this and other method sets extraValue to each point.

First problem is, that this values have diffrent ranges, eg:

temperature: <80; 2000>
preassure: <-500; 400>
gamma: <0,5; 1,8>
...

Now I want to visualize it to look for reliable, for example the temperature: 80 C is cold, so blue color, 2000 is hot so red. Similarry for others, preassure, gamma and so on.

The second problem is that Gl.glColor3f accepts 3 parameters: red, green, blue. I have only ONE parameter to each ponit. Range of RGB is <0;1>, my values have diffrent ranges.

Does anybody have an idea, or some algorithm that could help mi with this ?

Upvotes: 0

Views: 657

Answers (1)

Chris
Chris

Reputation: 5514

Firstly, remap your value into a range of 0-1, like so:

double t = ( value - min ) / ( max - min ); // i.e. min could be 80 and max 2000
// it might be a good idea to limit t to 0-1 here, in case
// your original value could be outside the valid range

Then, do a linear interpolation between the colors, like so (pseudocode):

Color a = Blue, b = Red
double inv = 1.0 - t

Color result = Color( inv * a.R + t * b.R,
                      inv * a.G + t * b.G,
                      inv * a.B + t * b.B )

That should get you started!

Upvotes: 2

Related Questions