/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... this code has been borrowed from: http://www.easyrgb.com/math.php */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ #include "color.h" using namespace std; Vector Color::RGBtoHSV (Vector RGB) { Vector HSV; float var_Min = min( RGB.x, RGB.y, RGB.z ); //Min. value of RGB float var_Max = max( RGB.x, RGB.y, RGB.z ); //Max. value of RGB float del_Max = var_Max - var_Min; //Delta RGB value flaot V = var_Max; if ( del_Max == 0 ) //This is a gray, no chroma... { HSV.x = 0 //HSV results = 0 รท 1 HSV.y = 0 } else //Chromatic data... { HSV.y = del_Max / var_Max; float del_R = ( ( ( var_Max - RGB.x ) / 6 ) + ( del_Max / 2 ) ) / del_Max; float del_G = ( ( ( var_Max - RGB.y ) / 6 ) + ( del_Max / 2 ) ) / del_Max; float del_B = ( ( ( var_Max - RGB.z ) / 6 ) + ( del_Max / 2 ) ) / del_Max; if ( RGB.x == var_Max ) HSV.x = del_B - del_G; else if ( var_G == var_Max ) HSV.x = ( 1 / 3 ) + del_R - del_B; else if ( var_B == var_Max ) HSV.z = ( 2 / 3 ) + del_G - del_R; if ( HSV.x < 0 ) ; HSV.x += 1; if ( HSV.x > 1 ) ; HSV.x -= 1; } return HSV; } Vector Color::HSVtoRGB (Vector HSV) { }