コード例 #1
0
void MySensorsOutputLightRGB::setColorReal(const ColorValue &c, bool s)
{
    string nodeId_r = get_param("node_id_red");
    string sensorId_r = get_param("sensor_id_red");
    string nodeId_g = get_param("node_id_green");
    string sensorId_g = get_param("sensor_id_green");
    string nodeId_b = get_param("node_id_blue");
    string sensorId_b = get_param("sensor_id_blue");

    int dataType = MySensors::V_DIMMER;
    if (MySensors::String2DataType(get_param("data_type")) != MySensors::V_ERROR)
        dataType = MySensors::String2DataType(get_param("data_type"));

    int r = 0, g = 0, b = 0;
    if (s)
    {
        r = c.getRed();
        g = c.getGreen();
        b = c.getBlue();
    }

    MySensorsController::Instance(get_params()).setValue(nodeId_r, sensorId_r, dataType, Utils::to_string(r));
    MySensorsController::Instance(get_params()).setValue(nodeId_g, sensorId_g, dataType, Utils::to_string(g));
    MySensorsController::Instance(get_params()).setValue(nodeId_b, sensorId_b, dataType, Utils::to_string(b));
}
コード例 #2
0
void HueOutputLightRGB::setColor(const ColorValue &c)
{
    string url = "http://" + m_host + "/api/" + m_api + "/lights/" + m_idHue + "/state";
    UrlDownloader *dl = new UrlDownloader(url, true);
    string ccolor = "{\"on\":true,"
                   "\"sat\":"  + Utils::to_string((int)(c.getHSVSaturation() * 255.0 / 100.0)) +
                   ",\"bri\":" + Utils::to_string((int)(c.getHSLLightness() * 255.0 / 100.0)) +
                   ",\"hue\":" + Utils::to_string((int)(c.getHSLHue() * 65535.0 / 360.0)) + "}";
    dl->bodyDataSet(ccolor);
    dl->m_signalCompleteData.connect([&](Eina_Binbuf *downloadedData, int status)
    {
        VAR_UNUSED(status);
        cDebugDom("hue") << "datareceived: " << eina_binbuf_string_get(downloadedData);
    });

    dl->httpPut();
}
コード例 #3
0
void HueOutputLightRGB::setColorReal(const ColorValue &c, bool s)
{
    if (!s)
    {
        cDebugDom("hue") << "State OFF ";
        setOff();
    }
    else
    {
        cDebugDom("hue") << "Hue color: " << c.toString();
        setColor(c);
    }
}
コード例 #4
0
DWORD
Material::GetThumbColor(int i, int j, int size)
{
	Color    result = Color::LightGray;

	double   x = i   - size/2;
	double   y = j   - size/2;
	double   r = 0.9 * size/2;
	double   d = sqrt(x*x + y*y);

	if (d <= r) {
		double z = sqrt(r*r - x*x - y*y);

		Point  loc(x,y,z);
		Point  nrm = loc;       nrm.Normalize();
		Point  light(1,-1,1);   light.Normalize();
		Point  eye(0,0,1);

		ColorValue c = Ka * ColorValue(0.25f, 0.25f, 0.25f);  // ambient light
		ColorValue white(1,1,1);

		double diffuse = nrm*light;
		double v       = 1 - (acos(nrm.y)/PI);
		double u       = asin(nrm.x / sin(acos(nrm.y))) / PI + 0.5;

		ColorValue cd  = Kd;
		ColorValue cs  = Ks;
		ColorValue ce  = Ke;

		if (tex_diffuse) {
			int   tu = (int) (u * tex_diffuse->Width());
			int   tv = (int) (v * tex_diffuse->Height());
			cd = Kd * tex_diffuse->GetColor(tu,tv);
		}

		if (tex_emissive) {
			int   tu = (int) (u * tex_emissive->Width());
			int   tv = (int) (v * tex_emissive->Height());
			ce = Ke * tex_emissive->GetColor(tu,tv);
		}

		if (tex_bumpmap && bump != 0 && nrm.z > 0) {
			// compute derivatives B(u,v)
			int   tu = (int) (u * tex_bumpmap->Width());
			int   tv = (int) (v * tex_bumpmap->Height());

			double   du1 = tex_bumpmap->GetColor(tu,tv).Red() - 
			tex_bumpmap->GetColor(tu-1,tv).Red();
			double   du2 = tex_bumpmap->GetColor(tu+1,tv).Red() - 
			tex_bumpmap->GetColor(tu,tv).Red();

			double   dv1 = tex_bumpmap->GetColor(tu,tv).Red() - 
			tex_bumpmap->GetColor(tu,tv-1).Red();
			double   dv2 = tex_bumpmap->GetColor(tu,tv+1).Red() - 
			tex_bumpmap->GetColor(tu,tv).Red();

			double   du  = (du1 + du2) / 512 * 1e-8;
			double   dv  = (dv1 + dv2) / 512 * 1e-8;

			if (du || dv) {
				Point    Nu  = nrm.cross(Point(0,-1,0));  Nu.Normalize();
				Point    Nv  = nrm.cross(Point(1, 0,0));  Nv.Normalize();

				nrm += (Nu*du*bump);
				nrm += (Nv*dv*bump);
				nrm.Normalize();

				diffuse  = nrm*light;
				v        = 1 - (acos(nrm.y)/PI);
				u        = asin(nrm.x / sin(acos(nrm.y))) / PI + 0.5;
			}
		}

		if (tex_specular) {
			int   tu = (int) (u * tex_specular->Width());
			int   tv = (int) (v * tex_specular->Height());
			cs = Ks * tex_specular->GetColor(tu,tv);
		}

		// anisotropic diffuse lighting
		if (brilliance >= 0) {
			diffuse = pow(diffuse, (double)brilliance);
		}

		// forward lighting
		if (diffuse > 0) {
			// diffuse
			c += cd * (white * diffuse);

			// specular
			if (power > 0) {
				double spec = ((nrm * 2*(nrm*light) - light) * eye);
				if (spec > 0.01) {
					spec = pow(spec, (double)power);
					c += cs * (white * spec);
				}
			}
		}

		// back lighting
		else {
			diffuse *= -0.5;
			c += cd * (white * diffuse);

			// specular
			if (power > 0) {
				light *= -1;

				double spec = ((nrm * 2*(nrm*light) - light) * eye);
				if (spec > 0.01) {
					spec = pow(spec, (double)power);
					c += cs * (white * spec) * 0.7;
				}
			}
		}

		c += ce;

		result = c.ToColor();
	}

	return result.Value();
}
コード例 #5
0
ファイル: Viewport.cpp プロジェクト: adan830/FKEngine
	//--------------------------------------------------------------------------------------------------------------
	//设置清空颜色
	void Viewport::SetClearColor( const ColorValue& refColor )
	{
		mdwClearColor = refColor.GetARGB();
	}
コード例 #6
0
graphics::color::RGBAColorValue::RGBAColorValue(const ColorValue &colorValue)
    : m_red(colorValue.GetRed())
    , m_green(colorValue.GetGreen())
    , m_blue(colorValue.GetBlue())
    , m_alpha(colorValue.GetAlpha()) {
}
コード例 #7
0
ファイル: Milight.cpp プロジェクト: DjMomo/calaos_base
ushort Milight::calcMilightColor(const ColorValue &color)
{
    cDebugDom("milight") << "HSL Hue: " << color.getHSLHue();
    ushort mcolor = (256 + 176 - (int)(color.getHSLHue() / 360.0 * 255.0)) % 256;
    return mcolor + 0xFA;
}