예제 #1
0
void nGame::RenderExplosion(const Explosion& explosion)
{
	nGetInstance()->GetGraphics()->SetLineWidth(2);

	// Draw explosion shock-waves
	nGetInstance()->GetGraphics()->DrawCircle(nPoint(explosion.position.x,explosion.position.y),explosion.size,30,nColor(1.0f - explosion.size / explosion.power,explosion.color));
	nGetInstance()->GetGraphics()->DrawCircle(nPoint(explosion.position.x,explosion.position.y),explosion.size * explosion.size / explosion.power,30,nColor(1.0f - explosion.size * explosion.size / explosion.power / explosion.power,explosion.color));
}
예제 #2
0
void nGame::RenderMissle(const Missle& missle)
{
	nGetInstance()->GetGraphics()->SetLineWidth(3);

	// Fade the missle if it's dying
	float alpha = 1.0f;

	if(missle.dead > 0.0f)
		alpha = (10.0f - missle.dead) / 10.0f;

	nVector2 line[2];

	// Draw missle trail
	if(missle.trail)
	{
		line[0] = missle.source;
		line[1] = missle.position;
		nGetInstance()->GetGraphics()->DrawLines(line,2,nColor(alpha,missle.color));
	}

	// Don't draw missle head if it exploded
	if(missle.dead == 0.0f)
	{
		// Get missle direction vector for head drawing
		nVector2 dir = missle.destination - missle.source;
		dir.Normalize();

		// Draw missle head
		line[0] = missle.position;
		line[1] = missle.position + dir * 5.0f;

		nGetInstance()->GetGraphics()->DrawLines(line,2,nColor(alpha,0.1f,1.0f,0.1f));
	}

	// Draw missle destination target
	if(missle.frendly && missle.dead == 0.0f)
	{
		if(missle.trail)
			nGetInstance()->GetGraphics()->DrawTarget(nPoint(missle.destination.x,missle.destination.y),missle.target,nColor(1.0f - missle.target,GAME_FRENDLY_COLOR));
		else
			nGetInstance()->GetGraphics()->DrawTarget(nPoint(missle.destination.x,missle.destination.y),0.0f,GAME_FRENDLY_COLOR);
	}
}
예제 #3
0
//*******************************************************//
int main(int argc, char* argv[]){

	int max_time; 
	string Tfile, Dfile;
	std::cout<<"start dynamic-c"<<std::endl;
	//std::cout<<"start dynamic-c process, number of argv:"<<argc<<std::endl;
	if(argc != 3){
		std::cout<<"Usage:"<<"\n \t"<<argv[0]<<" Tstable-file"<<" Dstable-file"<<" max_time"<<std::endl;
		std::cout<<"where	Tstable-file and Dstable-file are stable time and stable distance profiles of the car on corresponding road segment"<<std::endl;
		std::cout<<"\tmax_time: this set the limit of arrival time"<<std::endl;
		std::cout<<"	E.g:"<<argv[0]<<" T.csv D.csv 4000"<<std::endl;
		std::cout<<"-------end--------"<<std::endl;
		std::cout<<"Type Y/N to run the default:"<<argv[0]<<" ../../profiles/90STNORMED.csv ../../profiles/90SDNORMED.csv 500:"<<std::endl;
	/* 	std::string c;
		std::cin >>c;
		std::cout<<"You have typed: "<<c;
		if(c == "y" || c == "Y"){
			std::cout<<" .Continue Running...";
			Tfile = "../../profiles/90STNORMED.csv";
			Dfile = "../../profiles/90SDNORMED.csv";
			max_time = 500; 
			std::cout<<" with: Tfile= " << Tfile <<" Dfile = "<< Dfile <<" and max_time = "<<max_time<<std::endl;
		}
		else{
			std::cout<<" .Stop Running!"<<std::endl;
			return 0; 
		}   */
 		std::cout<<" .Continue Running...";
		Tfile = "../../profiles/90STNORMED.csv";
		Dfile = "../../profiles/90SDNORMED.csv";
		max_time = 500; 
		std::cout<<" with: Tfile= " << Tfile <<" Dfile = "<< Dfile <<" and max_time = "<<max_time; 
	}
	else {
		Tfile = argv[1];
		Dfile = argv[2];
		max_time = atoi(argv[3]);
	}

	int N = max_time/2 + 1;
		
	/* open log file to write down running time */
	std::string log_file_name = string("running_time.csv");
	std::ofstream logFile(log_file_name.c_str() );
	std::vector<std::vector<int> > T, D; 
	Timer timer;
	timer.start();
	T = readFile(Tfile, NUM_DISCRETE_VEL);
	D = readFile(Dfile, NUM_DISCRETE_VEL);
	// T = readFile("/bigdrive/pygame/src/carSimulation3/profiles/T.csv", M);
	// D = readFile("/bigdrive/pygame/src/carSimulation3/profiles/D.csv", M);
	// T = readFile("./profiles/90STNORMED.csv", M);
	// D = readFile("./profiles/90SDNORMED.csv", M);
 	/* std::cout<<"T table:"<<std::endl;
	for(int i=0; i<11; i++){
		for(int j = 0; j<11; j++)
			std::cout<<T[i][j]<<"\t";
		std::cout<<"\n";
	}  */


	std::cout<<"Now, begin dynamic programming."<<std::endl;
	std::vector<std::vector<fSet> > G(M, std::vector<fSet>(N));
	
	/* initialize a table's elements that have distance value equal 0 */
	for(int i=0;i<M;i++){

		classPoint2T nPoint(0,i);
		fSet x;
		x.push_back(nPoint);
		G[i][0] = x;
	}

	// print the original
/* 	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			std::cout<<"i,j:"<<i<<" "<<j<<" have size ="<<G[i][j].size()<<std::endl;
			for(unsigned int k=0;k<G[i][j].size();k++)
				G[i][j][k].print();
		}
	}   */
	
	/* dynamic program */
	for(int k=0;k<N;k++){
		for(int i=0;i<M;i++){
			// std::cout<<"problem with i,k:"<<i<<" "<<k<<std::endl;
			for(int j=0;j<M;j++)
				if(k>= D[i][j]){
					// std::cout<<"	subproblem: j:"<<j<<" k:"<<k<<" vs D[i][j]:"<<D[i][j]<<std::endl;
					if(addPoints(G[i][k], G[j][k-D[i][j]], T[i][j], max_time)){};
				}
		} 
	} 
	/* print final result */
/* 	std::cout<<"\nFinal data is:"<<std::endl;
	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			std::cout<<"<$"<<i<<","<<j<<">"<<std::endl;
			for(unsigned int k=0;k<G[i][j].size();k++)
				G[i][j][k].print();
			std::cout<<"<"<<i<<","<<j<<"&>"<<std::endl;
		}
	}   */
	
	std::cout<<"Acquiring feasible points took: running time:"<< " seconds" <<std::endl;
	
	// write down running time: 
	logFile << "*******start dynamic********" <<"\n";
	logFile << timer.now() << ":" <<" max_time\t"<< max_time <<"\n";
	logFile << timer.now() <<": table creation time:\t" << timer.elapse()<<"\n"; 
	
	
	/* Find trajectory corresponding different arrival configurations and road segment's distances */
	// vector of road segments 
	std::vector<int> distance_array;
	
	distance_array.push_back(max_time/4);
	distance_array.push_back(max_time*3/8);
	distance_array.push_back(max_time/2);

	
	// choose feasible points for each road segment 
	/* initialize random seed: */
	srand (time(NULL));
	for(unsigned int i=0; i<distance_array.size(); i++){
		for(int j=0; j<NUM_PLANS; j++){
			int v0_index; 
			int feasible_size;
			while(true){
				v0_index = rand()%M; 
				feasible_size = G[v0_index][distance_array[i]].size();
				if(feasible_size >= NUM_PLANS){
					// std::cout<<"subproblem "<<v0_index<<"-"<<distance_array[i]<<" has" << feasible_size <<" plans, >= NUM_PLANS. Continue"<<std::endl; 
					break; 
				}
				// std::cout<<"subproblem "<<v0_index<<"-"<<distance_array[i]<<" has" << feasible_size <<" plans, >= NUM_PLANS. Move to next v0_index."<<std::endl;  
			}
			std::cout<<"\n**********************"<<std::endl;
			// std::cout<<"\n** Problem v0 = "<< v0_index<< "distance = "<<distance_array[i]<<std::endl;
		
			classPoint2T point(0,0);
			int rand_index = rand()%feasible_size; 
			point = G[v0_index][distance_array[i]][rand_index];
			// std::cout<<"\t* Chosen feasible_point: "<<point.time<<" "<<point.vel<<"\n"<<std::endl;
			if(findTrajectory(G, distance_array[i], v0_index, point, T, D) > 0) {}; 
			// std::cout<<"One more plan is extracted!"<<std::endl;
			
		}
		std::cout<<"\n**********************"<<std::endl;
	}
	

	// write down running time: 
	logFile << "************************" <<"\n";
	logFile << timer.now() << ":" <<" time to extract plans:\t"<< timer.elapse() <<"\n";
	logFile << "************************" <<"\n";
	logFile << timer.now() << ":" <<" End! Total running time:\t"<< timer.stop() <<"\n";
	logFile << "************End dynamic programming **********************" <<"\n";
	return 0; 
}
예제 #4
0
QgsPointSequence QgsCircularString::compassPointsOnSegment( double p1Angle, double p2Angle, double p3Angle, double centerX, double centerY, double radius )
{
  QgsPointSequence pointList;

  QgsPointV2 nPoint( centerX, centerY + radius );
  QgsPointV2 ePoint( centerX + radius, centerY );
  QgsPointV2 sPoint( centerX, centerY - radius );
  QgsPointV2 wPoint( centerX - radius, centerY );

  if ( p3Angle >= p1Angle )
  {
    if ( p2Angle > p1Angle && p2Angle < p3Angle )
    {
      if ( p1Angle <= 90 && p3Angle >= 90 )
      {
        pointList.append( nPoint );
      }
      if ( p1Angle <= 180 && p3Angle >= 180 )
      {
        pointList.append( wPoint );
      }
      if ( p1Angle <= 270 && p3Angle >= 270 )
      {
        pointList.append( sPoint );
      }
    }
    else
    {
      pointList.append( ePoint );
      if ( p1Angle >= 90 || p3Angle <= 90 )
      {
        pointList.append( nPoint );
      }
      if ( p1Angle >= 180 || p3Angle <= 180 )
      {
        pointList.append( wPoint );
      }
      if ( p1Angle >= 270 || p3Angle <= 270 )
      {
        pointList.append( sPoint );
      }
    }
  }
  else
  {
    if ( p2Angle < p1Angle && p2Angle > p3Angle )
    {
      if ( p1Angle >= 270 && p3Angle <= 270 )
      {
        pointList.append( sPoint );
      }
      if ( p1Angle >= 180 && p3Angle <= 180 )
      {
        pointList.append( wPoint );
      }
      if ( p1Angle >= 90 && p3Angle <= 90 )
      {
        pointList.append( nPoint );
      }
    }
    else
    {
      pointList.append( ePoint );
      if ( p1Angle <= 270 || p3Angle >= 270 )
      {
        pointList.append( sPoint );
      }
      if ( p1Angle <= 180 || p3Angle >= 180 )
      {
        pointList.append( wPoint );
      }
      if ( p1Angle <= 90 || p3Angle >= 90 )
      {
        pointList.append( nPoint );
      }
    }
  }
  return pointList;
}