Example #1
0
Light * Scene::GetNearestDynamicLight(Light::eType type, Vector3 position)
{
    switch(type)
    {
        case Light::TYPE_DIRECTIONAL:
            
            break;
            
        default:
            break;
    };
    
	float32 squareMinDistance = 10000000.0f;
	Light * nearestLight = 0;

	Set<Light*> & lights = GetLights();
	const Set<Light*>::iterator & endIt = lights.end();
	for (Set<Light*>::iterator it = lights.begin(); it != endIt; ++it)
	{
		Light * node = *it;
		if(node->IsDynamic())
		{
			const Vector3 & lightPosition = node->GetPosition();

			float32 squareDistanceToLight = (position - lightPosition).SquareLength();
			if (squareDistanceToLight < squareMinDistance)
			{
				squareMinDistance = squareDistanceToLight;
				nearestLight = node;
			}
		}
	}

	return nearestLight;
}
Example #2
0
void CVehicle::StoreEmptyVehicle(EMPTYVEHICLESYNCPACKET * syncPacket)
{
	// Check stuff
	if(syncPacket->bLights != GetLights())
		SetLights(syncPacket->bLights);

	if(syncPacket->bSirenState != GetSirenState())
		SetSirenState(syncPacket->bSirenState);

	if(syncPacket->bTaxiLights != GetTaxiLights())
		TurnTaxiLights(syncPacket->bTaxiLights);

	if(syncPacket->fDirtLevel != GetDirtLevel())
		SetDirtLevel(syncPacket->fDirtLevel);

	if(syncPacket->fPetrolHealth != GetPetrolTankHealth())
		SetPetrolTankHealth(syncPacket->fPetrolHealth);

	if(syncPacket->uiHealth != GetHealth())
		SetHealth(syncPacket->uiHealth);

	// Only when the vehicle stands still -> update stuff
	/*if(syncPacket->vecMoveSpeed.Length() == 0)
	{
		CVector3 vecPos; GetPosition(vecPos);
		if((vecPos-syncPacket->vecPosition).Length() > 5.0f || (vecPos-syncPacket->vecPosition).Length() < -5.0f)
			SetPosition(syncPacket->vecPosition);

		CVector3 vecRot; GetRotation(vecRot);
		if((vecRot-syncPacket->vecRotation).Length() > 5.0f || (vecRot-syncPacket->vecRotation).Length() < -5.0f)
			SetRotation(syncPacket->vecRotation);

		CVector3 vecTurnSpeed; GetTurnSpeed(vecTurnSpeed);
		if((vecTurnSpeed-syncPacket->vecTurnSpeed).Length() > 5.0f || (vecTurnSpeed-syncPacket->vecTurnSpeed).Length() < -5.0f)
			SetTurnSpeed(syncPacket->vecTurnSpeed);

		CVector3 vecMoveSpeed; GetMoveSpeed(vecMoveSpeed);
		if((vecMoveSpeed-syncPacket->vecMoveSpeed).Length() > 5.0f || (vecMoveSpeed-syncPacket->vecMoveSpeed).Length() < -5.0f)
			SetMoveSpeed(syncPacket->vecMoveSpeed);
	}*/

	/*for(unsigned int ui = 0; ui <= 3; ui++)
	{
		if(syncPacket->bWindow[ui] != m_bWindow[ui])
			SetWindowState(ui, syncPacket->bWindow[ui]);
	}

	for(unsigned int ui = 0; ui <= 5; ui++)
	{
		if(syncPacket->bTyre[ui] != m_bTyre[ui])
			SetTyreState(ui, syncPacket->bTyre[ui]);
	}*/
}
Example #3
0
bool CPhilipsHue::GetStates()
{
	std::vector<std::string> ExtraHeaders;
	std::string sResult;

#ifdef DEBUG_PhilipsHue
	sResult= ReadFile("E:\\philipshue.json");
#else
	std::stringstream sstr2;
	sstr2 << "http://" << m_IPAddress
		<< ":" << m_Port
		<< "/api/" << m_UserName;
	//Get Data
	std::string sURL = sstr2.str();
	if (!HTTPClient::GET(sURL, ExtraHeaders, sResult))
	{
		_log.Log(LOG_ERROR, "Philips Hue: Error getting Light States, (Check IPAddress/Username)");
		return false;
	}
#endif
#ifdef DEBUG_PhilipsHue2
	SaveString2Disk(sResult, "E:\\philipshue.json");
#endif

	Json::Value root;

	Json::Reader jReader;
	bool ret = jReader.parse(sResult, root);
	if (!ret)
	{
		_log.Log(LOG_ERROR, "Philips Hue: Invalid data received, or invalid IPAddress/Username!");
		return false;
	}

	if (sResult.find("\"error\":") != std::string::npos)
	{
		//We had an error
		_log.Log(LOG_ERROR, "Philips Hue: Error received: %s", root[0]["error"]["description"].asString().c_str());
		return false;
	}


	if (!GetLights(root))
	{
		//_log.Log(LOG_ERROR, "Philips Hue: No Lights found!");
		return false;
	}
	GetGroups(root);
	GetScenes(root);
	return true;
}