Results 1 to 19 of 19

Thread: Hanmacs request

  1. #1

    Default Hanmacs request

    hello @ all

    i try to make a ruby wrapper for clanlib an i steped about some things:

    Circle:
    • why doesnt exist a CL_Circlex<type> template? (or a double form)
    • CL_Rect and CL_Triangle has methods for a point inside, why not the CL_Circle?
      PS: its better if the methods are named equal


    Color:
    • could you please add methods for the HSV-color-space?
    • Gradient only acept CL_Colorf, wouldn't a template better? ( i use color and i couldn't be good converted)


    Triangle:
    • why does the .h includes vec3.h but the triangle uses vec2?
    • or make a 3D Triangle


    CL_Line and other ...

    i'm a little bit confused what line schould i use


    edit:
    has clanlib the skills to play midi files?
    Last edited by Hanmac; 10-23-2009 at 11:46 AM.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Circle:
    • why doesnt exist a CL_Circlex<type> template? (or a double form)
    • CL_Rect and CL_Triangle has methods for a point inside, why not the CL_Circle?
      PS: its better if the methods are named equal
    There is no reason, except nobody has submitted a patch for it.
    You are right, it should be in CL_Circlex<type> form with "point inside" and the numerious circle functions.

    Personally, I don't have time to implement this myself.

    Color:
    • could you please add methods for the HSV-color-space?
    • Gradient only acept CL_Colorf, wouldn't a template better? ( i use color and i couldn't be good converted)
    Control of HSV color space would be nice.

    I'm not sure what you mean about CL_Gradient. Internally clanlib converts all colours to floats (for opengl).

    Also:
    CL_Gradient (const CL_Colorf &first_color, const CL_Colorf &second_color);
    You should be able to call CL_Gradient( CL_Color(255,255,255,255), Cl_Color(255,0,0,255) ) as far as I know.


    Triangle:
    • why does the .h includes vec3.h but the triangle uses vec2?
    • or make a 3D Triangle
    The .h probably includes vec3.h as a mistake. Since vec3.h includes vec2.h, it should be okay.

    Yes, you could have CL_Trangle3f etc. The same with CL_Rect3f etc.
    Nobody has found any need for it.

    CL_Line and other ...

    i'm a little bit confused what line schould i use
    See http://clanlib.org/docs/clanlib-2.0....view/math.html

    CL_Line denotes a line of infinite length
    CL_LineSegment denotes a line with 2 endpoints
    CL_LineRay has a starting point, and a direction vector.

    CL_LineSegment is the most useful, in my opinion.

    In theory, if you draw a horizontal CL_Line, it's length will always be the window width. (Although, we don't have a function to draw CL_Line's)


    edit:
    has clanlib the skills to play midi files?[
    No.

    But it should be easy to do using an external midi library with clanlib. This is how clanVorbis and clanMikmod works.

  3. #3

    Default

    i thy a CL_Circle template for you
    what functions do you think a needed?

    i can also try hsv methods for the color (i have the calc in ruby, but is simple to make it in c++) ... but i must type i 3times or?
    would a superclass better for the color stuff? (with virtual rgba methods?) so i can use the superclass to add the hsv?

    the little problem that i have with CL_Gradient is that i does not get the same color object that i put it in
    the same with all higher classes..

    what audio files are supported? only ogg-vobis?
    for midi i found "libportmidi" i look how clanlib should use it ..
    Last edited by Hanmac; 10-23-2009 at 11:24 PM.

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    i thy a CL_Circle template for you
    what functions do you think a needed?
    To determine point is inside the circle
    bool is_inside( const CL_Vec2<Type> &point )

    To get the closest point on the circle radius from a specifed point (outside the circle, maybe allow inside the circle as well?)
    CL_Vec2<Type> get_closest_point( const CL_Vec2<Type> &point)

    Maybe some get_intersection() or bool is_intersect() with CL_Line/CL_LineSegment/CL_LineRay

    The list could go on and on

    It depends what you find useful

    i can also try hsv methods for the color (i have the calc in ruby, but is simple to make it in c++) ... but i must type i 3times or?
    would a superclass better for the color stuff? (with virtual rgba methods?) so i can use the superclass to add the hsv?
    Adding:
    set_hsv(float h, float s, float v) and a get_hue() + get_saturation() + get_value() to CL_Colorf would be useful

    Remember, CL_Colorf cannot have any more member variables. This is so additional conversion is not required before passing to OpenGL (via an array of CL_Colorf's).

    the little problem that i have with CL_Gradient is that i does not get the same color object that i put it in
    the same with all higher classes..
    I don't care about what happens with CL_Gradient, whatever you think is the best. It is only used in the CL_Draw class. It doesn't do any magic. It's just a wrapper to 4 colors.

    what audio files are supported? only ogg-vobis?
    for midi i found "libportmidi" i look how clanlib should use it ..
    Ogg vorbis
    .wav's
    raw format
    See - http://en.wikipedia.org/wiki/MikMod "Supported formats" for MikMod

  5. #5

    Default

    i think i'm finish with hsv struff:
    Code:
    //Color
    std::vector<int> CL_Color::get_hsv(){
    	std::vector<int> hsv;
    	int min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	int max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    	
    	hsv[1] = max != 0 ? 255 * (max - min) / max : 0;
    	hsv[2] = max;
    	
    	float r = float(max - red) / (max - min);
      float g = float(max - green) / (max - min);
      float b = float(max - blue) / (max - min);
    	switch (max){
    	case get_red(): hsv[0]= (60 * (b - g)).round;break;
    	case get_green(): hsv[0]= (60 * (2 + r - b)).round;break;	
    	case get_red(): hsv[0]= (60 * (4 + g - r)).round;break;	
    	}
    	if (hsv[0] < 0)
    		hsv[0] += 360;
    	return hsv;
    }
    
    int CL_Color::get_hue(){
    	return get_hsv()[0];
    }
    int CL_Color::get_saturation(){
    	return get_hsv()[1];
    }
    int CL_Color::get_value(){
    	return get_hsv()[2];
    }
    
    //hue [0,359]
    //saturation = [0,255]
    //value = [0,255]
    void CL_Color::set_hsv(int hue,int saturation,int value){
    	hue = cl_min(359,cl_max(0,hue));
    	saturation = cl_min(1,cl_max(0,hue));	
    	value = cl_min(1,cl_max(0,hue));
    	if (saturation == 0)
    	{
    		set_red(value);
    		set_green(value);
    		set_blue(value);
    	}else
    	{
    		double h = int(hue / 60);
    		double f = hue / 60 - h;
    		double p = value * (255 - saturation) / 255;
    		double q = value * (255 - saturation * f) / 255;
    		double t = value * (255 - saturation * (255 - f)) / 255;
    		switch(h){
    		case 1:
    			set_red(q);set_green(value);set_blue(p);
    			break;
    		case 2:
    			set_red(p);set_green(value);set_blue(t);
    			break;
    		case 3:
    			set_red(p);set_green(q);set_blue(value);
    			break;
    		case 4:
    			set_red(t);set_green(p);set_blue(value);
    			break;
    		case 5:
    			set_red(value);set_green(p);set_blue(q);
    			break;
    		default:
    			set_red(value);set_green(t);set_blue(p);
    			break;
    		}
    	}
    	
    }
    void CL_Color::set_hue(int hue){
    	std::vector<int> hsv = get_hsv();
    	set_hsv(hue,hsv[1],hsv[2]);	
    }
    
    void CL_Color::set_saturation(int saturation){
    	std::vector<int> hsv = get_hsv();
    	set_hsv(hsv[0],saturation,hsv[2]);	
    }
    
    void CL_Color::set_value(int value){
    	std::vector<int> hsv = get_hsv();
    	set_hsv(hsv[0],hsv[1],value);	
    }
    
    //Colord
    std::vector<double> CL_Colord::get_hsv(){
    	std::vector<double> hsv;
    	double min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	double max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    	
    	hsv[1] = max != 0 ? (max - min) / max : 0;
    	hsv[2] = max;
    	switch (max){
    	case get_red(): hsv[0]= (60 * (get_blue() - get_green())).round;break;
    	case get_green(): hsv[0]= (60 * (2 + get_red() - get_blue())).round;break;	
    	case get_red(): hsv[0]= (60 * (4 + get_green() - get_red())).round;break;	
    	}
    	if (hsv[0] < 0)
    		hsv[0] += 360;
    	return hsv;
    }
    
    double CL_Colord::get_hue(){
    	return get_hsv()[0];
    }
    double CL_Colord::get_saturation(){
    	return get_hsv()[1];
    }
    double CL_Colord::get_value(){
    	return get_hsv()[2];
    }
    
    //hue [0,360]
    //saturation = [0,1]
    //value = [0,1]
    void CL_Colord::set_hsv(double hue,double saturation,double value){
    	hue = cl_min(359,cl_max(0,hue));
    	saturation = cl_min(1,cl_max(0,hue));	
    	value = cl_min(1,cl_max(0,hue));
    	if (saturation == 0)
    	{
    		set_red(value);
    		set_green(value);
    		set_blue(value);
    	}else
    	{
    		double h = int(hue / 60);
    		double f = hue / 60 - h;
    		double p = value * (1 - saturation);
    		double q = value * (1 - saturation * f);
    		double t = value * (1 - saturation * (1 - f));
    		switch(h){
    		case 1:
    			set_red(q);set_green(value);set_blue(p);
    			break;
    		case 2:
    			set_red(p);set_green(value);set_blue(t);
    			break;
    		case 3:
    			set_red(p);set_green(q);set_blue(value);
    			break;
    		case 4:
    			set_red(t);set_green(p);set_blue(value);
    			break;
    		case 5:
    			set_red(value);set_green(p);set_blue(q);
    			break;
    		default:
    			set_red(value);set_green(t);set_blue(p);
    			break;
    		}
    	}
    	
    }
    void CL_Colord::set_hue(double hue){
    	std::vector<double> hsv = get_hsv();
    	set_hsv(hue,hsv[1],hsv[2]);	
    }
    
    void CL_Colord::set_saturation(double saturation){
    	std::vector<double> hsv = get_hsv();
    	set_hsv(hsv[0],saturation,hsv[2]);	
    }
    
    void CL_Colord::set_value(double value){
    	std::vector<double> hsv = get_hsv();
    	set_hsv(hsv[0],hsv[1],value);	
    }
    
    //Colorf
    std::vector<float> CL_Colorf::get_hsv(){
    	std::vector<float> hsv;
    	float min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	float max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    	
    	hsv[1] = max != 0 ? (max - min) / max : 0;
    	hsv[2] = max;
    	switch (max){
    	case get_red(): hsv[0]= (60 * (get_blue() - get_green())).round;break;
    	case get_green(): hsv[0]= (60 * (2 + get_red() - get_blue())).round;break;	
    	case get_red(): hsv[0]= (60 * (4 + get_green() - get_red())).round;break;	
    	}
    	if (hsv[0] < 0)
    		hsv[0] += 360;
    	return hsv;
    }
    
    float CL_Colorf::get_hue(){
    	return get_hsv()[0];
    }
    float CL_Colorf::get_saturation(){
    	return get_hsv()[1];
    }
    float CL_Colorf::get_value(){
    	return get_hsv()[2];
    }
    
    //hue [0,360]
    //saturation = [0,1]
    //value = [0,1]
    void CL_Colorf::set_hsv(float hue,float saturation,float value){
    	hue = cl_min(359,cl_max(0,hue));
    	saturation = cl_min(1,cl_max(0,hue));	
    	value = cl_min(1,cl_max(0,hue));
    	if (saturation == 0)
    	{
    		set_red(value);
    		set_green(value);
    		set_blue(value);
    	}else
    	{
    		float h = int(hue / 60);
    		float f = hue / 60 - h;
    		float p = value * (1 - saturation);
    		float q = value * (1 - saturation * f);
    		float t = value * (1 - saturation * (1 - f));
    		switch(h){
    		case 1:
    			set_red(q);set_green(value);set_blue(p);
    			break;
    		case 2:
    			set_red(p);set_green(value);set_blue(t);
    			break;
    		case 3:
    			set_red(p);set_green(q);set_blue(value);
    			break;
    		case 4:
    			set_red(t);set_green(p);set_blue(value);
    			break;
    		case 5:
    			set_red(value);set_green(p);set_blue(q);
    			break;
    		default:
    			set_red(value);set_green(t);set_blue(p);
    			break;
    		}
    	}
    	
    }
    void CL_Colorf::set_hue(float hue){
    	std::vector<float> hsv = get_hsv();
    	set_hsv(hue,hsv[1],hsv[2]);	
    }
    
    void CL_Colorf::set_saturation(float saturation){
    	std::vector<float> hsv = get_hsv();
    	set_hsv(hsv[0],saturation,hsv[2]);	
    }
    
    void CL_Colorf::set_value(float value){
    	std::vector<float> hsv = get_hsv();
    	set_hsv(hsv[0],hsv[1],value);	
    }
    hue is between 0 and 360

    saturation and value are between 0 and 255 in CL_Color and between 0 and 1 in CL_Colorf and CL_Colord

    in addion to the other headers it needs the cl_math header


    @Circle: i does not found a right method to get the intersections from a cirle with a line
    have you a right?
    Last edited by Hanmac; 10-25-2009 at 04:12 PM.

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    That was fast!

    It looks okay. I personally cannot check it for a couple of week due to other commitments.

    Reference to circle and line. See - http://mathworld.wolfram.com/Circle-...ersection.html .That site contains very good geometry information.

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    For the future, it may be an idea to also add HSL ( http://www.w3.org/TR/2003/CR-css3-co...514/#hsl-color )

  8. #8

    Default

    the problem is that Saturation is diffrent from HSL and HSV ...

    idea what should i do? (enum as parameter?)

  9. #9

    Default

    • Fixed hsv code (there were bugs inside)
    • added hsl


    it should work but its untested

    Code:
    enum ColorSpace{
    HSV,
    HSL
    };
    
    //Color
    std::vector<int> CL_Color::get_hsv(){
    	std::vector<int> hsv;
    	int min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	int max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    	
    	hsv[1] = max != 0 ? 255 * (max - min) / max : 0;
    	hsv[2] = max;
    	
    	float r = float(max - red) / (max - min);
      float g = float(max - green) / (max - min);
      float b = float(max - blue) / (max - min);
    	switch (max){
    	case get_red(): hsv[0]= (60 * (b - g)).round;break;
    	case get_green(): hsv[0]= (60 * (2 + r - b)).round;break;	
    	case get_red(): hsv[0]= (60 * (4 + g - r)).round;break;	
    	}
    	if (hsv[0] < 0)
    		hsv[0] += 360;
    	return hsv;
    }
    
    int CL_Color::get_hue(){
    	return get_hsv()[0];
    }
    int CL_Color::get_saturation(ColorSpace space = HSV ){
    	switch (space){
    	case HSV:
    		return get_hsv()[1];
    	case HSL:
    		return get_hsl()[1];
    	}
    }
    int CL_Color::get_value(){
    	return get_hsv()[2];
    }
    
    std::vector<int> CL_Color::get_hsl(){
    	std::vector<double> hsl;
    	int min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	int max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    
    	hsl[2]= (max + min)/2;
    	if(min == max) {
    		hsl[1]= 0;
    	}else if (l <= 0.5) {
    		hsl[1]= (max - min) / (2*hsl[2]);
    	}else
    		hsl[1]= (max - min) / (2-2*hsl[2]);
    	hsl[1]*=256;
    	hsl[2]*=256;
    	switch (max){
    	case get_red(): hsl[0]= (60 * (get_blue() - get_green())).round;break;
    	case get_green(): hsl[0]= (60 * (2 + get_red() - get_blue())).round;break;	
    	case get_red(): hsl[0]= (60 * (4 + get_green() - get_red())).round;break;	
    	}
    	if (hsl[0] < 0)
    		hsl[0] += 360;
    	return hsl;
    }
    
    //hue [0,359]
    //saturation = [0,255]
    //value = [0,255]
    void CL_Color::set_hsv(int hue,int saturation,int value){
    	hue = cl_min(359,cl_max(0,hue));
    	saturation = cl_min(255,cl_max(0,hue));	
    	value = cl_min(255,cl_max(0,hue));
    	if (saturation == 0)
    	{
    		set_red(value);
    		set_green(value);
    		set_blue(value);
    	}else
    	{
    		double h = int(hue / 60);
    		double f = hue / 60 - h;
    		double p = value * (255 - saturation) / 255;
    		double q = value * (255 - saturation * f) / 255;
    		double t = value * (255 - saturation * (255 - f)) / 255;
    		switch(h){
    		case 1:
    			set_red(q);set_green(value);set_blue(p);
    			break;
    		case 2:
    			set_red(p);set_green(value);set_blue(t);
    			break;
    		case 3:
    			set_red(p);set_green(q);set_blue(value);
    			break;
    		case 4:
    			set_red(t);set_green(p);set_blue(value);
    			break;
    		case 5:
    			set_red(value);set_green(p);set_blue(q);
    			break;
    		default:
    			set_red(value);set_green(t);set_blue(p);
    			break;
    		}
    	}
    	
    }
    
    void CL_Colord::set_hsl(int hue,int saturation,int lightness){
    	
    	t_hue = cl_min(359,cl_max(0,hue)) / 360.0;
    	t_saturation = cl_min(255,cl_max(0,saturation)) / 255.0;
    	t_lightness = cl_min(255,cl_max(0,lightness)) / 255.0;
    	if (t_saturation == 0)
    	{
    		set_red(t_lightness);
    		set_green(t_lightness);
    		set_blue(t_lightness);
    	}else
    	{
    		double q;
    		if (l < 0.5)
    			q = t_lightness * (1+t_saturation)
    		else
    			q = t_lightness + t_saturation - t_lightness * t_saturation;
    		double p = 2 * t_lightness - q;
    		std::vector<double> temp;
    		int i=0;
    		temp[0]=t_hue + 1.0 / 3;
    		temp[1]=t_hue;
    		temp[2]=t_hue - 1.0 / 3;
    		for (i=0;i<2;i++){
    			temp[i]= temp[i] % 1;
    			if (temp[i] < 1.0/6)
    				temp[i] = p + (q - p) * 6 * temp[i];
    			else if (temp[i] < 0.5)
    				temp[i] = q
    			else if (temp[i] < 2.0/3)
    				temp[i] = p + (q - p) * 6 * (2.0/3 - temp[i]);
    		}
    		set_red(temp[0]*256);
    		set_green(temp[1]*256);
    		set_blue(temp[2]*256);
    	}
    }
    
    void CL_Color::set_hue(int hue){
    	std::vector<int> hsv = get_hsv();
    	set_hsv(hue,hsv[1],hsv[2]);	
    }
    
    void CL_Colord::set_saturation(int saturation,ColorSpace space = HSV){
    	switch (space){
    	case HSV:
    		std::vector<int> hsv = get_hsv();
    		set_hsv(hsv[0],saturation,hsv[2]);
    		break;
    	case HSL:	
    		std::vector<int> hsl = get_hsl();
    		set_hsl(hsl[0],saturation,hsl[2]);
    		break;
    	}
    }
    
    void CL_Color::set_value(int value){
    	std::vector<int> hsv = get_hsv();
    	set_hsv(hsv[0],hsv[1],value);	
    }
    
    void CL_Colord::set_lightness(int lightness){
    	std::vector<int> hsl = get_hsl();
    	set_hsl(hsl[0],hsl[1],lightness);	
    }
    
    //Colord
    std::vector<double> CL_Colord::get_hsv(){
    	std::vector<double> hsv;
    	double min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	double max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    	
    	hsv[1] = max != 0 ? (max - min) / max : 0;
    	hsv[2] = max;
    	switch (max){
    	case get_red(): hsv[0]= (60 * (get_blue() - get_green())).round;break;
    	case get_green(): hsv[0]= (60 * (2 + get_red() - get_blue())).round;break;	
    	case get_red(): hsv[0]= (60 * (4 + get_green() - get_red())).round;break;	
    	}
    	if (hsv[0] < 0)
    		hsv[0] += 360;
    	return hsv;
    }
    
    std::vector<double> CL_Colord::get_hsl(){
    	std::vector<double> hsl;
    	double min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	double max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    
    	hsl[2]= (max + min)/2;
    	if(min == max) {
    		hsl[1]= 0;
    	}else if (l <= 0.5) {
    		hsl[1]= (max - min) / (2*hsl[2]);
    	}else
    		hsl[1]= (max - min) / (2-2*hsl[2]);
    
    	switch (max){
    	case get_red(): hsl[0]= (60 * (get_blue() - get_green())).round;break;
    	case get_green(): hsl[0]= (60 * (2 + get_red() - get_blue())).round;break;	
    	case get_red(): hsl[0]= (60 * (4 + get_green() - get_red())).round;break;	
    	}
    	if (hsl[0] < 0)
    		hsl[0] += 360;
    	return hsl;
    }
    
    double CL_Colord::get_hue(){
    	return get_hsv()[0];
    }
    double CL_Colord::get_saturation(ColorSpace space = HSV ){
    	switch (space){
    	case HSV:
    		return get_hsv()[1];
    	case HSL:
    		return get_hsl()[1];
    	}
    }
    double CL_Colord::get_value(){
    	return get_hsv()[2];
    }
    
    //hue [0,360]
    //saturation = [0,1]
    //value = [0,1]
    void CL_Colord::set_hsv(double hue,double saturation,double value){
    	hue = cl_min(359,cl_max(0,hue));
    	saturation = cl_min(1,cl_max(0,saturation));	
    	value = cl_min(1,cl_max(0,value));
    	if (saturation == 0)
    	{
    		set_red(value);
    		set_green(value);
    		set_blue(value);
    	}else
    	{
    		double h = int(hue / 60);
    		double f = hue / 60 - h;
    		double p = value * (1 - saturation);
    		double q = value * (1 - saturation * f);
    		double t = value * (1 - saturation * (1 - f));
    		switch(h){
    		case 1:
    			set_red(q);set_green(value);set_blue(p);
    			break;
    		case 2:
    			set_red(p);set_green(value);set_blue(t);
    			break;
    		case 3:
    			set_red(p);set_green(q);set_blue(value);
    			break;
    		case 4:
    			set_red(t);set_green(p);set_blue(value);
    			break;
    		case 5:
    			set_red(value);set_green(p);set_blue(q);
    			break;
    		default:
    			set_red(value);set_green(t);set_blue(p);
    			break;
    		}
    	}
    	
    }
    
    void CL_Colord::set_hsl(double hue,double saturation,double lightness){
    	hue = cl_min(359,cl_max(0,hue)) / 360;
    	saturation = cl_min(1,cl_max(0,saturation));	
    	lightness = cl_min(1,cl_max(0,lightness));
    	if (saturation == 0)
    	{
    		set_red(lightness);
    		set_green(lightness);
    		set_blue(lightness);
    	}else
    	{
    		double q;
    		if (l < 0.5)
    			q = lightness * (1+saturation)
    		else
    			q = lightness + saturation - lightness * saturation;
    		double p = 2 * lightness - q;
    		std::vector<double> temp;
    		int i=0;
    		temp[0]=hue + 1.0 / 3;
    		temp[1]=hue;
    		temp[2]=hue - 1.0 / 3;
    		for (i=0;i<2;i++){
    			temp[i]= temp[i] % 1;
    			if (temp[i] < 1.0/6)
    				temp[i] = p + (q - p) * 6 * temp[i];
    			else if (temp[i] < 0.5)
    				temp[i] = q
    			else if (temp[i] < 2.0/3)
    				temp[i] = p + (q - p) * 6 * (2.0/3 - temp[i]);
    		}
    		set_red(temp[0]);
    		set_green(temp[1]);
    		set_blue(temp[2]);
    	}
    }
    
    void CL_Colord::set_hue(double hue){
    	std::vector<double> hsv = get_hsv();
    	set_hsv(hue,hsv[1],hsv[2]);	
    }
    
    void CL_Colord::set_saturation(double saturation,ColorSpace space = HSV){
    	switch (space){
    	case HSV:
    		std::vector<double> hsv = get_hsv();
    		set_hsv(hsv[0],saturation,hsv[2]);
    		break;
    	case HSL:	
    		std::vector<double> hsl = get_hsl();
    		set_hsl(hsl[0],saturation,hsl[2]);
    		break;
    	}
    }
    
    void CL_Colord::set_value(double value){
    	std::vector<double> hsv = get_hsv();
    	set_hsv(hsv[0],hsv[1],value);	
    }
    
    void CL_Colord::set_lightness(double lightness){
    	std::vector<double> hsl = get_hsl();
    	set_hsl(hsl[0],hsl[1],lightness);	
    }
    
    //Colorf
    std::vector<float> CL_Colorf::get_hsv(){
    	std::vector<float> hsv;
    	float min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	float max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    	
    	hsv[1] = max != 0 ? (max - min) / max : 0;
    	hsv[2] = max;
    	switch (max){
    	case get_red(): hsv[0]= (60 * (get_blue() - get_green())).round;break;
    	case get_green(): hsv[0]= (60 * (2 + get_red() - get_blue())).round;break;	
    	case get_red(): hsv[0]= (60 * (4 + get_green() - get_red())).round;break;	
    	}
    	if (hsv[0] < 0)
    		hsv[0] += 360;
    	return hsv;
    }
    
    std::vector<float> CL_Colorf::get_hsl(){
    	std::vector<float> hsl;
    	float min = cl_min(get_red(),cl_min(get_blue(),get_green()));
    	float max = cl_max(get_red(),cl_max(get_blue(),get_green()));
    
    	hsl[2]= (max + min)/2;
    	if(min == max) {
    		hsl[1]= 0;
    	}else if (l <= 0.5) {
    		hsl[1]= (max - min) / (2*hsl[2]);
    	}else
    		hsl[1]= (max - min) / (2-2*hsl[2]);
    
    	switch (max){
    	case get_red(): hsl[0]= (60 * (get_blue() - get_green())).round;break;
    	case get_green(): hsl[0]= (60 * (2 + get_red() - get_blue())).round;break;	
    	case get_red(): hsl[0]= (60 * (4 + get_green() - get_red())).round;break;	
    	}
    	if (hsl[0] < 0)
    		hsl[0] += 360;
    	return hsl;
    }
    
    float CL_Colorf::get_hue(){
    	return get_hsv()[0];
    }
    float CL_Colorf::get_saturation(ColorSpace space = HSV ){
    	switch (space){
    	case HSV:
    		return get_hsv()[1];
    	case HSL:
    		return get_hsl()[1];
    	}
    }
    float CL_Colorf::get_value(){
    	return get_hsv()[2];
    }
    
    //hue [0,360]
    //saturation = [0,1]
    //value = [0,1]
    void CL_Colorf::set_hsv(float hue,float saturation,float value){
    	hue = cl_min(359,cl_max(0,hue));
    	saturation = cl_min(1,cl_max(0,saturation));	
    	value = cl_min(1,cl_max(0,value));
    	if (saturation == 0)
    	{
    		set_red(value);
    		set_green(value);
    		set_blue(value);
    	}else
    	{
    		float h = int(hue / 60);
    		float f = hue / 60 - h;
    		float p = value * (1 - saturation);
    		float q = value * (1 - saturation * f);
    		float t = value * (1 - saturation * (1 - f));
    		switch(h){
    		case 1:
    			set_red(q);set_green(value);set_blue(p);
    			break;
    		case 2:
    			set_red(p);set_green(value);set_blue(t);
    			break;
    		case 3:
    			set_red(p);set_green(q);set_blue(value);
    			break;
    		case 4:
    			set_red(t);set_green(p);set_blue(value);
    			break;
    		case 5:
    			set_red(value);set_green(p);set_blue(q);
    			break;
    		default:
    			set_red(value);set_green(t);set_blue(p);
    			break;
    		}
    	}
    	
    }
    
    void CL_Colorf::set_hsl(float hue,float saturation,float lightness){
    	hue = cl_min(359,cl_max(0,hue)) / 360;
    	saturation = cl_min(1,cl_max(0,saturation));	
    	lightness = cl_min(1,cl_max(0,lightness));
    	if (saturation == 0)
    	{
    		set_red(lightness);
    		set_green(lightness);
    		set_blue(lightness);
    	}else
    	{
    		float q;
    		if (l < 0.5)
    			q = lightness * (1+saturation)
    		else
    			q = lightness + saturation - lightness * saturation;
    		float p = 2 * lightness - q;
    		std::vector<float> temp;
    		int i=0;
    		temp[0]=hue + 1.0 / 3;
    		temp[1]=hue;
    		temp[2]=hue - 1.0 / 3;
    		for (i=0;i<2;i++){
    			temp[i]= temp[i] % 1;
    			if (temp[i] < 1.0/6)
    				temp[i] = p + (q - p) * 6 * temp[i];
    			else if (temp[i] < 0.5)
    				temp[i] = q
    			else if (temp[i] < 2.0/3)
    				temp[i] = p + (q - p) * 6 * (2.0/3 - temp[i]);
    		}
    		set_red(temp[0]);
    		set_green(temp[1]);
    		set_blue(temp[2]);
    	}
    }
    
    void CL_Colorf::set_hue(float hue){
    	std::vector<float> hsv = get_hsv();
    	set_hsv(hue,hsv[1],hsv[2]);	
    }
    
    void CL_Colorf::set_saturation(float saturation,ColorSpace space = HSV){
    	switch (space){
    	case HSV:
    		std::vector<float> hsv = get_hsv();
    		set_hsv(hsv[0],saturation,hsv[2]);
    		break;
    	case HSL:	
    		std::vector<float> hsl = get_hsl();
    		set_hsl(hsl[0],saturation,hsl[2]);
    		break;
    	}
    }
    
    void CL_Colorf::set_value(float value){
    	std::vector<float> hsv = get_hsv();
    	set_hsv(hsv[0],hsv[1],value);	
    }
    
    void CL_Colorf::set_lightness(float lightness){
    	std::vector<float> hsl = get_hsl();
    	set_hsl(hsl[0],hsl[1],lightness);	
    }

  10. #10
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Many thanks.

    Looking at the code, we think that it would be better to create a CL_ColorHSVf class and a CL_ColorHSLf class.

    That way, we could formally support different color bases in the future.

    CL_ColorHSVf would contains 3 floats h, s, v, a (alpha )

    CL_Colorf and CL_ColorHSVf constructors can be used to convert between the formats (eg: CL_ColorHSVf::CL_ColorHSVf(const CL_Colorf &rgb); )

    (The same applies for CL_ColorHSV and CL_ColorHSVd)

    It should be simple to adjust your existing patch to use this.

    I'll have a look in a couple of weeks.

  11. #11

    Default

    i dont know if it is a good idea to split it in classes
    (but its no problem, i can combine it again in my wrapper)


    for midi stuff: the best thing i found is midiio its from 2003, but can play midi and the copyright is LGPL.
    or a better idea?

    PS: how could i pack this in a CL_sound_provider?

    PPS: the best thing could be if the sound factory select the sound with using the mime type of the file.


    im working on the circle template.
    that what i have: (without intersect)
    Code:
    #include "point.h"
    template<typename Type>
    class CL_Circlex
    {
    public:
    
    	CL_Circlex()
    	{ return; }
    
    	CL_Circlex(Type x, Type y, Type radius)
    	: position(x,y), radius(radius) { return; }
    
    	/// \brief Constructs a Circle.
    	///
    	/// \param p = Point to use for initial values.
    	/// \param radius = Circle radius.
    	CL_Circlex(const CL_Vec2<Type> &p, Type radius)
    	: position(p), radius(radius) { return; }
    
    // Attributes:
    public:
    	/// \brief Circle center point
    	CL_Vec2<Type> position;
    
    	/// \brief Circle radius
    	Type radius;
    	
    //operations:
    public:
    	bool is_inside( const CL_Vec2<Type> &point ){
    		return radius >= position.distance(point);
    	}
    };

  12. #12
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    i dont know if it is a good idea to split it in classes
    It should be okay, as you will be able to to the following:

    CL_Colorf mycolor;
    float hue = mycolor.get_hsv().h;
    etc

    im working on the circle template.
    Looks good. ( Since it breaks the current API, it'll need to be implemented in ClanLib 2.2.0, but that's not a problem )

    for midi stuff: the best thing i found is midiio its from 2003, but can play midi and the copyright is LGPL.
    or a better idea?
    humm, it looks like it reads a MIDI file and outputs it to a MIDI device.

    It would need to convert the midi file into 8bit or 16bit, or floating point samples for the ClanSound mixer.

    But I have not studied midiio, so I could be wrong

    PS: how could i pack this in a CL_sound_provider?
    PPS: the best thing could be if the sound factory select the sound with using the mime type of the file.
    See Sources/Vorbis or Sources/Mikmod for examples

  13. #13

    Default

    addional ideas for the forms:
    rect,quad and triangle get a method that returns a vector of LineSegments (the sites of the forms)

    the get_intersection of the forms should return an array of vec2, and it should be exist all combines of all this (rect,circle,quad,triangle,line)

    Question about Font:
    how does i can change the italic of a font without making a new font object?

  14. #14

    Default

    idea for intersections (without circle)

    methods for triangle
    Code:
    #include <vector>
    template<typename Type>
    class CL_Trianglex{
    
    std::vector<CL_LineSegment2x<Type>> get_lines(){
    	std::vector<CL_LineSegment2x<Type>> result;
    	result.push_back(CL_LineSegment2x<Type>(p,q));
    	result.push_back(CL_LineSegment2x<Type>(q,r));
    	result.push_back(CL_LineSegment2x<Type>(r,p));
    	return result;
    }
    //witch LineSegment2x
    std::vector<CL_Vec2<Type>> get_intersections(const CL_LineSegment2x<Type> &line){
    	std::vector<CL_Vec2<Type>> result;
    	std::vector<CL_LineSegment2x<Type>> lines = get_lines();
    	bool intersect;
    	CL_Vec2<Type> temp_vec;
    	for (unsigned int i = 0; i < lines.size(); i += 1){
    		temp_vec = line.get_intersection(lines[i],intersect);
    		if (intersect)
    			result.push_back(temp_vec);
    	}
     	return result;	
    }
    //witch trianglex
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Trianglex<Type> &triangle){
    	std::vector<CL_Vec2<Type>> result;
    	std::vector<CL_Vec2<Type>> temp_vec;
    	std::vector<CL_LineSegment2x<Type>> lines = get_lines();
    	for (unsigned int i = 0; i < lines.size(); i += 1){
    		temp_vec=triangle.get_intersections(lines[i]);
    		result.insert(result.end(),temp_vec.begin(),temp_vec.end());
    	}
    	return result;
    }
    //witch quadx
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Quadx<Type> &quad){
    	std::vector<CL_Vec2<Type>> result;
    	std::vector<CL_Vec2<Type>> temp_vec;
    	std::vector<CL_LineSegment2x<Type>> lines = get_lines();
    	for (unsigned int i = 0; i < lines.size(); i += 1){
    		temp_vec=quad.get_intersections(lines[i]);
    		result.insert(result.end(),temp_vec.begin(),temp_vec.end());
    	}
    	return result;
    }
    //witch Rect
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Rectx<Type> &rect){
    	return get_intersections((CL_Quadx<Type>)rect);
    }
    
    }
    methods for quadx
    Code:
    #include <vector>
    template<typename Type>
    class CL_Quadx{
    
    std::vector<CL_LineSegment2x<Type>> get_lines(){
    	std::vector<CL_LineSegment2x<Type>> result;
    	result.push_back(CL_LineSegment2x<Type>(p,q));
    	result.push_back(CL_LineSegment2x<Type>(q,r));
    	result.push_back(CL_LineSegment2x<Type>(r,s));
    	result.push_back(CL_LineSegment2x<Type>(s,p));
    	return result;
    }
    
    std::vector<CL_Vec2<Type>> get_intersections(const CL_LineSegment2x<Type> &line){
    	std::vector<CL_Vec2<Type>> result;
    	std::vector<CL_LineSegment2x<Type>> lines = get_lines();
    	bool intersect;
    	CL_Vec2<Type> temp_vec;
    	for (unsigned int i = 0; i < lines.size(); i += 1){
    		temp_vec = line.get_intersection(lines[i],intersect);
    		if (intersect)
    			result.push_back(temp_vec);
    	}
     	return result;	
    }
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Quadx<Type> &quad){
    	std::vector<CL_Vec2<Type>> result;
    	std::vector<CL_Vec2<Type>> temp_vec;
    	std::vector<CL_LineSegment2x<Type>> lines = get_lines();
    	for (unsigned int i = 0; i < lines.size(); i += 1){
    		temp_vec=quad.get_intersections(lines[i]);
    		result.insert(result.end(),temp_vec.begin(),temp_vec.end());
    	}
    	return result;
    }
    //wich trianglex
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Trianglex<Type> &triangle){
    	std::vector<CL_Vec2<Type>> result;
    	std::vector<CL_Vec2<Type>> temp_vec;
    	std::vector<CL_LineSegment2x<Type>> lines = get_lines();
    	for (unsigned int i = 0; i < lines.size(); i += 1){
    		temp_vec=triangle.get_intersections(lines[i]);
    		result.insert(result.end(),temp_vec.begin(),temp_vec.end());
    	}
    	return result;
    }
    //witch Rect
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Rectx<Type> &rect){
    	return get_intersections((CL_Quadx<Type>)rect);
    }
    }
    methods for rect (rect is similar to a quad)
    Code:
    #include <vector>
    template<typename Type>
    class CL_Rectx{
    
    std::vector<CL_LineSegment2x<Type>> get_lines(){
    	return (CL_Quadx<Type>)this.get_lines();
    }
    std::vector<CL_Vec2<Type>> get_intersections(const CL_LineSegment2x<Type> &line){
    	return (CL_Quadx<Type>)this.get_intersections(line);
    }
    
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Quadx<Type> &quad){
    	return (CL_Quadx<Type>)this.get_intersections(quad);
    }
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Trianglex<Type> &triangle){
    	return (CL_Quadx<Type>)this.get_intersections(triangle);
    }
    //witch Rect
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Rectx<Type> &rect){
    	return get_intersections((CL_Quadx<Type>)rect);
    }
    }
    methods for linesegment
    Code:
    #include <vector>
    template<typename Type>
    class CL_LineSegment2x{
    
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Quadx<Type> &quad){
    	return quad.get_intersections(this);
    }
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Trianglex<Type> &triangle){
    	return triangle.get_intersections(this);
    }
    std::vector<CL_Vec2<Type>> get_intersections(const CL_Rectx<Type> &rect){
    	return rect.get_intersections(this);
    }
    }

    as you can see this functions a similar (equal from code) i think a form class would be better

    PS: th methods a untested, but you could understand the function of the methods?
    (it collect the intersections of all lines from 2 forms.
    if you have 2 quads all 4 lines from one check the intersection with all 4 lines from the other)
    PPS: it could be possible that i count an intersection twice

  15. #15
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Question about Font:
    how does i can change the italic of a font without making a new font object?
    You cannot.

    An italic font is not always just slanted. It depends on the typeface, thus a new font is required.

    If you want an oblique font (slanted font), you can simply apply a shear modelview matrix (note, there isn't a CL_Mat4f function to create one, but you can easily make one manually)

    However, it is possible that it may not look clean, due to not being able to use font subpixel hinting (by freetype or win32 api).

  16. #16
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I have applied the CL_Circlex template to the ClanLib 2.2 SVN

    I have applied the CL_ColorHSVf and CL_ColorHSLf to both ClanLib 2.2 and 2.1 SVN.

    See - http://www.rtsoft.com/forums/showthread.php?t=2947

    Many thanks for your help.

    (Note, I had to modify you code slightly, as there were a couple of minor bugs)

  17. #17

    Default

    i only make ideas, if you modify this is ok
    (but i dont know to download svn)

  18. #18

    Default

    @Color:
    i make a ColorHSVi, and convert it into a Color, then i change it back to a ColorHSVi, but the values are difrent. is it a bug, or a round error because of int?

    @DateTime: to make a wrapper, it could be be good to make const and operator for time_t and the tm structure

    @CL_String: it is posible to make operator for std::string and const char * ?

  19. #19

    Default midi

    for midi i have found:
    http://timidity.sourceforge.net/

    i dont know if you can use it.

Similar Threads

  1. Editor feature request
    By Uhfgood in forum Novashell Game Creation System
    Replies: 0
    Last Post: 07-03-2008, 04:36 AM
  2. Request: Physic tutorial .
    By Rrrichi in forum Novashell Game Creation System
    Replies: 1
    Last Post: 06-05-2007, 11:11 PM
  3. Request concerning forum not novashell itself
    By Uhfgood in forum Novashell Game Creation System
    Replies: 1
    Last Post: 05-07-2007, 11:49 PM
  4. Feature request
    By Tuttle in forum Funeral Quest
    Replies: 5
    Last Post: 07-05-2003, 03:11 PM
  5. Feature Request
    By Fugazi in forum Funeral Quest
    Replies: 1
    Last Post: 11-25-2002, 04:44 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •