示例#1
0
rc_t archIndexTestSerialization(ss_m*, test_volume_t*)
{
    // ============================== DIR 1 ==============================
    LogArchiver::ArchiveDirectory dir1(test_env->archive_dir, BLOCK_SIZE,
            true /* createIndex */);
    EXPECT_TRUE(dir1.getIndex());

    unsigned total = 0;
    generateFakeArchive(&dir1, BLOCK_SIZE*1000, 10, total);
    // ===================================================================


    // ============================== DIR 2 ==============================
    LogArchiver::ArchiveDirectory dir2(test_env->archive_dir, BLOCK_SIZE,
            true /* createIndex */);
    EXPECT_TRUE(dir2.getIndex());
    // ===================================================================

    LogArchiver::ArchiveIndex* index1 = dir1.getIndex();
    LogArchiver::ArchiveIndex* index2 = dir2.getIndex();
    EXPECT_EQ(index1->runs.size(), index2->runs.size());

    for(unsigned i=0; i<index1->runs.size(); i++) {
        EXPECT_EQ(index1->runs[i].entries.size(), index2->runs[i].entries.size());
        for(unsigned j=0; j<index1->runs[i].entries.size(); j++) {
            EXPECT_EQ(index1->runs[i].entries[j].offset, index2->runs[i].entries[j].offset);
            EXPECT_EQ(index1->runs[i].entries[j].pid, index2->runs[i].entries[j].pid);
        }
    }

    return RCOK;
}
示例#2
0
void Dialog::browse_objectsdir() {
  QString d = QFileDialog::getExistingDirectory (edobjectsdir->text(), this, 0,
						 "select objects dir");
  
  if (! d.isEmpty()) {
#ifdef WIN32
    QDir dir(d);
    
    if (! dir.exists()) {
      int index = d.length() - 1;
      
      if (d.at(index) == QChar('/'))
	index -= 1;
      
      QString d2 = d;
	
      d2.remove(index, 1);
	
      QDir dir2(d2);
	
      if (dir2.exists())
	d = d2;
    }
#endif
    
    edobjectsdir->setText(d);
  }
}
void postoperation::send()   //连接到服务器,执行发送
{
    ui->pbsendfile->setEnabled(false);
    bytesWritten = 0;
    //初始化已发送字节为0

    QDir dir;
    QString path = dir.currentPath();
    path += "/setting";
    QDir dir2(path);
    QString settingname;
    if(dir2.exists())
    {
        dir2.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
        dir2.setSorting(QDir::Size | QDir::Reversed);
        QFileInfoList list = dir2.entryInfoList();
        QFileInfo fileInfo = list.at(0);
        settingname = fileInfo.fileName();
        qDebug()<<settingname;
    }
    QString filename = path + "/" +settingname;
    QFile file(filename);
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QMessageBox::information(this,tr("提示"),tr("无法打开文件"),QMessageBox::Ok);
        qDebug()<<"Can't open the file!"<<endl;
    }
    QTextStream  in(&file);
    QString ipaddress;
    ipaddress = in.readLine();
    qDebug()<<ipaddress;
    tcpClient->connectToHost(QHostAddress(ipaddress),6111);//连接
}
void CGenericParticleProjectile::Draw()
{
	inArray = true;

	if (directional) {
		float3 dif(pos-camera->GetPos());
		dif.ANormalize();
		float3 dir1(dif.cross(speed));
		dir1.ANormalize();
		float3 dir2(dif.cross(dir1));

		unsigned char color[4];

		colorMap->GetColor(color, life);

		va->AddVertexTC(drawPos - dir1 * size - dir2 * size, texture->xstart, texture->ystart, color);
		va->AddVertexTC(drawPos - dir1 * size + dir2 * size, texture->xend,   texture->ystart, color);
		va->AddVertexTC(drawPos + dir1 * size + dir2 * size, texture->xend,   texture->yend,   color);
		va->AddVertexTC(drawPos + dir1 * size - dir2 * size, texture->xstart, texture->yend,   color);
	} else {
		unsigned char color[4];

		colorMap->GetColor(color, life);

		va->AddVertexTC(drawPos - camera->right * size - camera->up * size, texture->xstart, texture->ystart, color);
		va->AddVertexTC(drawPos + camera->right * size - camera->up * size, texture->xend,   texture->ystart, color);
		va->AddVertexTC(drawPos + camera->right * size + camera->up * size, texture->xend,   texture->yend,   color);
		va->AddVertexTC(drawPos - camera->right * size + camera->up * size, texture->xstart, texture->yend,   color);
	}
}
void CExploSpikeProjectile::Draw(void)
{
	inArray=true;

	float3 dif(pos-camera->pos2);
	dif.Normalize();
	float3 dir2(dif.cross(dir));
	dir2.Normalize();

	unsigned char col[4];
	float a=std::max(0.f,alpha-alphaDecay*gu->timeOffset)*255;
	col[0]=(unsigned char)(a*color.x);
	col[1]=(unsigned char)(a*color.y);
	col[2]=(unsigned char)(a*color.z);
	col[3]=1;

	float3 interpos=pos+speed*gu->timeOffset;
	float3 l=dir*length+lengthGrowth*gu->timeOffset;
	float3 w=dir2*width;

	va->AddVertexTC(interpos+l+w, ph->laserendtex.xend, ph->laserendtex.yend, col);
	va->AddVertexTC(interpos+l-w, ph->laserendtex.xend, ph->laserendtex.ystart, col);
	va->AddVertexTC(interpos-l-w, ph->laserendtex.xstart, ph->laserendtex.ystart, col);
	va->AddVertexTC(interpos-l+w, ph->laserendtex.xstart, ph->laserendtex.yend, col);
}
示例#6
0
文件: XMath.cpp 项目: 373137461/OBS
float GetPlaneCapsuleOffset(const Vect &dir, float capsuleHalfHeight, float capsuleRadius)
{
    Vect2 dir2(sqrtf(1.0f-(dir.y*dir.y)), fabs(dir.y));
    Vect2 centerOffset(capsuleRadius, capsuleHalfHeight);

    return centerOffset.Dot(dir2)-(1.0f-MAX(dir2.x, dir2.y));
}
void CExploSpikeProjectile::Draw(void)
{
	inArray=true;

	float3 dif(pos-camera->pos2);
	dif.Normalize();
	float3 dir2(dif.cross(dir));
	dir2.Normalize();

	unsigned char col[4];
	float a=std::max(0.f,alpha-alphaDecay*gu->timeOffset)*255;
	col[0]=(unsigned char)a;
	col[1]=(unsigned char)(a*0.8);
	col[2]=(unsigned char)(a*0.5);
	col[3]=1;

	float3 interpos=pos+speed*gu->timeOffset;
	float3 l=dir*length+lengthGrowth*gu->timeOffset;
	float3 w=dir2*width;

	va->AddVertexTC(interpos+l+w, 8/8.0, 1/8.0, col);
	va->AddVertexTC(interpos+l-w, 8/8.0, 0/8.0, col);
	va->AddVertexTC(interpos-l-w, 7/8.0, 0/8.0, col);
	va->AddVertexTC(interpos-l+w, 7/8.0, 1/8.0, col);
}
void CGeoSquareProjectile::Draw(void)
{
	inArray=true;
	unsigned char col[4];
	col[0]=(unsigned char) (r*a*255);
	col[1]=(unsigned char) (g*a*255);
	col[2]=(unsigned char) (b*a*255);
	col[3]=(unsigned char) (a*255);

	float3 dif(p1-camera->pos);
	dif.Normalize();
	float3 dir1(dif.cross(v1));
	dir1.Normalize();
	float3 dif2(p2-camera->pos);
	dif2.Normalize();
	float3 dir2(dif2.cross(v2));
	dir2.Normalize();

	if(w2!=0){
		va->AddVertexTC(p1-dir1*w1,1.0/16,1.0/8,col);
		va->AddVertexTC(p1+dir1*w1,1.0/16,0.0/8,col);
		va->AddVertexTC(p2+dir2*w2,1.0/16,0.0/8,col);
		va->AddVertexTC(p2-dir2*w2,1.0/16,1.0/8,col);
	} else {
		va->AddVertexTC(p1-dir1*w1,1.0/16,1.0/8,col);
		va->AddVertexTC(p1+dir1*w1,1.0/16,0.0/8,col);
		va->AddVertexTC(p2+dir2*w2,1.0/16,0.5/8,col);
		va->AddVertexTC(p2-dir2*w2,1.0/16,1.5/8,col);
	}
}
示例#9
0
void CGeoSquareProjectile::Draw()
{
	inArray = true;
	unsigned char col[4];
	col[0] = (unsigned char) (r * a * 255);
	col[1] = (unsigned char) (g * a * 255);
	col[2] = (unsigned char) (b * a * 255);
	col[3] = (unsigned char) (    a * 255);

	float3 dif(p1 - camera->GetPos());
	dif.ANormalize();
	float3 dir1(dif.cross(v1));
	dir1.ANormalize();
	float3 dif2(p2 - camera->GetPos());
	dif2.ANormalize();
	float3 dir2(dif2.cross(v2));
	dir2.ANormalize();


	const float u = (projectileDrawer->geosquaretex->xstart + projectileDrawer->geosquaretex->xend) / 2;
	const float v0 = projectileDrawer->geosquaretex->ystart;
	const float v1 = projectileDrawer->geosquaretex->yend;

	if (w2 != 0) {
		va->AddVertexTC(p1 - dir1 * w1, u, v1, col);
		va->AddVertexTC(p1 + dir1 * w1, u, v0, col);
		va->AddVertexTC(p2 + dir2 * w2, u, v0, col);
		va->AddVertexTC(p2 - dir2 * w2, u, v1, col);
	} else {
		va->AddVertexTC(p1 - dir1 * w1, u, v1,                    col);
		va->AddVertexTC(p1 + dir1 * w1, u, v0,                    col);
		va->AddVertexTC(p2,             u, v0 + (v1 - v0) * 0.5f, col);
		va->AddVertexTC(p2,             u, v0 + (v1 - v0) * 1.5f, col);
	}
}
TEST( ResourceDependenciesGraph, removingDir )
{
   ResourceDependenciesGraph graph;

   FilePath file( "/directory1/a.res" );
   FilePath res1( "/directory2/b.tmat" );
   FilePath res2( "/directory3/c.tmat" );
   FilePath dir1( "/directory1" );
   FilePath dir2( "/directory2" );
   FilePath dir3( "/directory3" );
   graph.addDependency( file, res1 );
   graph.addDependency( file, res2 );

   CPPUNIT_ASSERT_EQUAL( ( uint ) 2, graph.getAffectedResources( file ).size() );

   graph.onDirRemoved( dir2 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 1, graph.getAffectedResources( file ).size() );
   CPPUNIT_ASSERT_EQUAL( res2.getRelativePath(), graph.getAffectedResources( file ).front().getRelativePath() );

   graph.onDirRemoved( dir3 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 0, graph.getAffectedResources( file ).size() );

   graph.addDependency( file, res1 );
   graph.addDependency( file, res2 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 2, graph.getAffectedResources( file ).size() );

   graph.onDirRemoved( dir1 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 0, graph.getAffectedResources( file ).size() );
}
示例#11
0
int main()
{
	std::string dir_name = "/tmp/1/1/1";
	native_dir dir(dir_name);
	assert(!dir.exist());
	assert(!dir.create_dir(false));
	assert(dir.create_dir(true));

	printf("press a key to continue the test of delete function.\n");
	getchar();
	native_dir dir2("/tmp/1");
	assert(!dir2.delete_dir(false));
	assert(dir2.delete_dir(true));

	dir_name = "1/1/1";
	native_dir dir3(dir_name);
	assert(!dir3.exist());
	assert(!dir3.create_dir(false));
	assert(dir3.create_dir(true));

	printf("press a key to continue the test of delete function.\n");
	getchar();
	native_dir dir4("1");
	assert(!dir4.delete_dir(false));
	assert(dir4.delete_dir(true));
}
示例#12
0
void MainWindow::LoadContest(const QString& path)
{
    if (!QDir(path).exists())
    {
        QMessageBox::critical(this, "无法打开竞赛", QString("%1\n路径不存在或已被移除。").arg(path));
        QSettings set("ccr.ini", QSettings::IniFormat);
        QStringList list = set.value("RecentContestList").toStringList();
        list.removeAll(path);
        set.setValue("RecentContestList", list);
        UpdateRecentContest(true);
        return;
    }

    QDir dir1(path + "/src"), dir2(path + "/data");
    if (!dir1.exists() || !dir2.exists())
        if (QMessageBox::question(this, "找不到试题或选手目录", "是否继续打开并创建子目录?") == QMessageBox::No) return;

    if (!dir1.exists() && !QDir(path).mkdir("src"))
    {
        QMessageBox::critical(this, "无法创建子目录", "创建子目录失败!");
        return;
    }
    if (!dir2.exists() && !QDir(path).mkdir("data"))
    {
        QMessageBox::critical(this, "无法创建子目录", "创建子目录失败!");
        return;
    }

    if (!Global::g_is_contest_closed) CloseContest();
    lastContest = path;
    Global::g_contest.SetPath(path);

    QSettings set("ccr.ini", QSettings::IniFormat);
    QStringList list = set.value("RecentContestList").toStringList();
    if (!list.count(path)) list.prepend(path);
    set.setValue("RecentContestList", list);
    set.setValue("LastContest", lastContest);
    UpdateRecentContest(false);

    ui->label_top->hide();
    ui->label_bottom->hide();
    ui->listWidget_recent->hide();
    close_button->show();

    this->setWindowTitle(path + " - CCR Plus 测评器");
    ui->action_close->setEnabled(true);
    ui->action_configure->setEnabled(true);
    ui->action_set_list->setEnabled(true);
    ui->action_export->setEnabled(true);
    ui->action_refresh->setEnabled(true);
    ui->action_judge_selected->setEnabled(true);
    ui->action_judge_unjudged->setEnabled(true);
    ui->action_judge_all->setEnabled(true);
    ui->action_stop->setEnabled(false);

    Global::g_is_judge_stoped = false;
    Global::g_is_contest_closed = false;

    LoadTable();
}
示例#13
0
void KBookmarkManager::slotNotify( const char *_url )
{
  if ( !m_bNotify )
    return;
  
  KURL u( _url );
  if ( strcmp( u.protocol(), "file" ) != 0 )
    return;
  
  QString p = kapp->localkdedir().data();
  p += "/share/apps/kfm/bookmarks";
  QDir dir2( p );
  QDir dir1( u.path() );

  QString p1( dir1.canonicalPath() );
  QString p2( dir2.canonicalPath() );
  if ( p1.isEmpty() )
    p1 = u.path();
  if ( p2.isEmpty() )
    p2 = p.data();
  
  if ( strncmp( p1.data(), p2.data(), p2.length() ) == 0 )
  {
    QString d = kapp->localkdedir().data();
    d += "/share/apps/kfm/bookmarks/";
    scan( d );
  }
}
示例#14
0
文件: XMath.cpp 项目: 373137461/OBS
float GetPlaneCylinderOffset(const Vect &dir, float cylHalfHeight, float cylRadius)
{
    Vect2 dir2(sqrtf(1.0f-(dir.y*dir.y)), fabs(dir.y));
    Vect2 centerOffset(cylRadius, cylHalfHeight);

    return centerOffset.Dot(dir2);
}
示例#15
0
void InMapDraw_QuadDrawer::DrawQuad(int x, int y)
{
	int drawQuadsX = imd->drawQuadsX;
	CInMapDraw::DrawQuad* dq = &imd->drawQuads[y * drawQuadsX + x];

	va->EnlargeArrays(dq->points.size()*12,0,VA_SIZE_TC);
	//! draw point markers
	for (std::list<CInMapDraw::MapPoint>::iterator pi = dq->points.begin(); pi != dq->points.end(); ++pi) {
		if (pi->MaySee(imd)) {
			float3 pos = pi->pos;
			float3 dif(pos - camera->pos);
			dif.ANormalize();
			float3 dir1(dif.cross(UpVector));
			dir1.ANormalize();
			float3 dir2(dif.cross(dir1));

			unsigned char col[4];
			col[0] = pi->color[0];
			col[1] = pi->color[1];
			col[2] = pi->color[2];
			col[3] = 200;

			float size = 6;
			float3 pos1 = pos;
			pos1.y += 5.0f;
			float3 pos2 = pos1;
			pos2.y += 100.0f;

			va->AddVertexQTC(pos1 - dir1 * size,               0.25f, 0, col);
			va->AddVertexQTC(pos1 + dir1 * size,               0.25f, 1, col);
			va->AddVertexQTC(pos1 + dir1 * size + dir2 * size, 0.00f, 1, col);
			va->AddVertexQTC(pos1 - dir1 * size + dir2 * size, 0.00f, 0, col);

			va->AddVertexQTC(pos1 - dir1 * size,               0.75f, 0, col);
			va->AddVertexQTC(pos1 + dir1 * size,               0.75f, 1, col);
			va->AddVertexQTC(pos2 + dir1 * size,               0.75f, 1, col);
			va->AddVertexQTC(pos2 - dir1 * size,               0.75f, 0, col);

			va->AddVertexQTC(pos2 - dir1 * size,               0.25f, 0, col);
			va->AddVertexQTC(pos2 + dir1 * size,               0.25f, 1, col);
			va->AddVertexQTC(pos2 + dir1 * size - dir2 * size, 0.00f, 1, col);
			va->AddVertexQTC(pos2 - dir1 * size - dir2 * size, 0.00f, 0, col);

			if (pi->label.size() > 0) {
				font->SetTextColor(pi->color[0]/255.0f, pi->color[1]/255.0f, pi->color[2]/255.0f, 1.0f); //FIXME (overload!)
				font->glWorldPrint(pos2 + UpVector * 6, 26.0f, pi->label);
			}
		}
	}

	lineva->EnlargeArrays(dq->lines.size()*2,0,VA_SIZE_C);
	//! draw line markers
	for (std::list<CInMapDraw::MapLine>::iterator li = dq->lines.begin(); li != dq->lines.end(); ++li) {
		if (li->MaySee(imd)) {
			lineva->AddVertexQC(li->pos - (li->pos - camera->pos).ANormalize() * 26, li->color);
			lineva->AddVertexQC(li->pos2 - (li->pos2 - camera->pos).ANormalize() * 26, li->color);
		}
	}
}
示例#16
0
void Cinema::load(){
        ofDirectory dir("cinema/");
        dir.listDir();
        vector<string> dirs;
        for(int i=0;i<dir.size();i++){
            string d = dir.getPath(i);
            if(d.find("DB")!=string::npos){
                vector<string> vids;
                vector<ofVideoPlayer*> ps;
                ofDirectory dir2(d);
                dir2.listDir();
                for(int j=0;j<dir2.size();j++){
                    vector<double> scene;
                    vector<string> movs;
                    string vidpath = dir2.getPath(j);
                    string origVidPath = vidpath;
                    if(dir2.getName(j)[0] != '.' &&
                            (vidpath.find(".mov")!=string::npos || vidpath.find(".mp4")!=string::npos ||
                       vidpath.find(".avi")!=string::npos ||
                       vidpath.find(".3gp")!=string::npos
                       || vidpath.find(".gif")!=string::npos
                       || vidpath.find(".webm")!=string::npos
                       || vidpath.find(".mkv")!=string::npos)){
                        vids.push_back(vidpath);
                        playerPaths.push_back(vidpath);
                        ofVideoPlayer* p = new ofVideoPlayer;
                        playerIntensities.push_back(0);
                        ps.push_back(p);
                        
                        string txtPath = vidpath;
                        ofStringReplace(txtPath, ".mov", ".txt");
                        ofStringReplace(txtPath, ".mp4", ".txt");
                        ofStringReplace(txtPath, ".mkv", ".txt");
                        ofStringReplace(txtPath, ".webm", ".txt");
                        ofStringReplace(txtPath, ".avi", ".txt");
                        ofStringReplace(txtPath, ".gif", ".txt");
                        string t = ofBufferFromFile(txtPath).getText();
                        if(t.compare("")){
                            vector<string > splitted = ofSplitString(t, "\n");
                            for(int x=0;x<splitted.size();x++){
                                vector<string> line = ofSplitString(splitted[x]," ");
                                scene.push_back(ofToDouble(line[0]));
                                if(line.size()>1)
                                    movs.push_back((line[1]));
                                else
                                    movs.push_back(" ");
                            }
                            ofFile vf(vidpath) ;
                            string absoluteVidPath = vf.getAbsolutePath();
                            playerScenes[absoluteVidPath] = scene;
                            playerScenesMovements[origVidPath] = movs;
                        }
                    }
                   
                }
                strdb.push_back(vids);
            }
        }
    }
示例#17
0
void InMapDraw_QuadDrawer::DrawQuad (int x,int y)
{
	int drawQuadsX = imd->drawQuadsX;
	CInMapDraw::DrawQuad* dq=&imd->drawQuads[y*drawQuadsX+x];

	for(std::list<CInMapDraw::MapPoint>::iterator pi=dq->points.begin();pi!=dq->points.end();++pi){
		float3 pos=pi->pos;

		float3 dif(pos-camera->pos);
		float camDist=dif.Length();
		dif/=camDist;
		float3 dir1(dif.cross(UpVector));
		dir1.Normalize();
		float3 dir2(dif.cross(dir1));

		unsigned char col[4];
		col[0]=pi->color[0];
		col[1]=pi->color[1];
		col[2]=pi->color[2];
		col[3]=200;//intensity*255;

		float size=6;

		float3 pos1=pos;
		float3 pos2=pos1;
		pos2.y+=100;

		va->AddVertexTC(pos1-dir1*size,					  0.25f,0,col);
		va->AddVertexTC(pos1+dir1*size,					  0.25f,1,col);
		va->AddVertexTC(pos1+dir1*size+dir2*size, 0.00f,1,col);
		va->AddVertexTC(pos1-dir1*size+dir2*size, 0.00f,0,col);

		va->AddVertexTC(pos1-dir1*size,0.75f,0,col);
		va->AddVertexTC(pos1+dir1*size,0.75f,1,col);
		va->AddVertexTC(pos2+dir1*size,0.75f,1,col);
		va->AddVertexTC(pos2-dir1*size,0.75f,0,col);

		va->AddVertexTC(pos2-dir1*size,					  0.25f,0,col);
		va->AddVertexTC(pos2+dir1*size,					  0.25f,1,col);
		va->AddVertexTC(pos2+dir1*size-dir2*size, 0.00f,1,col);
		va->AddVertexTC(pos2-dir1*size-dir2*size, 0.00f,0,col);

		if(pi->label.size()>0){
			glPushMatrix();
			glTranslatef3(pi->pos+UpVector*105);
			glScalef(30,30,30);
			glColor4ub(pi->color[0],pi->color[1],pi->color[2],250);
			font->glWorldPrint("%s",pi->label.c_str());
			glPopMatrix();
			glBindTexture(GL_TEXTURE_2D, texture);
		}
	}
	for(std::list<CInMapDraw::MapLine>::iterator li=dq->lines.begin();li!=dq->lines.end();++li){
		lineva->AddVertexC(li->pos-(li->pos - camera->pos).Normalize()*26,li->color);
		lineva->AddVertexC(li->pos2-(li->pos2 - camera->pos).Normalize()*26,li->color);
	}
}
示例#18
0
double Getrotation(Transform& Input)
{
	Vector3d pos;
	pos = Input.RefPos();
    Vector3d dir;
    dir = Input.Matrix() * Vector3d(0, 0, -1);
    Vector3d dir2;
    dir2 = Input.Matrix() * Vector3d(1, 0, 0);
    double r = sqrt(pow(dir(0), 2) + pow(dir(2), 2));
    if (abs(r)>1){ r = 1.0f; }
    double latitude = acos_s(r) * 180.0f / PI;
    double longitude = acos_s(dir(2) / r) * 180.0f / PI;
    if (dir(0) < 0){ longitude = -longitude; }
    double intersect[3] = {-dir(2) / r, 0, dir(0) / r};
    double rotation = acos_s(dir2(0) * intersect[0] + dir2(1) * intersect[1] + dir2(2) * intersect[2]) * 180.0f / PI;
    if (dir2(1) < 0){ rotation = -rotation; }
	return rotation;
}
示例#19
0
	//     ----|------>|---
	//	   1   4   3   5 2    0
	int Geometry::Line::position(const Point &P){
		if (dir == Point(0, 0)) return 0;
		Point dir2(P - A);
		if (dir2 == Point(0, 0)) return 4;
		if (dcmp(det(dir, dir2)) != 0) return 0;
		if (dcmp(dot(dir, dir2))<0) return 1;
		if (dcmp(dir2.len(), dir.len())<0) return 3;
		if (dcmp(dir2.len(), dir.len())>0) return 2;
		return 5;
	}
示例#20
0
sun_lightmap::rays sun_lightmap::generate(float raylen, size_t count) const
{
    rays result;

    switch (count) {
    case 0:
        add(result, raylen, direction_);
    // Fallthrough

    case 1:
        for (int i(0); i < 6; ++i) {
            double a(((2. * 3.1415827) / 6.) * i);
            vector2<float> r(sin(a), cos(a));
            vector2<float> dir2(direction_ + r * radius_);
            add(result, raylen, dir2);
        }
    // Fallthrough

    case 2:
        for (int i(0); i < 6; ++i) {
            double a(((2. * 3.1415827) / 6.) * float(i + .5));
            vector2<float> r(sin(a), cos(a));
            vector2<float> dir2(direction_ + r * radius_ * 0.5);
            add(result, raylen, dir2);
        }
        break;

    default:
        assert(false);
    }

    // Normalize all rays so the highest intensity is 1.0
    float max(0);
    for (auto& r : result) {
        if (r.weight > max)
            max = r.weight;
    }

    for (auto& r : result)
        r.multiply_weight(1.0f / max);

    return result;
}
示例#21
0
文件: XMath.cpp 项目: 373137461/OBS
float GetPlaneConeOffset(const Vect &dir, float coneHeight, float coneRadius)
{
    Vect2 dir2(sqrtf(1.0f-(dir.y*dir.y)), dir.y);
    Vect2 p1(coneRadius, coneHeight), p2(coneRadius, 0.0f);

    float dist1 = dir2.Dot(p1);
    float dist2 = dir2.Dot(p2);

    return MAX(dist1, dist2);
}
示例#22
0
QString Database::commonPath(QString path1, QString path2)
{
	if(!path1.size() || !path2.size()) return "";
	QDir dir1(path1), dir2(path2);
	if(dir1.isRoot() || dir2.isRoot()) return "";
	path1 = dir1.canonicalPath();
	while(!dir2.isRoot()) {
		if(path1.startsWith(dir2.canonicalPath())) return dir2.canonicalPath();
		dir2.cdUp();
	}
	return "";
}
示例#23
0
/**
 * Initialize by three points
 *
 * This points are used:
 *
 *	  normal
 * 		|    p3
 *      |   /
 * 		|  /
 * 		| /
 * 		p1---------------p2
 *
 * 		d1 = p2 - p1
 * 		d2 = p3 - p1
 * 		n = d1 x d2
 */
void srs::CTestingPlane::set(const tPoint & p1, const tPoint & p2, const tPoint & p3)
{
    // Compute directional vectors
    tPoint dir1( p2 - p1 ), dir2( p3 - p1 );

    // Get normal vector from cross-product
    m_plane = dir1;
    m_plane.cross(dir2);
    m_plane.normalize();

    // Compute last parameter
    m_d = - p1.dot( m_plane );
}
示例#24
0
QZip::QZip(const QString &zipFileName,const QString &zipPathName)
{
    _zipFileName = zipFileName;
    _zipPathName = zipPathName;

    QDir dir1(".");
    dir1.setCurrent(".");
    _zipFileName = dir1.absoluteFilePath(_zipFileName);

    QDir dir2(_zipPathName);
    if(!dir2.isAbsolute()){
        _zipPathName = dir2.absolutePath();
    }
}
void CBeamLaserProjectile::Draw(void)
{
	inArray=true;
	float3 dif(pos-camera->pos);
	float camDist=dif.Length();
	dif/=camDist;
	float3 dir=endPos-startPos;
	dir.Normalize();
	float3 dir1(dif.cross(dir));
	dir1.Normalize();
	float3 dir2(dif.cross(dir1));

	unsigned char col[4];
	col[0]=(unsigned char)(color.x*startAlpha);
	col[1]=(unsigned char)(color.y*startAlpha);
	col[2]=(unsigned char)(color.z*startAlpha);
	col[3]=1;//intensity*255;

	unsigned char col2[4];
	col2[0]=(unsigned char)(color.x*endAlpha);
	col2[1]=(unsigned char)(color.y*endAlpha);
	col2[2]=(unsigned char)(color.z*endAlpha);
	col2[3]=1;//intensity*255;

	float size=thickness;
	float3 pos1=startPos;
	float3 pos2=endPos;

	if(camDist<1000){
		va->AddVertexTC(pos1-dir1*size,					  15.0/16,0,    col);
		va->AddVertexTC(pos1+dir1*size,					  15.0/16,1.0/8,col);
		va->AddVertexTC(pos1+dir1*size-dir2*size, 14.0/16,1.0/8,col);
		va->AddVertexTC(pos1-dir1*size-dir2*size, 14.0/16,0		,col);

		va->AddVertexTC(pos1-dir1*size,11.0/16,0,    col);
		va->AddVertexTC(pos1+dir1*size,11.0/16,1.0/8,col);
		va->AddVertexTC(pos2+dir1*size,11.0/16,1.0/8,col2);
		va->AddVertexTC(pos2-dir1*size,11.0/16,0    ,col2);

		va->AddVertexTC(pos2-dir1*size,					  15.0/16,0,    col2);
		va->AddVertexTC(pos2+dir1*size,					  15.0/16,1.0/8,col2);
		va->AddVertexTC(pos2+dir1*size+dir2*size, 14.0/16,1.0/8,col2);
		va->AddVertexTC(pos2-dir1*size+dir2*size, 14.0/16,0		,col2);
	} else {
		va->AddVertexTC(pos1-dir1*size,11.0/16,0,    col);
		va->AddVertexTC(pos1+dir1*size,11.0/16,1.0/8,col);
		va->AddVertexTC(pos2+dir1*size,11.0/16,1.0/8,col2);
		va->AddVertexTC(pos2-dir1*size,11.0/16,0    ,col2);
	}
}
示例#26
0
void CSimpleParticleSystem::Draw()
{
	inArray=true;

	va->EnlargeArrays(numParticles*4,0,VA_SIZE_TC);
	if(directional)
	{
		for(int i=0; i<numParticles; i++)
		{
			if(particles[i].life<1.0f)
			{
				float3 dif(particles[i].pos-camera->pos);
				dif.ANormalize();
				float3 dir1(dif.cross(particles[i].speed));
				dir1.ANormalize();
				float3 dir2(dif.cross(dir1));

				unsigned char color[4];

				colorMap->GetColor(color, particles[i].life);
				float3 interPos=particles[i].pos+particles[i].speed*gu->timeOffset;
				float size = particles[i].size;
				va->AddVertexQTC(interPos-dir1*size-dir2*size,texture->xstart,texture->ystart,color);
				va->AddVertexQTC(interPos-dir1*size+dir2*size,texture->xend ,texture->ystart,color);
				va->AddVertexQTC(interPos+dir1*size+dir2*size,texture->xend ,texture->yend ,color);
				va->AddVertexQTC(interPos+dir1*size-dir2*size,texture->xstart,texture->yend ,color);
			}
		}
	}
	else
	{
		unsigned char color[4];
		for(int i=0; i<numParticles; i++)
		{
			Particle* p = &particles[i];
			if(p->life<1.0f)
			{
				colorMap->GetColor(color, p->life);
				float3 interPos=p->pos+p->speed*gu->timeOffset;
				const float3 cameraRight = camera->right*p->size;
				const float3 cameraUp    = camera->up*p->size;

				va->AddVertexQTC(interPos-cameraRight-cameraUp,texture->xstart,texture->ystart,color);
				va->AddVertexQTC(interPos+cameraRight-cameraUp,texture->xend ,texture->ystart,color);
				va->AddVertexQTC(interPos+cameraRight+cameraUp,texture->xend ,texture->yend ,color);
				va->AddVertexQTC(interPos-cameraRight+cameraUp,texture->xstart,texture->yend ,color);
			}
		}
	}
}
void CLaserProjectile::Draw(void)
{
	if(s3domodel)	//dont draw if a 3d model has been defined for us
		return;

	inArray=true;
	float3 dif(pos-camera->pos);
	float camDist=dif.Length();
	dif/=camDist;
	float3 dir1(dif.cross(dir));
	dir1.Normalize();
	float3 dir2(dif.cross(dir1));

	unsigned char col[4];
	col[0]=(unsigned char) (color.x*intensity*255);
	col[1]=(unsigned char) (color.y*intensity*255);
	col[2]=(unsigned char) (color.z*intensity*255);
	col[3]=1;//intensity*255;

	float size=weaponDef->thickness;

	if(camDist<1000){
		float3 pos1=pos+speed*gu->timeOffset;
		float3 pos2=pos1-dir*curLength;

		va->AddVertexTC(pos1-dir1*size,					  15.0/16,0,    col);
		va->AddVertexTC(pos1+dir1*size,					  15.0/16,1.0/8,col);
		va->AddVertexTC(pos1+dir1*size-dir2*size, 14.0/16,1.0/8,col);
		va->AddVertexTC(pos1-dir1*size-dir2*size, 14.0/16,0		,col);

		va->AddVertexTC(pos1-dir1*size,11.0/16,0,    col);
		va->AddVertexTC(pos1+dir1*size,11.0/16,1.0/8,col);
		va->AddVertexTC(pos2+dir1*size,11.0/16,1.0/8,col);
		va->AddVertexTC(pos2-dir1*size,11.0/16,0    ,col);

		va->AddVertexTC(pos2-dir1*size,					  15.0/16,0,    col);
		va->AddVertexTC(pos2+dir1*size,					  15.0/16,1.0/8,col);
		va->AddVertexTC(pos2+dir1*size+dir2*size, 14.0/16,1.0/8,col);
		va->AddVertexTC(pos2-dir1*size+dir2*size, 14.0/16,0		,col);
	} else {
		float3 pos1=pos+speed*gu->timeOffset+dir*(size*0.5);
		float3 pos2=pos1-dir*(curLength+size);

		va->AddVertexTC(pos1-dir1*size,11.0/16,0,    col);
		va->AddVertexTC(pos1+dir1*size,11.0/16,1.0/8,col);
		va->AddVertexTC(pos2+dir1*size,11.0/16,1.0/8,col);
		va->AddVertexTC(pos2-dir1*size,11.0/16,0    ,col);
	}
}
void CSimpleParticleSystem::Draw()
{
	inArray=true;

	if(directional)
	{
		for(int i=0; i<numParticles; i++)
		{
			if(particles[i].life<1.0f)
			{
				float3 dif(particles[i].pos-camera->pos);
				float camDist=dif.Length();
				dif/=camDist;
				float3 dir1(dif.cross(particles[i].speed));
				dir1.Normalize();
				float3 dir2(dif.cross(dir1));

				unsigned char color[4];

				colorMap->GetColor(color, particles[i].life);
				float3 interPos=particles[i].pos+particles[i].speed*gu->timeOffset;
				float size = particles[i].size;
				va->AddVertexTC(interPos-dir1*size-dir2*size,texture->xstart,texture->ystart,color);
				va->AddVertexTC(interPos-dir1*size+dir2*size,texture->xend ,texture->ystart,color);
				va->AddVertexTC(interPos+dir1*size+dir2*size,texture->xend ,texture->yend ,color);
				va->AddVertexTC(interPos+dir1*size-dir2*size,texture->xstart,texture->yend ,color);
			}
		}
	}
	else
	{
		for(int i=0; i<numParticles; i++)
		{
			if(particles[i].life<1.0f)
			{
				unsigned char color[4];

				colorMap->GetColor(color, particles[i].life);
				float3 interPos=particles[i].pos+particles[i].speed*gu->timeOffset;
				float size = particles[i].size;

				va->AddVertexTC(interPos-camera->right*size-camera->up*size,texture->xstart,texture->ystart,color);
				va->AddVertexTC(interPos+camera->right*size-camera->up*size,texture->xend ,texture->ystart,color);
				va->AddVertexTC(interPos+camera->right*size+camera->up*size,texture->xend ,texture->yend ,color);
				va->AddVertexTC(interPos-camera->right*size+camera->up*size,texture->xstart,texture->yend ,color);
			}
		}
	}
}
示例#29
0
void TestFixture::testDir()
{
  wxExDir dir("./", "*.h", wxDIR_FILES);
  CPPUNIT_ASSERT(dir.IsOpened());
  CPPUNIT_ASSERT(dir.GetFileSpec() == "*.h");
  CPPUNIT_ASSERT(dir.FindFiles() == 1);
  
  // we could use *.h;*.cpp, however wxDir handles only
  // one type, so all files would be found (wxExDir uses empty spec,
  // and checks each file on a match)
  wxExDir dir2("../", "*.h", wxDIR_FILES | wxDIR_DIRS);
  CPPUNIT_ASSERT(dir2.IsOpened());
  CPPUNIT_ASSERT(dir2.GetFileSpec() == "*.h");
  CPPUNIT_ASSERT(dir2.FindFiles() > 50);
}
bool IfcGeom::is_convex(const TopoDS_Wire& wire) {
	for ( TopExp_Explorer exp1(wire,TopAbs_VERTEX); exp1.More(); exp1.Next() ) {
		TopoDS_Vertex V1 = TopoDS::Vertex(exp1.Current());
		gp_Pnt P1 = BRep_Tool::Pnt(V1);
		// Store the neighboring points
		std::vector<gp_Pnt> neighbors;
		for ( TopExp_Explorer exp3(wire,TopAbs_EDGE); exp3.More(); exp3.Next() ) {
			TopoDS_Edge edge = TopoDS::Edge(exp3.Current());
			std::vector<gp_Pnt> edge_points;
			for ( TopExp_Explorer exp2(edge,TopAbs_VERTEX); exp2.More(); exp2.Next() ) {
				TopoDS_Vertex V2 = TopoDS::Vertex(exp2.Current());
				gp_Pnt P2 = BRep_Tool::Pnt(V2);
				edge_points.push_back(P2);
			}
			if ( edge_points.size() != 2 ) continue;
			if ( edge_points[0].IsEqual(P1,GetValue(GV_POINT_EQUALITY_TOLERANCE))) neighbors.push_back(edge_points[1]);
			else if ( edge_points[1].IsEqual(P1, GetValue(GV_POINT_EQUALITY_TOLERANCE))) neighbors.push_back(edge_points[0]);
		}
		// There should be two of these
		if ( neighbors.size() != 2 ) return false;
		// Now find the non neighboring points
		std::vector<gp_Pnt> non_neighbors;
		for ( TopExp_Explorer exp2(wire,TopAbs_VERTEX); exp2.More(); exp2.Next() ) {
			TopoDS_Vertex V2 = TopoDS::Vertex(exp2.Current());
			gp_Pnt P2 = BRep_Tool::Pnt(V2);
			if ( P1.IsEqual(P2,GetValue(GV_POINT_EQUALITY_TOLERANCE)) ) continue;
			bool found = false;
			for( std::vector<gp_Pnt>::const_iterator it = neighbors.begin(); it != neighbors.end(); ++ it ) {
				if ( (*it).IsEqual(P2,GetValue(GV_POINT_EQUALITY_TOLERANCE)) ) { found = true; break; }
			}
			if ( ! found ) non_neighbors.push_back(P2);
		}
		// Calculate the angle between the two edges of the vertex
		gp_Dir dir1(neighbors[0].XYZ() - P1.XYZ());
		gp_Dir dir2(neighbors[1].XYZ() - P1.XYZ());
		const double angle = acos(dir1.Dot(dir2)) + 0.0001;
		// Now for the non-neighbors see whether a greater angle can be found with one of the edges
		for ( std::vector<gp_Pnt>::const_iterator it = non_neighbors.begin(); it != non_neighbors.end(); ++ it ) {
			gp_Dir dir3((*it).XYZ() - P1.XYZ());
			const double angle2 = acos(dir3.Dot(dir1));
			const double angle3 = acos(dir3.Dot(dir2));
			if ( angle2 > angle || angle3 > angle ) return false;
		}
	}
	return true;
}