terça-feira, 30 de setembro de 2014

multidimensional array and pseudo-multidimensional array



#2D array access 
#define WIDTH 5
#define HEIGHT 3

int jimmy [HEIGHT][WIDTH];
int n,m;

int main ()
{
  for (n=0; n<HEIGHT; n++)
    for (m=0; m<WIDTH; m++)
    {
      jimmy[n][m]=(n+1)*(m+1);
    }
}



#1D array access

#define WIDTH 5
#define HEIGHT 3

int jimmy [HEIGHT * WIDTH];
int n,m;

int main ()
{
  for (n=0; n<HEIGHT; n++)
    for (m=0; m<WIDTH; m++)
    {
      jimmy[n*WIDTH+m]=(n+1)*(m+1);
    }
}

sábado, 27 de setembro de 2014

REMAP function and LERP function


remap range:
double fit(double index, double old_min, double old_max, double new_min,double new_max)
{
    return new_min + (new_max - new_min) * (index - old_min) / (old_max- old_min);
}
usage :
fit(0.5, 0, 1, 10, 20);
>> 15.0
>>

LERP: 
Precise method which guarantees v = v1 when t = 1.

float lerp(float v0, float v1, float t)
{
  return (1-t)*v0 + t*v1;
}