Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8986 in orxonox.OLD for trunk/src/lib/util/color.cc


Ignore:
Timestamp:
Jul 1, 2006, 4:57:07 PM (18 years ago)
Author:
bensch
Message:

trunk: slerping colors in HSV-space works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/color.cc

    r8619 r8986  
    2020
    2121
     22//! Red Color
     23const Color Color::red(1,0,0, 1);
     24//! Green Color
     25const Color Color::green(0,1,0, 1) ;
     26//! blue Color
     27const Color Color::blue(0,0,1, 1);
     28//! White Color
     29const Color Color::white(1,1,1, 1);
     30//! Black Color
     31const Color Color::black(0,0,0,1);
     32//! Orx Color
     33const Color Color::orx(.2, .5, .7, .8);  //!< TODO Define the ORX-color :)
     34
     35
     36void Color::slerpHSV(const Color& c, float v)
     37{
     38  this->a() += (c.a() - this->a()) * v;
     39  Vector from(r(), g(), b());
     40  Vector to(c.r(), c.g(), c.b());
     41
     42  from = RGBtoHSV(from);
     43  to = RGBtoHSV(to);
     44
     45  from += (to - from) * v;
     46
     47  to = HSVtoRGB(from);
     48
     49  this->r() = to.x;
     50  this->g() = to.y;
     51  this->b() = to.z;
     52}
     53
     54Color Color::slerpHSVColor(const Color& from, const Color& to, float v)
     55{
     56  Color fromColor(from);
     57  fromColor.slerpHSV(to, v);
     58  return fromColor;
     59}
     60
     61
    2262void Color::debug() const
    2363{
     
    65105  if( s == 0 )
    66106    h = undefined;
    67   else {
     107  else
     108  {
    68109    r_dist = (max_v - r)/diff;
    69110    g_dist = (max_v - g)/diff;
     
    74115      if( g == max_v )
    75116        h = 2 + r_dist - b_dist;
    76     else
    77       if( b == max_v )
    78         h = 4 + g_dist - r_dist;
    79     else
    80       printf("rgb2hsv::How did I get here?\n");
     117      else
     118        if( b == max_v )
     119          h = 4 + g_dist - r_dist;
     120        else
     121          printf("rgb2hsv::How did I get here?\n");
    81122    h *= 60.;
    82123    if( h < 0)
     
    112153  int i;
    113154
    114   if( s == 0 ) {
     155  if( s == 0 )
     156  {
    115157    r = v;
    116158    g = v;
    117159    b = v;
    118160  }
    119   else {
    120    if(h >= 360.)
    121      h = h - (float)((int)(ceilf(h) / 360.0));
     161  else
     162  {
     163    if(h >= 360.)
     164      h = h - (float)((int)(ceilf(h) / 360.0));
    122165    h /= 60.;
    123166    i = (int) h;
     
    126169    q = v*(1-(s*f));
    127170    t = v*(1-s*(1-f));
    128     switch(i) {
     171    switch(i)
     172    {
    129173      case 0:
    130174        r = v;
     
    161205        g = 1.0;
    162206        b = 1.0;
    163       //printf("hsv2rgb::How did I get here?\n");
    164       // printf("h: %f, s: %f, v: %f; i:  %d\n",hin,s,v,i);
     207        //printf("hsv2rgb::How did I get here?\n");
     208        // printf("h: %f, s: %f, v: %f; i:  %d\n",hin,s,v,i);
    165209        break;
    166210    }
Note: See TracChangeset for help on using the changeset viewer.