示例#1
0
// Compute the derived values if required ...
void FGQuaternion::ComputeDerivedUnconditional(void) const
{
  mCacheValid = true;
  
  // First normalize the 4-vector
  double norm = Magnitude();
  if (norm == 0.0)
    return;

  double rnorm = 1.0/norm;
  double q1 = rnorm*Entry(1);
  double q2 = rnorm*Entry(2);
  double q3 = rnorm*Entry(3);
  double q4 = rnorm*Entry(4);

  // Now compute the transformation matrix.
  double q1q1 = q1*q1;
  double q2q2 = q2*q2;
  double q3q3 = q3*q3;
  double q4q4 = q4*q4;
  double q1q2 = q1*q2;
  double q1q3 = q1*q3;
  double q1q4 = q1*q4;
  double q2q3 = q2*q3;
  double q2q4 = q2*q4;
  double q3q4 = q3*q4;
  
  mT(1,1) = q1q1 + q2q2 - q3q3 - q4q4;
  mT(1,2) = 2.0*(q2q3 + q1q4);
  mT(1,3) = 2.0*(q2q4 - q1q3);
  mT(2,1) = 2.0*(q2q3 - q1q4);
  mT(2,2) = q1q1 - q2q2 + q3q3 - q4q4;
  mT(2,3) = 2.0*(q3q4 + q1q2);
  mT(3,1) = 2.0*(q2q4 + q1q3);
  mT(3,2) = 2.0*(q3q4 - q1q2);
  mT(3,3) = q1q1 - q2q2 - q3q3 + q4q4;
  // Since this is an orthogonal matrix, the inverse is simply
  // the transpose.
  mTInv = mT;
  mTInv.T();
  
  // Compute the Euler-angles
  if (mT(3,3) == 0.0)
    mEulerAngles(ePhi) = 0.5*M_PI;
  else
    mEulerAngles(ePhi) = atan2(mT(2,3), mT(3,3));
  
  if (mT(1,3) < -1.0)
    mEulerAngles(eTht) = 0.5*M_PI;
  else if (1.0 < mT(1,3))
    mEulerAngles(eTht) = -0.5*M_PI;
  else
    mEulerAngles(eTht) = asin(-mT(1,3));
  
  if (mT(1,1) == 0.0)
    mEulerAngles(ePsi) = 0.5*M_PI;
  else {
    double psi = atan2(mT(1,2), mT(1,1));
    if (psi < 0.0)
      psi += 2*M_PI;
    mEulerAngles(ePsi) = psi;
  }
  
  // FIXME: may be one can compute those values easier ???
  mEulerSines(ePhi) = sin(mEulerAngles(ePhi));
  // mEulerSines(eTht) = sin(mEulerAngles(eTht));
  mEulerSines(eTht) = -mT(1,3);
  mEulerSines(ePsi) = sin(mEulerAngles(ePsi));
  mEulerCosines(ePhi) = cos(mEulerAngles(ePhi));
  mEulerCosines(eTht) = cos(mEulerAngles(eTht));
  mEulerCosines(ePsi) = cos(mEulerAngles(ePsi));
}
示例#2
0
void *wxThread::CallEntry()
{
    wxON_BLOCK_EXIT0(wxThreadSpecificInfo::ThreadCleanUp);
    return Entry();
}
示例#3
0
/** Returns the derivative of the quaternion corresponding to the
    angular velocities PQR.
    See Stevens and Lewis, "Aircraft Control and Simulation", Second Edition,
    Equation 1.3-36. 
*/
FGQuaternion FGQuaternion::GetQDot(const FGColumnVector3& PQR) const {
  double norm = Magnitude();
  if (norm == 0.0)
    return FGQuaternion::zero();
  double rnorm = 1.0/norm;

  FGQuaternion QDot;
  QDot(1) = -0.5*(Entry(2)*PQR(eP) + Entry(3)*PQR(eQ) + Entry(4)*PQR(eR));
  QDot(2) =  0.5*(Entry(1)*PQR(eP) + Entry(3)*PQR(eR) - Entry(4)*PQR(eQ));
  QDot(3) =  0.5*(Entry(1)*PQR(eQ) + Entry(4)*PQR(eP) - Entry(2)*PQR(eR));
  QDot(4) =  0.5*(Entry(1)*PQR(eR) + Entry(2)*PQR(eQ) - Entry(3)*PQR(eP));
  return rnorm*QDot;
}
示例#4
0
bool Config::init(const char *subPath){
	size_t len = subPath? strlen(subPath) : 0;

#ifdef _WIN32
	path = new char[len + 16];
	strcpy(path, "SOFTWARE\\Humus");
	if (len){
		strcat(path + 14, "\\%s");
	}

	HKEY hkey;
	if (RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey) == ERROR_SUCCESS){
		char name[256];
		unsigned long type, nameSize = sizeof(name);
		unsigned long value, valueSize;

		unsigned int i = 0;
		while (RegEnumValue(hkey, i, name, &nameSize, NULL, &type, NULL, NULL) != ERROR_NO_MORE_ITEMS){
			if (type == REG_DWORD){
				valueSize = sizeof(value);
				if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE) &value, &valueSize) == ERROR_SUCCESS){
					entries.add(Entry(name, (int) value, false));
				}
			}
			nameSize = sizeof(name);
			i++;
		}
		RegCloseKey(hkey);
		return true;
	}

#else

	char *home = getenv("HOME");

	path = new char[len + strlen(home) + 23];
	int pos = sprintf(path, "%s/.humus", home);
	mkdir(path, 0777);
	if (len){
		pos += sprintf(path + pos, "/%s", subPath);
		mkdir(path, 0777);
	}
	strcpy(path + pos, "/settings.conf");

	Tokenizer tok(2);
	if (tok.setFile(path)){
		char *name, *value;
		while ((name = tok.next()) != NULL){
			if ((value = tok.nextAfterToken("=")) != NULL){
				if ((name[0] >= 'A' && name[0] <= 'Z') || (name[0] >= 'a' && name[0] <= 'z')){
					entries.add(Entry(name, atoi(value), false));
				}
				tok.goToNext();
			}
		}

		return true;
	}
	
#endif

	return false;
}
示例#5
0
文件: protocol.cpp 项目: Robby-/anope
Anope::string IRCDProto::NormalizeMask(const Anope::string &mask)
{
	if (IsExtbanValid(mask))
		return mask;
	return Entry("", mask).GetNUHMask();
}
示例#6
0
Entry maxBlue(unsigned char src,Entry dest) { 
    return Entry(src > dest.blue ? src : dest.blue,dest.red); 
}
示例#7
0
wxThreadError wxThread::Create()
{
    p_internal->exit_status = Entry();
    OnExit();
    return wxTHREAD_NO_ERROR;
}
示例#8
0
void Router::parseNeighborhood(char* str_orig)
{
	char *str = strcopy(str_orig + 1); // pour le [
	str[strlen(str) - 1] = 0; // pour le ]

	if(strcmp(str, "") != 0)
	{
		std::vector<char*> v;
		// 1 : on extrait chaque groupe d'infos (séparés par ;)
		char * r = strtok(str, ";");
		if(r != NULL)
			v.push_back(r);

		while((r = strtok(NULL, ";")) != NULL)
		{
			v.push_back(r);
		}


		// à ce moment, on a dans v : | a,b,c:d  | e,f,g:h |  par ex.
		// (si vect = [a,b,c,d;e,f,g,h;...])

		std::vector<char*>::iterator i;
		std::vector<std::string> routerNames;

		// On ajoute ceux qui ne sont pas dans la table
		for(i = v.begin(); i != v.end(); ++i)
		{
			std::string s(strtok((*i), ","));
			routerNames.push_back(s);
			if(s.compare(std::string(getName())) != 0)
			{
				if(routeTable.find(s) == routeTable.end())
				{
                    routeTable[s] = Entry(s, s, atoi(strtok(NULL, ",")));

                    char * ip = strtok(strtok(NULL, ","), ":");
					int port = atoi(strtok(NULL, ":"));
					Client *c = network__connect(net, ip, port);
					strcpy(c->id, s.c_str());
					routeTable[s].setClient(c);
					routeTable[s].isNeighbor() = true;
					routeTable[s].isComplete() = true;

					this->saction->link(c);
				}
				else if(!routeTable[s].isComplete())
				{
					routeTable[s].dist() = atoi(strtok(NULL, ","));
					//~ char * ip = strtok(strtok(NULL, ","), ":");
					//~ int port = atoi(strtok(NULL, ":"));
					//~ Client *c = network__connect(net, ip, port); // OBSOLETE !
					//~ strcpy(c->id, s.c_str());
					//~ routeTable[s].setClient(c);
					routeTable[s].isNeighbor() = true;
					routeTable[s].isComplete() = true;
				}
				else
				{
					routeTable[s].dist() = atoi(strtok(NULL, ","));
					strtok(strtok(NULL, ","), ":");
					strtok(NULL, ":");
				}
			}
		}

		RouteTable::iterator k;
		// On enlève ceux qui n'y sont plus
		for(k = routeTable.begin(); k != routeTable.end(); k++)
		{
			if(std::find(routerNames.begin(), routerNames.end(), (*k).first) == routerNames.end() && (*k).second.isNeighbor())
			{
				network__disconnect(net, (*k).second.client());
				routeTable.erase(k);
			}

			if(std::find(routerNames.begin(), routerNames.end(), (*k).second.nextHop()) == routerNames.end() && !(*k).second.isNeighbor())
			{
				routeTable.erase(k);
			}
		}
	}
	else // on vide la table de routage
	{
		routeTable.clear();
	}
	free(str);
}
示例#9
0
Playlist::Entries XSPF::read()
{
	Reader *reader = ioCtrl.rawPtr<Reader>();
	Entries list;

	const QString playlistPath = getPlaylistPath(reader->getUrl());

	QXmlStreamReader xmlReader(reader->read(reader->size()));
	bool inTrack = false, inExtension = false;
	Entry curr;

	while (!xmlReader.atEnd() && !xmlReader.hasError())
	{
		const QXmlStreamReader::TokenType token = xmlReader.readNext();
		const QStringRef name = xmlReader.name();
		switch (token)
		{
			case QXmlStreamReader::StartElement:
				if (name == "track")
					inTrack = true;
				else if (inTrack)
				{
					if (name == "extension")
					{
						if (xmlReader.attributes().value("application") == "QMPlay2")
							inExtension = true;
					}
					else
					{
						const QString value = xmlReader.readElementText();
						if (name == "location")
							curr.url = Functions::Url(QUrl::fromPercentEncoding(value.toUtf8()), playlistPath);
						else if (name == "title")
							curr.name = value;
						else if (name == "duration")
							curr.length = value.toInt() / 1000.0;
						if (inExtension)
						{
							if (name == "f")
								curr.flags = value.toInt();
							else if (name == "q")
								curr.queue = value.toInt();
							else if (name == "g")
								curr.GID = value.toInt();
							else if (name == "p")
								curr.parent = value.toInt();
						}
					}
				}
				break;
			case QXmlStreamReader::EndElement:
				if (name == "extension")
					inExtension = false;
				else if (name == "track")
				{
					if (inTrack)
					{
						if (curr.name.isEmpty())
							curr.name = Functions::fileName(curr.url, false);
						list += curr;
					}
					curr = Entry();
					inTrack = false;
				}
				break;
			default:
				break;
		}
	}

	return list;
}
示例#10
0
bool Scenes::Menu::initialize()
{
	Shader.reset(new PMX::PMXShader);
	assert(Shader);
	if (!Shader->InitializeBuffers(Renderer->GetDevice(), nullptr))
		return false;
	Shader->SetLightCount(1);
	Shader->SetLights(DirectX::XMVectorSplatOne(), DirectX::XMVectorSplatOne(), DirectX::XMVectorSplatOne(), DirectX::XMVectorSet(-1.0f, -1.0f, 1.0f, 0.0f), DirectX::XMVectorZero(), 0);

	auto &Viewport = Renderer->getViewport();
	Camera.reset(new Renderer::Camera(DirectX::XM_PIDIV4, (float)Viewport.Width / (float)Viewport.Height, Renderer::SCREEN_NEAR, Renderer::SCREEN_DEPTH));
	assert(Camera);
	Camera->SetPosition(0, 10.0f, 0.0f);

	Frustum.reset(new Renderer::ViewFrustum);
	assert(Frustum);

	// Create a list of motions to be used as idle animations
	fs::directory_iterator EndIterator;
	fs::path MotionPath(L"./Data/Motions/Idle/");
	for (fs::directory_iterator Entry(MotionPath); Entry != EndIterator; Entry++) {
		if (fs::is_regular_file(Entry->status()) && Entry->path().extension().wstring().compare(L".vmd") == 0) {
			KnownMotions.emplace_back(Entry->path().generic_wstring());
		}
	}

	DirectX::XMMATRIX View, Projection;
	Camera->setFocalDistance(-35.0f);
	Camera->update(0.0f);
	Camera->getViewMatrix(View);
	Camera->getProjectionMatrix(Projection);

	Frustum->Construct(Renderer::SCREEN_DEPTH, Projection, View);

	Shader->SetEyePosition(Camera->GetPosition());
	Shader->SetMatrices(DirectX::XMMatrixIdentity(), View, Projection);

	// Initializes the model
	// Pause the physics environment, to prevent resource race
	Physics->pause();
	// Select a model to be displayed
#if 1
	auto ModelList = ModelHandler->getKnownModels();
	do {
		size_t Index = RandomGenerator() % ModelList.size();
		for (auto &ModelPath : ModelList) {
			if (Index-- == 0) {
				Model = ModelHandler->loadModel(ModelPath.first, Physics);
				ModelList.erase(ModelPath.first);
				break;
			}
		}
	} while (!Model);
#else
	Model = ModelHandler->loadModel(L"Tda式改変WIMミク ver.2.9", Physics);
	Model->SetDebugFlags(PMX::Model::DebugFlags::RenderBones);
#endif
	Model->SetShader(Shader);

	if (!Model->Initialize(Renderer, Physics))
		return false;
	Physics->resume();

	return true;
}
示例#11
0
/** \brief parse the str_orig strig to read and save
 * information about the curent state of the network
 * 	\param str_orig string to parse (char *)
 * 	\param node_orig node which sent str_orig
 */
void Router::parseVector(char* str_orig, char* node_orig)
{
	std::string sourceNode(node_orig);
	char *str = strcopy(str_orig + 1); // pour le [
	str[strlen(str) - 1] = 0; // pour le ]

	std::vector<char*> v;
	// 1 : on extrait chaque groupe d'infos (séparés par ;)
	char * r = strtok(str, ";");
	if(r != NULL)
		v.push_back(r);

	while((r = strtok(NULL, ";")) != NULL)
	{
		v.push_back(r);
	}

	// dans le tableau on a id,dist  dans chaque case.
	// dans la routetable, il faut :
	// si le noeud est présent, mettre à jour la distance si elle est plus courte
	// sinon l'ajouter et mettre en next hop sourceNode

	std::vector<char*>::iterator i;

	RouteTable::iterator i_rte;
	for(i_rte = routeTable.begin(); i_rte != routeTable.end(); ++i_rte)
	{

		if((*i_rte).second.name() != (*i_rte).second.nextHop()
			&& (*i_rte).second.nextHop() == sourceNode)
		{
			routeTable.erase(i_rte);
		}
	}

	// On ajoute ceux qui ne sont pas dans la table
	for(i = v.begin(); i != v.end(); ++i)
	{
		std::string s(strtok((*i), ","));
		if(s != std::string(getName()))
		{
			int dist = atoi(strtok(NULL, ","));

			if(routeTable.find(s) != routeTable.end()) // si on le trouve
			{
				if((routeTable[s].isNeighbor() && dist < routeTable[s].dist()) ||
                    (!routeTable[s].isNeighbor() && dist + routeTable[sourceNode].dist() < routeTable[s].dist()) ||
                    (!routeTable[s].isNeighbor() && routeTable[s].nextHop() == sourceNode &&
                                                    routeTable[s].dist() != dist + routeTable[sourceNode].dist()) ||
					(routeTable[s].dist() < 0))
				{

					routeTable[s].nextHop() = sourceNode;
					if(!routeTable[s].isNeighbor())
					{
						routeTable[s].dist() = dist + routeTable[sourceNode].dist();
					}
					else
					{
						routeTable[s].dist() = dist;
					}

				}
			}
			else
			{
				routeTable[s] = Entry(s, sourceNode, dist + routeTable[sourceNode].dist());
				// exception si sourceNode pas dans hashtable ? peu probable
			}
		}
	}
}
示例#12
0
Entry halfRed(unsigned char src,Entry dest) { 
  return Entry(dest.blue,src/2 > dest.red ? src/2 : dest.red); 
}
示例#13
0
Entry maxRed(unsigned char src,Entry dest) { 
    return Entry(dest.blue,src > dest.red ? src : dest.red); 
}
示例#14
0
Entry halfBlue(unsigned char src,Entry dest) { 
    return Entry(src/2 > dest.blue ? src/2 : dest.blue,dest.red); 
}
示例#15
0
void  CDataQueueNotBuffered<_Key, _Type>::Clear()
{
	CReentry  Entry(&m_Lock);
	m_Data.clear();
}
 //! Add entry
 void addParam(const Teuchos::RCP<FamilyType>& family,
               BaseValueType baseValue) { 
   params.push_back(Entry(family, baseValue));
 }
示例#17
0
void  CDataQueueBuffered<_Type>::Push(const _Type & Value)
{
	CReentry  Entry(&m_Lock);
	m_Data.push(Value);
	SetEvent(m_hNotification);
}
		InMemoryQueue(std::size_t max_size):max_messages_(1000), max_size_(max_size),current_size_(0),queue_(),subscriber_map_(),write_itr_(),queued_messages_(0) {
			queue_.resize(1000, Entry());
			write_itr_= queue_.begin();
		}