Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

trunk: slerping colors in HSV-space works

Location:
trunk/src/lib/util
Files:
2 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    }
  • trunk/src/lib/util/color.h

    r8448 r8986  
    22 * @file color.h
    33 * @brief Definition of color-calculations
     4 *
     5 * TODO CONVERT THE VECTORS to COLORS!!
    46 *
    57 * code borrowed from:
     
    4951
    5052  void slerp(const Color& c, float v) { *this += (c - *this) * v; };
     53  void slerpHSV(const Color& c, float v);
     54
     55  static Color slerpHSVColor(const Color& from, const Color& to, float v);
    5156
    5257  void debug() const;
     
    6368  static float maxrgb(float r, float g, float b);
    6469
     70public:
     71  static const Color red;
     72  static const Color green;
     73  static const Color blue;
     74  static const Color white;
     75  static const Color black;
     76  static const Color orx;
     77
    6578private:
    6679  float       _rgba[4]; //!< Color Values
Note: See TracChangeset for help on using the changeset viewer.