Exemplo n.º 1
0
        void Matrix::do_jacobi_rotation(int p, int q, /*out*/ Matrix & current_transformation)
        {
            check_index(p);
            check_index(q);
            
            // check for invalid rotation
            if(p == q)
            {
                Logger::warning("incorrect jacobi rotation: `p` and `q` must be different indices", __FILE__, __LINE__);
                return;
            }
            
            // if element is already zeroed
            if(0 == get_at(p,q))
                return;

            // r is the remaining index: not p and not q
            int r = 3 - p - q;

            // theta is cotangent of Real rotation angle
            Real theta = (get_at(q,q) - get_at(p,p))/get_at(p,q)/2;
            // t is sin/cos of rotation angle
            // it is determined from equation t^2 + 2*t*theta - 1 = 0,
            // which implies from definition of theta as (cos^2 - sin^2)/(2*sin*cos)
            Real t = (0 != theta) ? sign(theta)/(abs(theta) + sqrt(theta*theta + 1)) : 1;
            Real cosine = 1/sqrt(t*t + 1);
            Real sine = t*cosine;
            // tau is tangent of half of rotation angle
            Real tau = sine/(1 + cosine);

            add_at(p, p, - t*get_at(p,q));
            add_at(q, q, + t*get_at(p,q));
            
            // correction to element at (r,p)
            Real rp_correction = - sine*(get_at(r,q) + tau*get_at(r,p));
            // correction to element at (r,q)
            Real rq_correction = + sine*(get_at(r,p) - tau*get_at(r,q));
            add_at(r, p, rp_correction);
            add_at(p, r, rp_correction);
            add_at(r, q, rq_correction);
            add_at(q, r, rq_correction);
            set_at(p, q, 0);
            set_at(q, p, 0);

            // construct matrix of applied jacobi rotation
            Matrix rotation = Matrix::IDENTITY;
            rotation.set_at(p, p, cosine);
            rotation.set_at(q, q, cosine);
            rotation.set_at(p, q, sine);
            rotation.set_at(q, p, - sine);
            current_transformation = current_transformation*rotation;
        }
Exemplo n.º 2
0
void matrix4::initialize_camera(vector3 forward, vector3 up) {
    forward.normalize();
    vector3 f = forward;
    up.normalize();
    vector3 r = up;
    r.normalize();
    r.cross_product(f);
    vector3 u = f;
    u.cross_product(r);
    initialize_identity();
    set_at(0, 0, r.get_x());
    set_at(0, 1, r.get_y());
    set_at(0, 2, r.get_z());
    set_at(1, 0, u.get_x());
    set_at(1, 1, u.get_y());
    set_at(1, 2, u.get_z());
    set_at(2, 0, f.get_x());
    set_at(2, 1, f.get_y());
    set_at(2, 2, f.get_z());
}
Exemplo n.º 3
0
void thread_ssid_msgio(void)
{
	int ret = pthread_detach(pthread_self());
	Debug("pthread_self():%lu, ret[%d]", pthread_self(), ret);
	char mac[32] = {0};
	char ssid[14] = {"FotileAP_"};
	int retssid = 0;
	while (1) 
	{
		fd_set rset, wset;
		FD_ZERO(&rset);
		//FD_ZERO(&wset);
		int i, maxfd, rcvfd;
		maxfd = set_get_max(&ssid_fdset);
		for(i=0;i<set_get_elem_num(&ssid_fdset);i++)
		{
			FD_SET(set_at(&ssid_fdset, i),&rset);
		}
		//FD_SET(socket_fd,&wset);
		struct timeval tval;
		tval.tv_sec = 0;
		tval.tv_usec = 10000;
		if(select(maxfd+1, &rset, NULL, NULL,&tval) > 0)
		{
			int i;
			for(i=0;i<set_get_elem_num(&ssid_fdset);i++)
			{
				if(FD_ISSET(set_at(&ssid_fdset, i), &rset))
				{
					rcvfd = set_at(&ssid_fdset, i);
					break;
				}
			}
			
			char szRcv[MAX_MESSAGE_LEN] = {0};
			int len = 0;
			int lens =0;
			unsigned char mac_arr[6] = {0};		//not use

			if (retssid == 0){
				retssid = get_eth0_mac(mac, mac_arr, 32);
				ssid[9] = mac[12];
				ssid[10] = mac[13];
				ssid[11] = mac[15];
				ssid[12] = mac[16];
				Debug("first time get ssid!");
			}else{

			}
			int ret = recv(rcvfd, szRcv, MAX_MESSAGE_LEN, 0);
			//Info("ret[%d]%s", ret, szRcv);
			if (ret > 0) 
			{
				cJSON *root1 = cJSON_Parse(szRcv);
				cJSON *root2 = cJSON_CreateObject();
				if(strcmp(cJSON_GetObjectItem(root1,"type")->valuestring,"reqssid") == 0)
				{
					cJSON_AddItemToObject(root2, "type", cJSON_CreateString("reqssid"));
					cJSON_AddNumberToObject(root2, "seq", cJSON_GetObjectItem(root1,"seq")->valueint);
					if(retssid > 0)
					{
						cJSON_AddNumberToObject(root2, "respcode", 0);
						cJSON_AddStringToObject(root2, "respmsg", ssid);
					}
					else
					{
						cJSON_AddNumberToObject(root2, "respcode", -1);
						cJSON_AddStringToObject(root2,"respmsg",  "error:get ssid failed!");
					}
					char *out = cJSON_Print(root2);
					//Info("out[%s]", out);
					lens = strlen(out);
					send(rcvfd, out , lens ,0);
					//Info("%s",rendered);
					cJSON_Delete(root1);
					cJSON_Delete(root2);
					free(out);
				}else{
					Warn("param error!");
				}
			} 
			else
			{
				//Warn("[fd:%d]rcv error! close socket", rcvfd);
				set_erase(rcvfd, &ssid_fdset);
				close(rcvfd);
			}
		}
	}
}
Exemplo n.º 4
0
void language::load(const string& Path, const string& Language, int CountNeed)
{
	SCOPED_ACTION(GuardLastError);

	auto Data = m_Data->create();

	const auto LangFileData = OpenLangFile(Path, LangFileMask, Language);
	const auto& LangFile = std::get<0>(LangFileData);
	const auto LangFileCodePage = std::get<2>(LangFileData);

	if (!LangFile)
	{
		throw MAKE_EXCEPTION(exception, L"Cannot find language data"sv);
	}

	Data->m_FileName = LangFile.GetName();

	if (CountNeed != -1)
	{
		Data->reserve(CountNeed);
	}

	std::unordered_map<string, size_t> id_map;
	string label, text;
	for (const auto& i: enum_file_lines(LangFile, LangFileCodePage))
	{
		bool have_text;
		parse_lng_line(trim(i.Str), label, text, have_text);
		if (have_text)
		{
			auto idx = Data->size();
			Data->add(ConvertString(text));
			if (!label.empty())
			{
				id_map[label] = idx;
				label.clear();
			}
		}
	}

	//   Проведем проверку на количество строк в LNG-файлах
	if (CountNeed != -1 && CountNeed != static_cast<int>(Data->size()))
	{
		throw MAKE_EXCEPTION(exception, Data->m_FileName + L": language data is incorrect or damaged"sv);
	}

	// try to load Far<LNG>.lng.custom file(s)
	//
	if (!id_map.empty())
	{
		const auto& LoadStrings = [&](const string& FileName)
		{
			const os::fs::file CustomFile(FileName, FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING);
			if (!CustomFile)
				return;

			const auto CustomFileCodepage = GetFileCodepage(CustomFile, encoding::codepage::oem(), nullptr, false);
			label.clear();
			for (const auto& i: enum_file_lines(CustomFile, CustomFileCodepage))
			{
				bool have_text;
				parse_lng_line(trim(i.Str), label, text, have_text);
				if (have_text && !label.empty())
				{
					const auto found = id_map.find(label);
					if (found != id_map.end())
					{
						Data->set_at(found->second, ConvertString(text));
					}
					label.clear();
				}
			}
		};

		const auto CustomLngInSameDir = Data->m_FileName + L".custom"sv;
		const auto CustomLngInProfileDir = concat(Global->Opt->ProfilePath, L'\\', ExtractFileName(CustomLngInSameDir));

		LoadStrings(CustomLngInSameDir);
		LoadStrings(CustomLngInProfileDir);
	}

	m_Data = std::move(Data);
}