示例#1
0
文件: scene.cpp 项目: yxrkt/DigiPen
void CreateScene(Scene& scene)
{
	scene.Clear();

	scene.EnableLighting = false;
	scene.EnableFlatShading = false;

	TileTexture* tile = new TileTexture(256,256);
	WoodTexture* wood = new WoodTexture(256,256);

	scene.SetAmbient(Color(0.4, 0.4, 0.4));
	scene.AddLight(Point3D(100,80,50), Color(0.8, 0.8, 0.8));
	scene.AddLight(Point3D(-100,-80,-50), Color(0.8, 0.8, 0.8));

	scene.SetTexture(tile, NULL);
	scene.modeling.Push();
	scene.modeling.Translate(-0.6, 0.0, 0);
	scene.SetColor(HSVColor(0.083, 0.75, 0.8), HSVColor(0.0, 0.0, 0.0), 0);
	CreateRect(scene, 1.0, 1.0);
	scene.modeling.Pop();

	scene.SetTexture(wood, NULL);
	scene.modeling.Push();
	scene.modeling.Translate(0.6, 0.0, 0);
	scene.SetColor(HSVColor(0.125, 0.7, 0.8), HSVColor(0.0, 0.0, 0.0), 0);
	CreateRect(scene, 1.0, 1.0);
	scene.modeling.Pop();
}
示例#2
0
HSVColor HSVColor::Shade(float amount) const
{
    float v = value - amount;
    v = std::max(0.0f, v);

    return HSVColor(hue, saturation, v, alpha);
}
示例#3
0
HSVColor HSVColor::Tint(float amount) const
{
    float s = saturation - amount;
    s = std::max(0.0f, s);

    return HSVColor(hue, s, value, alpha);
}
示例#4
0
HSVColor HSVColor::Complement() const
{
    float h = hue - 0.5f;
    if(h < 0.0f) 
        h += 1.0f;
    return HSVColor(h, saturation, value, alpha);
}
示例#5
0
void Scene04::spectrumPixels(PixelBuffer* pixels, int filter)
{
	// hue, saturation, brightness
	HSVColor hsv = HSVColor(0.0f, 0.0f, 1.0f); // initially white

	long counter = 0;
	for (long y=0; y<pixels->height; y++) {
		for (long x=0; x<pixels->width; x++) {
			RGBAColor rgb = Color::HSV2RGBA(hsv);

			pixels->data[counter+0] = rgb.r;
			pixels->data[counter+1] = rgb.g;
			pixels->data[counter+2] = rgb.b;
			if (pixels->bitdepth == 4) {
				pixels->data[counter+3] = 1.0f;
			}

			counter += pixels->bitdepth;
			hsv.h += 1.0f/pixels->width; if (hsv.h > 1.0f) { hsv.h -= 1.0f; } // Hue
		}

		if (y < pixels->height/2) {
			hsv.s += 1.0f/pixels->height*2; if (hsv.s > 1.0f) { hsv.s -= 1.0f; } // Saturation
		} else {
			hsv.v -= 1.0f/pixels->height*2; if (hsv.v < 0.0f) { hsv.v += 1.0f; } // Brightness
		}
	}
	pixels->filter = filter;
	pixels->wrap = 2; // clamp
}
示例#6
0
文件: window.cpp 项目: chichichap/Cpp
void Window::hsvChanged()
{
    // Calculate a new RGB Color from our HSV sliders
    RGBColor newRGB = HSVtoRGB(HSVColor((GLfloat)hSlider->value(), (GLfloat)sSlider->value()/100.0f , (GLfloat)vSlider->value()/100.0f ));

    // convert GLfloats to ints for Qt
    int r = (int)floor((double)newRGB.r * 255.0);
    int g = (int)floor((double)newRGB.g * 255.0);
    int b = (int)floor((double)newRGB.b * 255.0);

    rSlider->blockSignals(true);
    gSlider->blockSignals(true);
    bSlider->blockSignals(true);
    // update RGB slider positions
    rSlider->setValue(r);
    gSlider->setValue(g);
    bSlider->setValue(b);

    rSlider->blockSignals(false);
    gSlider->blockSignals(false);
    bSlider->blockSignals(false);

    // update RGB label values
    rLabel->setNum(r);
    gLabel->setNum(g);
    bLabel->setNum(b);

    // update Color Frame
    setColorFrame(r,g,b);

    //signal the glwidget with the new color
    emit colorChanged(newRGB);
}
示例#7
0
文件: scene.cpp 项目: yxrkt/DigiPen
void CreateScene(Scene& scene)
{
	scene.Clear();

	scene.EnableLighting = false;
	scene.EnableFlatShading = false;

	ReflTexture* refl = new ReflTexture();

	scene.SetAmbient(Color(0.4, 0.4, 0.4));
	scene.AddLight(Point3D(0,-100,80), Color(0.8, 0.8, 0.8));

	scene.SetTexture(NULL, NULL, refl);
	scene.modeling.Push();
	scene.SetColor(HSVColor(0.66, 1.0, 0.9), HSVColor(0.0, 0.0, 1.5), 120);
	Reflector(scene, 12*4, 12*4);
	scene.modeling.Pop();
}
示例#8
0
文件: scene.cpp 项目: yxrkt/DigiPen
void CreateScene(Scene& scene)
{
	scene.Clear();

	scene.EnableLighting = true;
	scene.EnableFlatShading = false;

	float r = 0.5;
	float count = 12;

	scene.SetAmbient(Color(0.2, 0.2, 0.2));
	scene.AddLight(Point3D(100,0,30), Color(0.8, 0.8, 0.8));
	scene.AddLight(Point3D(0,100,80), Color(0.5, 0.5, 0.5));

	// Red octant: Moderate specular, moderate shininess
	scene.modeling.Push();
	scene.SetColor(HSVColor(0.00, 1.0, 0.7), HSVColor(0.0, 0.0, 0.8), 30);
	scene.modeling.Translate( 0.5, -0.5, 0);
	CreateSphereOctant(scene, r, count);
	scene.modeling.Pop();

	// Blue octant: High specular, high shininess
	scene.modeling.Push();
	scene.SetColor(HSVColor(0.66, 1.0, 0.9), HSVColor(0.0, 0.0, 1.5), 120);
	scene.modeling.Translate(-0.5,  0.5, 0);
	CreateSphereOctant(scene, r, count);
	scene.modeling.Pop();

	// Green octant:  No specular
	scene.modeling.Push();
	scene.SetColor(HSVColor(0.33, 1.0, 0.7), HSVColor(0.0, 0.0, 0.0), 0);
	scene.modeling.Translate(-0.5, -0.5, 0);
	CreateSphereOctant(scene, r, count);
	scene.modeling.Pop();
}
示例#9
0
HSVColor RGB2HSV(const RGBColor & rgb)
{
	double r = rgb.red() / 255.0;
	double g = rgb.green() / 255.0;
	double b = rgb.blue() / 255.0;

	// Calculate chroma
	double maxColor = Max(r, g, b);
	double minColor = Min(r, g, b);
	double chroma = maxColor - minColor;
	
	// Calculate hue
	double hue = 0;
	if (chroma != 0)
	{
		if (maxColor == r)
		{
			hue = (g - b / chroma) * 60.0;
		}
		else if (maxColor == g)
		{
			hue = (2 + (b - r) / chroma) * 60.0;
		}
		else // maxColor == b
		{
			assert(maxColor == b);
			hue = (4 + (r - g) / chroma) * 60.0;
		}
		if (hue < 0)
		{
			hue += 360.0;
		}
		assert(hue >= 0 && hue < 360);
	}

	double saturation = 0;
    if (maxColor != 0)
    {
        saturation = chroma / maxColor;
    }
	assert(saturation >= 0 && saturation <= 1);

	double value = maxColor;
	assert(value >= 0 && value <= 1);

	return HSVColor(static_cast<int>(0.5 + hue),
				    static_cast<int>(0.5 + 100.0 * saturation),
					static_cast<int>(0.5 + 100.0 * value));
}
示例#10
0
文件: ocoltbl.cpp 项目: mecirt/7k2
// -------- begin of function ColorTable::rgb2hsv ---------//
HSVColor ColorTable::rgb2hsv(RGBColor &rgb)
{
	if( rgb.red == rgb.green && rgb.red == rgb.blue)
	{
		return HSVColor(1.0, 0.0, rgb.red / 255.0);
	}

	// find the smallest colour
	if( rgb.red <= rgb.green && rgb.red <= rgb.blue)
	{
		if( rgb.green >= rgb.blue )
		{
			// g is the primary, b is secondary
			return HSVColor( 2.0 + (double) rgb.blue/ rgb.green, 
				rgb.blue != 0 ? 1.0 - (double) rgb.red / rgb.blue : 1.0,
				rgb.green / 255.0);
		}
		else
		{
			// b is the primary, g is secondary
			return HSVColor( 4.0 - (double) rgb.green / rgb.blue,
				rgb.green != 0 ? 1.0 - (double) rgb.red/ rgb.green : 1.0,
				rgb.blue / 255.0);
		}
	}
	else if( rgb.green <= rgb.red && rgb.green <= rgb.blue)
	{
		if( rgb.red >= rgb.blue)
		{
			// r is the primary, b is secondary
			return HSVColor( 6.0 - (double)rgb.blue/rgb.red,
				rgb.blue!=0 ? 1.0 - (double)rgb.green/rgb.blue: 1.0,
				rgb.red / 255.0);
		}
		else
		{
			// b is the primary, r is secondary
			return HSVColor( 4.0 + (double)rgb.red/rgb.blue,
				rgb.red!=0 ? 1.0 - (double)rgb.green/rgb.red: 1.0,
				rgb.blue / 255.0);
		}
	}
	else if( rgb.blue <= rgb.red && rgb.blue <= rgb.green)
	{
		if( rgb.red >= rgb.green)
		{
			// r is the primary, g is secondary
			return HSVColor( (double)rgb.green/rgb.red,
				rgb.green!=0 ? 1.0 - (double)rgb.blue/rgb.green: 1.0,
				rgb.red / 255.0);
		}
		else
		{
			// g is the primary, r is secondary
			return HSVColor( 2.0 - (double)rgb.red/rgb.green,
				rgb.red!=0 ? 1.0 - (double)rgb.blue/rgb.red: 1.0,
				rgb.green / 255.0);
		}
	}
	else
	{
		err_when(1);
		return HSVColor( 1.0, 0.0, rgb.red / 255.0);
	}
}
示例#11
0
	HSVColor HSVColor::operator+(const HSVColor& c)
	{
		return HSVColor(hue_+c.hue_, sat_+c.sat_, val_+c.val_);
	}
示例#12
0
	HSVColor HSVColor::operator*(double w)
	{
		return HSVColor(hue_*w,val_*w,sat_*w);
	}