Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8986 in orxonox.OLD


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
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/gui/gl/glgui_bar.h

    r8984 r8986  
    3131    void setRange(float minimum, float maximum);
    3232
    33     float getValue() const { return this->_value; };
    34     float getMinimum() const { return this->_minimum; };
    35     float getMaximum() const { return this->_maximum; };
     33    float value() const { return this->_value; };
     34    float minimum() const { return this->_minimum; };
     35    float maximum() const { return this->_maximum; };
    3636
    3737    virtual void update() { };
  • 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
  • trunk/src/util/hud.cc

    r8976 r8986  
    168168  if (this->energyWidget != NULL)
    169169  {
    170     this->energyWidget->setAbsCoor2D(0.0 * this->resX, 0.9 * this->resY);
     170    this->energyWidget->setAbsCoor2D(0.0 * this->resX, 0.85 * this->resY);
    171171    this->energyWidget->setWidgetSize(.25 * this->resX, 0.1 * this->resY);
    172172  }
     
    177177  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.3)
    178178  {
    179     (*weaponWidget)->setAbsCoor2D(pos*this->resX, .9*this->resY);
     179    (*weaponWidget)->setAbsCoor2D(pos*this->resX, .85*this->resY);
    180180    (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY);
    181181    (*weaponWidget)->show();
  • trunk/src/world_entities/elements/glgui_energywidget.cc

    r8985 r8986  
    4040    this->_bar.setBackgroundColor(Color(0,0,0,0));
    4141    this->_bar.setForegroundColor(Color(.5, .5, .5, 1));
    42     this->_bar.font().setBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
    4342  }
    4443
     
    7069
    7170    this->_bar.setValue(value);
    72     this->_bar.setForegroundColor(Color(1 - (value / this->_bar.getMaximum()), value / this->_bar.getMaximum(),0,1));
     71    this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum()));
    7372    this->_bar.setFrontColor(Color(1,1,1,1), true);
    7473    this->_valueText.setText(val.getString());
Note: See TracChangeset for help on using the changeset viewer.