Пример #1
0
struct vector vector_add(struct vector a, struct vector b) {
	return vect(a.x + b.x, a.y + b.y, a.z + b.z);
}
Пример #2
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312"));
     QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
     QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
     QStringList list;
     list<<"one"<<"two"<<"three";
     qDebug()<<QObject::tr("qCopu() methord:");
     QVector<QString>vect(3);
     qCopy(list.begin(),list.end(),vect.begin());
     qDebug()<<vect;
     /****************************************************************************************************/
     qDebug()<<endl<<QObject::tr("qEqual() methord:");
     bool bl=qEqual(list.begin(),list.end(),vect.begin());
             qDebug()<<bl;
//             QList<QString>::iterator i;
//             i=qFind(list.begin,list.end(),"two");
 /****************************************************************************************************/
             qDebug()<<endl<<QObject::tr("qFind() methord:");
              QStringList::const_iterator i= qFind(list.begin(), list.end(), "two");
             qDebug()<<*i;
  /****************************************************************************************************/
      qDebug()<<endl<<QObject::tr("qFill() methord:");
      qFill(list.begin(),list.end(),"eleven");
      qDebug()<<list;
 /****************************************************************************************************/
      QList<int>list2;
      list2<<2<<31<<13<<2<<2<<2<<134<<2<<123<<4<<5<<3<<5<<51;
      qDebug()<<endl<<QObject::tr("qCount() methord:");
      int number=0;
      qCount(list2.begin(),list2.end(),2,number);
      qDebug()<<"The number of 2 is:"<<number;
      qSort(list2);
      QList<int>::iterator j=qLowerBound(list2.begin(),list2.end(),22);
     list2.insert(j,22);
     /****************************************************************************************************/
     qDebug()<<list2;
     qStableSort(list2);
qDebug()<<endl<<list2;
/****************************************************************************************************/
qSort(list2.begin(),list2.end(),qGreater<int>());
qDebug()<<endl<<list2;
/****************************************************************************************************/
qStableSort(list2.begin(),list2.end(),qGreater<int>());
qDebug()<<endl<<list2;
/****************************************************************************************************/
double d1=311.3998;
double d2=0.231314;
qDebug()<<endl<<"before swap:"<<d1<<" "<<d2;
qSwap(d1,d2);
qDebug()<<"then swap:"<<d1<<" "<<d2;
/****************************************************************************************************/
int int_a=qBound(2,49,12);
qDebug()<<"int_a="<<int_a;

    QDateTime time = QDateTime::currentDateTime();
    //QString s=time.toString("yyyy-MM-dd hh:mm:ss");
    qDebug()<<time.toString();
        return a.exec();

}
Пример #3
0
struct vector vector_div(struct vector a, float scale) {
	return vect(a.x / scale, a.y / scale, a.z / scale);
}
Пример #4
0
struct vector vector_cross(struct vector a, struct vector b) {
	return vect(a.y * b.z - a.z * b.y,
	            a.z * b.x - a.x * b.z,
	            a.x * b.y - a.y * b.x);
}
Пример #5
0
struct vector vector_sub(struct vector a, struct vector b) {
	return vect(a.x - b.x, a.y - b.y, a.z - b.z);
}
Пример #6
0
struct vector vector_mult(struct vector a, float scale) {
	return vect(a.x * scale, a.y * scale, a.z * scale);
}
Пример #7
0
void updateTurret(turret_struct* t)
{
	if(!t || !t->used)return;
	
	if(!t->OBB || !t->OBB->used){t->OBB=NULL;t->used=false;return;}
	
	t->counter+=2;t->counter%=63; //TEMP
	if(t->dead)t->counter=31;
	editPalette((u16*)t->OBB->modelInstance.palette,0,RGB15(abs(31-t->counter),0,0)); //TEMP
	
	int32* m=t->OBB->transformationMatrix;
	room_struct* r=getPlayer()->currentRoom;
	if(!r)return;

	int32 angle, d;
	bool b=pointInTurretSight(t, getPlayer()->object->position, &angle, &d);
	if(b)
	{
		vect3D u=vectDifference(getPlayer()->object->position,t->laserOrigin);
		int32 d=magnitude(u);
		u=divideVect(u,d);
		if(collideLineMap(&gameRoom, NULL, t->laserOrigin, u, d, NULL, NULL))b=false;
	}

	switch(t->state)
	{
		case TURRET_CLOSED:
			changeAnimation(&t->OBB->modelInstance, 0, false);
			t->drawShot[0]=t->drawShot[1]=0;

			if(b && !t->dead){t->state=TURRET_OPENING; playSFX(turretDeploySFX);}
			break;
		case TURRET_OPENING:
			if(t->OBB->modelInstance.currentAnim==2)
			{
				t->state=TURRET_OPEN;
			}else if(t->OBB->modelInstance.currentAnim!=1)
			{
				changeAnimation(&t->OBB->modelInstance, 2, false);
				changeAnimation(&t->OBB->modelInstance, 1, true);
			}
			t->drawShot[0]=t->drawShot[1]=0;
			break;
		case TURRET_OPEN:
			{
				if(angle>mulf32(sinLerp(TURRET_SIGHTANGLE/3),d))changeAnimation(&t->OBB->modelInstance, 4, false);
				else if(angle<-mulf32(sinLerp(TURRET_SIGHTANGLE/3),d))changeAnimation(&t->OBB->modelInstance, 5, false);
				else changeAnimation(&t->OBB->modelInstance, 2, false);

				int i;
				for(i=0;i<2;i++)
				{
					if(!t->drawShot[i] && !(rand()%3))
					{
						t->drawShot[i]=rand()%8;
						t->shotAngle[i]=rand();

						shootPlayer(NULL, normalize(vectDifference(t->laserDestination,t->laserOrigin)), 6);
						playSFX(turretFireSFX);
					}

					if(t->drawShot[i])t->drawShot[i]--;
				}

				if(!b || t->dead){t->state=TURRET_CLOSING; playSFX(turretRetractSFX);}
			}
			break;
		case TURRET_CLOSING:
			if(t->OBB->modelInstance.currentAnim==0)
			{
				t->state=TURRET_CLOSED;
			}else if(t->OBB->modelInstance.currentAnim!=3)
			{
				changeAnimation(&t->OBB->modelInstance, 0, false);
				changeAnimation(&t->OBB->modelInstance, 3, true);
			}
			t->drawShot[0]=t->drawShot[1]=0;
			break;
	}

	if(!t->dead)
	{
		t->laserOrigin=addVect(vectDivInt(t->OBB->position,4),evalVectMatrix33(m,laserOrigin));
		t->laserDestination=addVect(t->laserOrigin,vect(m[2],m[5],m[8]));

		if(b)t->laserDestination=getPlayer()->object->position;

		vect3D dir=normalize(vectDifference(t->laserDestination,t->laserOrigin));
		t->laserThroughPortal=false;

		laserProgression(r, &t->laserOrigin, &t->laserDestination, dir);
		
		int32 x, y, z;
		vect3D v;
		portal_struct* portal=NULL;
		if(isPointInPortal(&portal1, t->laserDestination, &v, &x, &y, &z))portal=&portal1;
		if(abs(z)>=32)portal=NULL;
		if(!portal)
		{
			if(isPointInPortal(&portal2, t->laserDestination, &v, &x, &y, &z))portal=&portal2;
			if(abs(z)>=32)portal=NULL;
		}
		if(portal)
		{
			t->laserDestination=addVect(t->laserDestination,vectMult(dir,TILESIZE));


			t->laserThroughPortal=true;
			dir=warpVector(portal,dir);
			t->laserOrigin2=addVect(portal->targetPortal->position, warpVector(portal, vectDifference(t->laserDestination, portal->position)));
			t->laserDestination2=addVect(t->laserOrigin2,dir);
			
			laserProgression(r, &t->laserOrigin2, &t->laserDestination2, dir);
			

			t->laserOrigin2=addVect(t->laserOrigin2,vectMult(dir,-TILESIZE));
		}

		if(m[4]<sinLerp(8192/2))t->dead=true;
	}
	
	updateAnimation(&t->OBB->modelInstance);
}
std::vector<int> Cross_variog_computer::compute_variogram_values(Discrete_function &f,
								GsTLVector<int> v,int num,
								float var,std::string& model_type,
								double mod_param)
{

    const RGrid *tempGrid=dynamic_cast<const RGrid*>(grid_);
    SGrid_cursor cursor=*(tempGrid->cursor());
    
    cursor.set_multigrid_level(1);
    std::vector<std::vector<std::pair<float,float> > >table;
    int i,j;

    for (i=0;i<num;i++)
    {
	std::vector<std::pair<float,float> > temp;
	table.push_back(temp);
	for(j=0;j<tempGrid->size();j++)
	{
	    int x,y,z;
	    cursor.coords(j,x,y,z);
	    GsTLGridNode point(x,y,z);	
	    GsTLVector<int> vect(v.x()*(i+1),v.y()*(i+1),v.z()*(i+1));
   GsTLGridNode candidate(point.x()+vect.x(),point.y()+vect.y(),point.z()+vect.z());

	    
	    int node_id=cursor.node_id((int)candidate.x(),(int)candidate.y(),
				   (int)candidate.z());
	   
	    if((node_id!=-1)&&(cursor.check_triplet((int)candidate.x(),(int)candidate.y(),
						    (int)candidate.z())))
	    {
		
		std::pair<float,float> temp;
		const Grid_continuous_property *prop1=tempGrid->selected_property();
                temp.first=prop1->get_value(j);
		const Grid_continuous_property *prop2=tempGrid->property(temp_prop_name);
		if (prop2->is_informed(node_id))
		{
		    temp.second=prop2->get_value(node_id);
		    table[i].push_back(temp);
		}
		
	
       	    }
	}
    }
 
    
    GsTLInt nx=tempGrid->nx();
    GsTLInt ny=tempGrid->ny();
    GsTLInt nz=tempGrid->nz();
    std::vector<double> x_values;
    std::vector<double> y_values;
    float temp;
    for(i=0;i<static_cast<signed>(table.size());i++)
    {
	temp=compute_single_value(table[i],model_type,mod_param);
	
	if((prim_var_*sec_var_)!=0)
	    y_values.push_back(temp/sqrt(prim_var_*sec_var_));
	else  y_values.push_back(temp);
	
        //y_values.push_back(temp/var);
	x_values.push_back( (i+1) * sqrt( double( v.x()*v.x() + v.y()*v.y() + v.z()*v.z() ) ) );
    }

    //Set y_values and x_values of discrete function object 
    f.set_y_values(y_values);
    f.set_x_values(x_values);

    std::vector<int> num_pairs;
    for(int j2=0;j2<static_cast<signed>(table.size());j2++)
    	num_pairs.push_back(table[j2].size());
    

    grid_->remove_property(temp_prop_name);
    return num_pairs;

}
Пример #9
0
SgExpression * LinearExpression::generate() const {
  std::vector<std::pair<RoseVariable, int> > vect(map.begin(), map.end());
  return vecToExp(vect);
}
Пример #10
0
Vector4 EditorSettings::ToVector4(const Color &color)
{
	Vector4 vect(color.r, color.g, color.b, color.a);
	return vect;
}
Пример #11
0
int main(void)
{
	boost::mpi::environment env;
	boost::mpi::communicator world;
	
	
	std::vector<double> vect(world.size());
	
	srand(world.rank()+100);
	
	for(size_t i=0;i<world.size();++i)
	{
		if(i==world.rank())
		{
			vect[i]=(double)rand()/(double)RAND_MAX;
			std::cout<<"processor "<<i<<" rand= "<<vect[i]<<std::endl;
		}
	}
	
	world.barrier();
	
	if(world.rank()==0)
	{
		std::cout<<"\nThe vector in processor 0 has the following elements"<<std::endl;
	}
	
	for(size_t i=0;i<world.size();++i)
	{
		if(world.rank()==0)
			std::cout<<i<<"\t"<<vect[i]<<std::endl;
	}
	
	if(world.rank()==0)
	{
		std::cout<<"\ndistributing the elements"<<std::endl;
	}
	
	//receive values from other processors
	std::vector<boost::mpi::request> reqs2(world.size()-1);
	size_t rind=0;
	for(size_t source=0;source<world.size();++source)
	{		
		if(source==world.rank())
		{
			//send my value to others
			std::vector<boost::mpi::request> reqs1(world.size()-1);
			
			size_t sind=0;
			for(size_t dest=0;dest<world.size();++dest)
			{
				if(dest != world.rank())
				{
					reqs1[sind] = world.isend(dest,source,vect[source]);
					++sind;
				}
			}
			
			boost::mpi::wait_all(reqs1.begin(), reqs1.end());
		}
		else
		{
			//double x=0;
			
			reqs2[rind] =  world.irecv(source, source, vect[source]);
			++rind;
		}
	}
	
	boost::mpi::wait_all(reqs2.begin(), reqs2.end());	
	
	if(world.rank()==0)
	{
		std::cout<<"\nafter distributing the elements the values are \n"<<std::endl;
	}
	
	if(world.rank()==0)
	{
		for(size_t i=0;i<world.size();++i)
		{
			std::cout<<i<<"\t"<<vect[i]<<std::endl;
		}
	}
	
	return 0;
}