Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5010 in orxonox.OLD


Ignore:
Timestamp:
Aug 14, 2005, 3:48:22 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: better color-transformation-algorithms

Location:
orxonox/trunk/src
Files:
4 edited
2 moved

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r5009 r5010  
    4646                  util/loading/load_param.cc \
    4747                  util/state.cc \
    48                   story_entities/story_entity.cc \
     48                  story_entities/story_entity.cc \
    4949                  story_entities/campaign.cc \
    5050                  story_entities/world.cc \
     
    7878                  lib/util/ini_parser.cc \
    7979                  lib/util/substring.cc \
     80                  lib/util/color.cc \
    8081                  lib/math/vector.cc \
    8182                  lib/math/curve.cc \
     
    147148                 lib/util/substring.h \
    148149                 lib/util/list.h \
     150                 lib/util/color.h \
    149151                 lib/math/vector.h \
    150152                 lib/math/curve.h \
  • orxonox/trunk/src/Makefile.in

    r4976 r5010  
    7878        orxonox-render_2d.$(OBJEXT) orxonox-base_object.$(OBJEXT) \
    7979        orxonox-class_list.$(OBJEXT) orxonox-ini_parser.$(OBJEXT) \
    80         orxonox-substring.$(OBJEXT) orxonox-vector.$(OBJEXT) \
    81         orxonox-curve.$(OBJEXT) orxonox-glmenu_imagescreen.$(OBJEXT) \
     80        orxonox-substring.$(OBJEXT) orxonox-color.$(OBJEXT) \
     81        orxonox-vector.$(OBJEXT) orxonox-curve.$(OBJEXT) \
     82        orxonox-glmenu_imagescreen.$(OBJEXT) \
    8283        orxonox-benchmark.$(OBJEXT)
    8384orxonox_OBJECTS = $(am_orxonox_OBJECTS)
     
    9596@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-character_attributes.Po \
    9697@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-class_list.Po \
     98@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-color.Po \
    9799@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-crosshair.Po \
    98100@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-curve.Po \
     
    331333                  lib/util/ini_parser.cc \
    332334                  lib/util/substring.cc \
     335                  lib/util/color.cc \
    333336                  lib/math/vector.cc \
    334337                  lib/math/curve.cc \
     
    400403                 lib/util/substring.h \
    401404                 lib/util/list.h \
     405                 lib/util/color.h \
    402406                 lib/math/vector.h \
    403407                 lib/math/curve.h \
     
    491495@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-character_attributes.Po@am__quote@
    492496@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-class_list.Po@am__quote@
     497@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-color.Po@am__quote@
    493498@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-crosshair.Po@am__quote@
    494499@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-curve.Po@am__quote@
     
    12841289@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    12851290@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-substring.obj `if test -f 'lib/util/substring.cc'; then $(CYGPATH_W) 'lib/util/substring.cc'; else $(CYGPATH_W) '$(srcdir)/lib/util/substring.cc'; fi`
     1291
     1292orxonox-color.o: lib/util/color.cc
     1293@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT orxonox-color.o -MD -MP -MF "$(DEPDIR)/orxonox-color.Tpo" -c -o orxonox-color.o `test -f 'lib/util/color.cc' || echo '$(srcdir)/'`lib/util/color.cc; \
     1294@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/orxonox-color.Tpo" "$(DEPDIR)/orxonox-color.Po"; else rm -f "$(DEPDIR)/orxonox-color.Tpo"; exit 1; fi
     1295@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='lib/util/color.cc' object='orxonox-color.o' libtool=no @AMDEPBACKSLASH@
     1296@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/orxonox-color.Po' tmpdepfile='$(DEPDIR)/orxonox-color.TPo' @AMDEPBACKSLASH@
     1297@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1298@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-color.o `test -f 'lib/util/color.cc' || echo '$(srcdir)/'`lib/util/color.cc
     1299
     1300orxonox-color.obj: lib/util/color.cc
     1301@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT orxonox-color.obj -MD -MP -MF "$(DEPDIR)/orxonox-color.Tpo" -c -o orxonox-color.obj `if test -f 'lib/util/color.cc'; then $(CYGPATH_W) 'lib/util/color.cc'; else $(CYGPATH_W) '$(srcdir)/lib/util/color.cc'; fi`; \
     1302@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/orxonox-color.Tpo" "$(DEPDIR)/orxonox-color.Po"; else rm -f "$(DEPDIR)/orxonox-color.Tpo"; exit 1; fi
     1303@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='lib/util/color.cc' object='orxonox-color.obj' libtool=no @AMDEPBACKSLASH@
     1304@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/orxonox-color.Po' tmpdepfile='$(DEPDIR)/orxonox-color.TPo' @AMDEPBACKSLASH@
     1305@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1306@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-color.obj `if test -f 'lib/util/color.cc'; then $(CYGPATH_W) 'lib/util/color.cc'; else $(CYGPATH_W) '$(srcdir)/lib/util/color.cc'; fi`
    12861307
    12871308orxonox-vector.o: lib/math/vector.cc
  • orxonox/trunk/src/lib/coord/p_node.cc

    r5008 r5010  
    653653  }
    654654}
     655#include "color.h"
    655656
    656657/**
     
    707708    tIterator<PNode>* iterator = this->children->getIterator();
    708709      //PNode* pn = this->children->enumerate ();
    709     Vector childColor =  color - Vector(.0,.3,.3);
     710    Vector childColor =  Color::RGBtoHSV(color)+Vector(-.3,.3,.2);
    710711    PNode* pn = iterator->nextElement();
    711712    while( pn != NULL)
  • orxonox/trunk/src/lib/util/color.cc

    r5009 r5010  
    2020
    2121#include "color.h"
     22#include "vector.h"
    2223
    2324using namespace std;
    2425
    25 Vector Color::RGBtoHSV (Vector RGB)
     26
     27
     28
     29#include <stdio.h>
     30
     31// Needed by rgb2hsv()
     32float Color::maxrgb(float r, float g, float b)
    2633{
    27   Vector HSV;
     34  float max;
    2835
    29   float var_Min = min( RGB.x, RGB.y, RGB.z );    //Min. value of RGB
    30   float var_Max = max( RGB.x, RGB.y, RGB.z );    //Max. value of RGB
    31   float del_Max = var_Max - var_Min;             //Delta RGB value
    32 
    33   flaot V = var_Max;
    34 
    35   if ( del_Max == 0 )                     //This is a gray, no chroma...
    36   {
    37     HSV.x = 0                                //HSV results = 0 ÷ 1
    38     HSV.y = 0
    39   }
    40   else                                    //Chromatic data...
    41   {
    42     HSV.y = del_Max / var_Max;
    43 
    44     float del_R = ( ( ( var_Max - RGB.x ) / 6 ) + ( del_Max / 2 ) ) / del_Max;
    45     float del_G = ( ( ( var_Max - RGB.y ) / 6 ) + ( del_Max / 2 ) ) / del_Max;
    46     float del_B = ( ( ( var_Max - RGB.z ) / 6 ) + ( del_Max / 2 ) ) / del_Max;
    47 
    48     if ( RGB.x == var_Max )
    49       HSV.x = del_B - del_G;
    50     else if ( var_G == var_Max )
    51       HSV.x = ( 1 / 3 ) + del_R - del_B;
    52     else if ( var_B == var_Max )
    53       HSV.z = ( 2 / 3 ) + del_G - del_R;
    54 
    55     if ( HSV.x < 0 ) ; HSV.x += 1;
    56     if ( HSV.x > 1 ) ; HSV.x -= 1;
    57   }
    58   return HSV;
     36  if( r > g)
     37    max = r;
     38  else
     39    max = g;
     40  if( b > max )
     41    max = b;
     42  return( max );
    5943}
    6044
    6145
    62 Vector Color::HSVtoRGB (Vector HSV)
     46// Needed by rgb2hsv()
     47float Color::minrgb(float r,float g,float b)
    6348{
     49  float min;
    6450
     51  if( r < g)
     52    min = r;
     53  else
     54    min = g;
     55  if( b < min )
     56    min = b;
     57  return( min );
    6558}
     59
     60
     61/* Taken from "Fund'l of 3D Computer Graphics", Alan Watt (1989)
     62   Assumes (r,g,b) range from 0.0 to 1.0
     63   Sets h in degrees: 0.0 to 360.;
     64      s,v in [0.,1.]
     65*/
     66Vector Color::RGBtoHSV(const Vector& RGB)
     67{
     68  float r = RGB.x;
     69  float g = RGB.y;
     70  float b = RGB.z;
     71
     72  float h=0,s=1.0,v=1.0;
     73  float max_v,min_v,diff,r_dist,g_dist,b_dist;
     74  float undefined = 0.0;
     75
     76  max_v = maxrgb(r,g,b);
     77  min_v = minrgb(r,g,b);
     78  diff = max_v - min_v;
     79  v = max_v;
     80
     81  if( max_v != 0 )
     82    s = diff/max_v;
     83  else
     84    s = 0.0;
     85  if( s == 0 )
     86    h = undefined;
     87  else {
     88    r_dist = (max_v - r)/diff;
     89    g_dist = (max_v - g)/diff;
     90    b_dist = (max_v - b)/diff;
     91    if( r == max_v )
     92      h = b_dist - g_dist;
     93    else
     94      if( g == max_v )
     95        h = 2 + r_dist - b_dist;
     96    else
     97      if( b == max_v )
     98        h = 4 + g_dist - r_dist;
     99    else
     100      printf("rgb2hsv::How did I get here?\n");
     101    h *= 60;
     102    if( h < 0)
     103      h += 360.0;
     104  }
     105  return Vector(h, s, v);
     106}
     107
     108/* Taken from "Fund'l of 3D Computer Graphics", Alan Watt (1989)
     109   Assumes H in degrees, s,v in [0.,1.0];
     110   (r,g,b) range from 0.0 to 1.0
     111*/
     112Vector Color::HSVtoRGB(const Vector& HSV)
     113{
     114  float h = HSV.x;
     115  float s = HSV.y;
     116  float v = HSV.z;
     117  float r=0, g=0, b=0;
     118  float f,p,q,t;
     119  int i;
     120
     121  if( s == 0 ) {
     122    r = v;
     123    g = v;
     124    b = v;
     125  }
     126  else {
     127    if(h == 360.)
     128      h = 0.0;
     129    h /= 60.;
     130    i = (int) h;
     131    f = h - i;
     132    p = v*(1-s);
     133    q = v*(1-(s*f));
     134    t = v*(1-s*(1-f));
     135    switch(i) {
     136      case 0:
     137        r = v;
     138        g = t;
     139        b = p;
     140        break;
     141      case 1:
     142        r = q;
     143        g = v;
     144        b = p;
     145        break;
     146      case 2:
     147        r = p;
     148        g = v;
     149        b = t;
     150        break;
     151      case 3:
     152        r = p;
     153        g = q;
     154        b = v;
     155        break;
     156      case 4:
     157        r = t;
     158        g = p;
     159        b = v;
     160        break;
     161      case 5:
     162        r = v;
     163        g = p;
     164        b = q;
     165        break;
     166      default:
     167        r = 1.0;
     168        g = 1.0;
     169        b = 1.0;
     170      //printf("hsv2rgb::How did I get here?\n");
     171      // printf("h: %f, s: %f, v: %f; i:  %d\n",hin,s,v,i);
     172        break;
     173    }
     174  }
     175  return Vector(r,g,b);
     176}
  • orxonox/trunk/src/lib/util/color.h

    r5009 r5010  
    1515class Color
    1616{
    17   Vector RGBtoHSV (Vector RGB);
    18   Vector HSVtoRGB (Vector HSV);
     17  public:
     18  static Vector RGBtoHSV (const Vector& RGB);
     19  static Vector HSVtoRGB (const Vector& HSV);
     20
     21  static float minrgb(float r, float g, float b);
     22  static float maxrgb(float r, float g, float b);
    1923};
    2024
  • orxonox/trunk/src/world_entities/camera.cc

    r5007 r5010  
    192192void Camera::apply ()
    193193{
    194   this->target->getParent()->debugDraw(0, 2);
     194  this->target->getParent()->debugDraw(0, 2, Vector(1,0,0));
    195195  // switching to Projection Matrix
    196196  glMatrixMode (GL_PROJECTION);
Note: See TracChangeset for help on using the changeset viewer.