Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5009 in orxonox.OLD


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

orxonox/trunk: added class Color for easy color-transformation

Location:
orxonox/trunk/src
Files:
1 edited
2 copied

Legend:

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

    r4976 r5009  
    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 \
  • orxonox/trunk/src/util/color.cc

    r5000 r5009  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
     14
     15   this code has been borrowed from:
     16   http://www.easyrgb.com/math.php
    1417*/
    1518
    1619//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1720
    18 #include "proto_class.h"
     21#include "color.h"
    1922
    2023using namespace std;
    2124
     25Vector Color::RGBtoHSV (Vector RGB)
     26{
     27  Vector HSV;
    2228
    23 /**
    24  * standard constructor
    25  * @todo this constructor is not jet implemented - do it
    26 */
    27 ProtoClass::ProtoClass ()
    28 {
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
     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
    3032
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
     33  flaot V = var_Max;
    3534
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
     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;
    4159}
    4260
    4361
    44 /**
    45  * standard deconstructor
    46 */
    47 ProtoClass::~ProtoClass ()
     62Vector Color::HSVtoRGB (Vector HSV)
    4863{
    49   // delete what has to be deleted here
     64
    5065}
  • orxonox/trunk/src/util/color.h

    r5000 r5009  
    11/*!
    2  * @file proto_class.h
    3  * @brief Definition of ...
     2 * @file color.h
     3 * @brief Definition of color-calculations
     4 *
     5 * code borrowed from:
     6 * http://www.easyrgb.com/math.php
    47*/
    58
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
     9#ifndef _COLOR_H
     10#define _COLOR_H
    811
    9 #include "base_object.h"
     12//#include "vector.h"
     13class Vector;
    1014
    11 // FORWARD DECLARATION
    12 
    13 
    14 
    15 //! A class for ...
    16 class ProtoClass : public BaseObject {
    17 
    18  public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
    21 
    22 
    23  private:
    24 
     15class Color
     16{
     17  Vector RGBtoHSV (Vector RGB);
     18  Vector HSVtoRGB (Vector HSV);
    2519};
    2620
    27 #endif /* _PROTO_CLASS_H */
     21#endif /* _COLOR_H */
Note: See TracChangeset for help on using the changeset viewer.