コード例 #1
0
ファイル: renderer.hpp プロジェクト: swc4848a/LuaSDL-2.0
		int LOBJECT_METHOD(drawLines, SDL_Renderer * renderer){
			if (state.is_table(1)){
				int count = state.obj_len(1);
				if (count>0){
					SDL_Point* points = new SDL_Point[count];
					int final_count = 0;

					for (int i=0; i< count; i++){
						state.push_integer(i+1);
						state.get_table(1); // 1 T
						if (state.is_table(-1)){
							state.get_field(-1, "x"); // 1 T x
							state.get_field(-2, "y"); // 1 T x y
							points[final_count].x = state.to_integer(-2);
							points[final_count].y = state.to_integer(-1);
							final_count++;
							state.pop(3);
						}else{
							state.pop(1);
						}
					}

					state.push_boolean(SDL_RenderDrawLines(renderer, points, final_count) == 0);

					delete[] points;
					return 1;
				}
			}
			return 0;
		}
コード例 #2
0
ファイル: video_display.c プロジェクト: kotoro/Jakopter
void draw_attitude_indic()
{
	/*
	* simple attitude indicator with the horizon represented by a straight line
	* and the drone by a line with a center point.
	*/
	int i=0;
	//nose inclination = y offset from the horizon
	int nose_incl = (int)(horiz_pitchScale * pitch);
	//"center" of the drone, unaffected by roll
	SDL_Point center = {horiz_posx + horiz_size/2, horiz_posy-nose_incl};
	//series of points representing the drone on the indicator, affected by pitch
	SDL_Point drone_points[] = {
		{horiz_posx, center.y},
		{center.x-5, center.y},
		{center.x, center.y-5},
		{center.x+5, center.y},
		{horiz_posx+horiz_size, center.y}
	};
	int nb_points = sizeof(drone_points)/sizeof(SDL_Point);
	//apply roll to the points
	for(i=0; i<nb_points; i++)
		rotate_point(&drone_points[i], &center, roll);
	//1. draw the horizon
	SDL_RenderDrawLine(renderer, horiz_posx, horiz_posy, horiz_posx+horiz_size, horiz_posy);
	//2. draw the drone's "flight line"
	SDL_RenderDrawLines(renderer, drone_points, nb_points);
}
コード例 #3
0
ファイル: testwheel.c プロジェクト: andrenho/newhope
void draw_shape(cpBody* body, cpShape* shape, void* data)
{
	// get body info
	cpVect v = cpBodyGetPos(body);
	cpFloat angle = cpBodyGetAngle(body);
	cpVect rot = cpvforangle(angle);

	// get vectors
	int n = cpPolyShapeGetNumVerts(shape); 
	SDL_Point* pts = calloc(sizeof(SDL_Point), n+1);

	// rotate vectors
	int i;
	for(i=0; i<n; i++) {
		cpVect p = cpPolyShapeGetVert(shape, i);
		cpVect vr = cpvrotate(cpv(p.x,p.y), rot);
		pts[i] = (SDL_Point) { (vr.x+v.x)*10+50, (vr.y+v.y)*10+50 };
		if(i == 0)
			pts[n] = pts[i];
	}

	// draw
	SDL_RenderDrawLines(ren, pts, n+1);

	free(pts);
}
コード例 #4
0
//Draws lines between the array of points
//param:pointsArray->The array of points to draw lines between
//param:numberOfPoints->The length of the array
//param:connectEndToStart->True to have the last point connect to the first point
int SpriteBatch::DrawLines(SDL_Point* pointsArray, int numberOfPoints,SDL_Color color, bool connectEndToStart)
{
	//Check if spritebatch.begin has been called
	if(!begun)
	{
		std::cout<<"Begin must be called before attempting to draw"<<std::endl;
		return -1;
	}

	int result = 0;
	
	//Check for proper size
	if(numberOfPoints < 2)
	{
		std::cout<<"DrawLines Error: Number Of Points must be greater than 2"<<std::endl;
		return -1;
	}

	//Set line color
	result = SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
	
	//check for color setting problems
	if(result != 0)
	{
		std::cout<<"DrawLines error: Problem setting lines' color"<<std::endl;
		return result;
	}	

	//Draw all the lines
	result = SDL_RenderDrawLines(renderer, pointsArray, numberOfPoints);

	//Check for draw errors
	if(result != 0)
	{
		std::cout<<"DrawLines error" <<std::endl;
		return result;
	}

	//If true to connect end to start
	if(connectEndToStart)
	{
		//Draw a line from first point to last point
		result = SDL_RenderDrawLine(renderer, pointsArray[0].x, pointsArray[0].y, 
			pointsArray[numberOfPoints - 1].x, pointsArray[numberOfPoints-1].y);

		//Check for draw errors
		if(result != 0)
		{
			std::cout<<"DrawLines error: Can't connect last element to beginning element"<<std::endl;
			return result;
		}
	}

	//return success
	return result;
}
コード例 #5
0
ファイル: GUI.cpp プロジェクト: HaoguangYang/AgileVehicle
void DrawWheel3(const std_msgs::UInt16MultiArray& WheelStatus3){
    float angle = Enc[0][3].extractAngle()/2.0;
    static int position[2] = {182, 252};
    SDL_Point draw[9];
    pointsRotTrans(9, wheel, angle, 1, position, draw);
    //printf("Angle Watch: %f\n", (angle)/M_PI*180.0);
    SDL_RenderDrawLines(renderer, draw, 9);
    SDL_RenderPresent(renderer);
	refresh[3] = true;
}
コード例 #6
0
ファイル: SDL2DRenderManager.cpp プロジェクト: kns-gh/oodevs
void SDL2DRenderManager::DrawCircle( const Circle& circle )
{
    int sampling = static_cast< int >( circle.radius_ );
    int center = static_cast< int >( circle.center_.x_ );
    SDL_Point* pointsUp = new SDL_Point[ 2 * sampling + 1 ];
    SDL_Point* pointsDown = new SDL_Point[ 2 * sampling + 1 ];
    for( int i = 0; i < 2 * sampling + 1; ++i )
    {
        int posx = i - sampling + center;
        pointsUp[ i ].x = posx;
        pointsDown[ i ].x = posx;
        pointsUp[ i ].y =  static_cast< int >( circle.center_.y_ + sqrt( pow( circle.radius_, 2.0 ) - pow( posx - center, 2.0 ) ) );
        pointsDown[ i ].y = static_cast< int >( circle.center_.y_ - sqrt( pow( circle.radius_, 2.0 ) - pow( posx - center, 2.0 ) ) );
    }
    SDL_RenderDrawLines( renderer_, pointsUp, 2 * sampling + 1 );
    SDL_RenderDrawLines( renderer_, pointsDown, 2 * sampling + 1 );
    delete pointsUp;
    delete pointsDown;
}
コード例 #7
0
ファイル: line.cpp プロジェクト: joejoyce/jsEngine
JSBool drawLines(JSContext *cx,uintN argc , jsval* vp){
	JSObject *jthis = NULL;
	pList *list = NULL;
	jthis = JS_THIS_OBJECT(cx, vp);
	if(jthis){
		list = (pList*)JS_GetInstancePrivate(cx, jthis, &lineList, NULL);
		if(list){
			SDL_RenderDrawLines(renderer,list->points,list->length);
			JS_SET_RVAL(cx,vp,JSVAL_TRUE);
			return JS_TRUE;
		}
	}
	JS_SET_RVAL(cx,vp,JSVAL_TRUE);
	return JS_TRUE;
}
コード例 #8
0
ファイル: Game.cpp プロジェクト: darcusfenix/lsdl2
void Game::render()
{

	SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
	SDL_RenderClear(ren);
	SDL_SetRenderDrawColor(ren, 255, 0, 0, 255);
	
	SDL_SetRenderDrawColor(ren, rand()%255, rand()%255, rand()%255, rand()%255);

	if(asteroides.size() > 0)
		for (int i = 0; i < asteroides.size(); i++)
			SDL_RenderDrawLines(ren, asteroides[i].getPoints(), asteroides[i].getNumeroVertices() + 1);
		
	SDL_RenderPresent(ren);
	return;
	
}
コード例 #9
0
ファイル: sdlrender_stub.c プロジェクト: fccm/OCamlSDL2
CAMLprim value
caml_SDL_RenderDrawLines(value renderer, value ml_points)
{
    unsigned int i;
    unsigned int count = Wosize_val(ml_points);
    SDL_Point * points = malloc(count * sizeof(SDL_Point));
    for (i = 0; i < count; i++) {
        value p = Field(ml_points, i);
        points[i].x = Int_val(Field(p, 0));
        points[i].y = Int_val(Field(p, 1));
    }
    int r = SDL_RenderDrawLines(
                SDL_Renderer_val(renderer),
                points, count);
    free(points);
    if (r) caml_failwith("Sdlrender.draw_lines");
    return Val_unit;
}
コード例 #10
0
ファイル: GameProyecto.cpp プロジェクト: holaalex2204/DSD
void GameProyecto:: render()
{
	SDL_Point p1,p2;
	SDL_SetRenderDrawColor(m_pRenderer, 0, 0, 0, 255);
	SDL_RenderClear(m_pRenderer);
	SDL_SetRenderDrawColor(m_pRenderer, 255, 0, 0, 255);	
	for(int  i=0; i < asteroides.size(); i++) {
		Coordenada centro = asteroides[i].obtenCentro();
		SDL_SetRenderDrawColor(m_pRenderer, rand()%255, rand()%255, rand()%255, 255);
		vector<Coordenada> vertices = asteroides[i].obtenVertices();
		p1.x = vertices.back().obtenerX();
		p1.y = vertices.back().obtenerY();
		for(int j = 0; j<vertices.size(); j++)
		{
			p2.x = vertices[j].obtenerX();
			p2.y = vertices[j].obtenerY();
			SDL_Point points[4] = { p1, p2};
			SDL_RenderDrawLines(m_pRenderer, points, 2);
			p1 = p2;
		}
	}
	SDL_RenderPresent(m_pRenderer);
}
コード例 #11
0
ファイル: Window.cpp プロジェクト: Gumichan01/lunatix-engine
void Window::drawLines( const std::vector<lx::Graphics::ImgCoord>& vpoints ) noexcept
{
    SDL_RenderDrawLines( m_wimpl->renderer,
                         reinterpret_cast<const SDL_Point *>( &vpoints[0] ),
                         static_cast<int>( vpoints.size() ) );
}
コード例 #12
0
ファイル: level_edit.c プロジェクト: numpad/PD
int main(int argc, char *argv[]) {
	if (argc == 1) {
		puts("Use: level_edit <level_folder>");
		return 1;
	}

	qw_screen(800, 600, 0, "Projekt Defense");
	
	/* get background image from level folder */
	char lvl_bg[128] = {0};
	strcpy(lvl_bg, argv[1]);
	strcat(lvl_bg, "/background.png");
	qw_image background = qw_loadimage(lvl_bg);
	

	int max_points = 128,
	    points_i = 0;
	SDL_Point *points = malloc(sizeof(SDL_Point) * max_points);
	
	while (qw_running()) {
		qw_drawimage(background);
		
		qw_color(200, 100, 120, 255);
		qw_fillrect(qw_mousex - 2, qw_mousey - 2, 4, 4);
		
		/* waypoint placement */
		if (qw_mousedown(SDL_BUTTON_LEFT)) {
			if (points_i == 0) {
				points[points_i++] = point_new(qw_mousex, qw_mousey);
			} else {
				/* if not the first point placed: check if current point is to close to the last one */
				SDL_Point np = point_new(qw_mousex, qw_mousey);
				
				if (point_distance(points[points_i - 1], np) > 7.f)
					points[points_i++] = np;
			}
			
			/* we need more points? */
			if (points_i == max_points) {
				max_points += 128;
				points = realloc(points, sizeof(SDL_Point) * max_points);
			}
		}
		
		if (qw_keydown(QW_KEY(E))) {
			if (points_i > 1) {
				export_points(argv[1], points, points_i);
				puts("Exported!");
				qw_quit();
			}
		}

		qw_color(100, 120, 200, 255);
		SDL_RenderDrawLines(qw_renderer, points, points_i);

		qw_redraw();
		if (qw_keydown(QW_KEY(ESCAPE))) {
			qw_quit();
		}
	}
	
	free(points);
	qw_destroyimage(background);
	
	return 0;
}
コード例 #13
0
ファイル: genetic.cpp プロジェクト: Arkezar/TSP_GA
void GA::Execute(){
	std::cout << "Solving TSP\n";
		SDL_Window *window = NULL;
	//SDL_Surface *surface;
	SDL_Init(SDL_INIT_VIDEO);
	const int wWidth = 640;
	const int wHeight = 480;
	window = SDL_CreateWindow("TSP Visualizer",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, wWidth,wHeight,SDL_WINDOW_OPENGL);
	//surface = SDL_GetWindowSurface(window);
	SDL_UpdateWindowSurface(window);
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
	std::vector<SDL_Rect> cityDots;
	for(const auto& c : baseCityVector){
		SDL_Rect dot;
		dot.x = c.getX() * wWidth / maxXPosition - 2;
		dot.y = c.getY() * wHeight / maxYPosition - 2;
		dot.w = 4;
		dot.h = 4;
		cityDots.push_back(dot);
	}

	for(int g = 1; g < targetGenerationNumber; g++){
		currentGeneration = g;
		std::cout << "Current generation: " << g << "\n";
		SortCandidates();
		//std::cout << "Sorted population\n";
		parentsPopulation.clear();
		SelectParents(populationBreadersPercentage);
		int childrenPopulationSize = populationSize * populationBreadersPercentage / 100;	
		//std::cout << "Childrem population size: " << childrenPopulationSize << "\n";
		while(newPopulation.size() < childrenPopulationSize){
			//std::cout << "New pop size: " << newPopulation.size() << "\n";
			auto parent1 = parentsPopulation.at( std::rand() % parentsPopulation.size() );
			auto parent2 = parentsPopulation.at( std::rand() % parentsPopulation.size() );
			
			//std::future<Candidate> fChild1 = std::async(GA::PMXCrossover,parent1,parent2);
			
			Candidate child1 = PMXCrossover(parent1,parent2);
			Candidate child2 = PMXCrossover(parent2,parent1);
			//if(std::find(newPopulation.begin(),newPopulation.end(),child) == newPopulation.end())
			newPopulation.push_back ( child1 );
			newPopulation.push_back ( child2 );
		}
		//std::cout << "Created new population\n";
		for(int m = 1; m <= newPopulation.size() * mutationPercentage / 100; m++){
			//auto mutant = newPopulation[std::rand() % newPopulation.size()];
			auto mutant = newPopulation[ (std::rand() * m) % newPopulation.size()];
			Mutate(mutant, mutationPower);
			mutant.ReEvaluate(distances);
		}
		//std::cout << "Mutated population\n";
		population.insert(population.end(), newPopulation.begin(), newPopulation.end());
		newPopulation.clear();
		NormalizeCandidates();
		SortCandidates();
		population = std::vector<Candidate>(population.begin(),population.begin()+populationSize);
		std::cout << "Best: " << population.at(0) << "\n";
		
		SDL_SetRenderDrawColor(renderer, 255,255,255,255);
		SDL_RenderClear(renderer);
				
		std::vector<SDL_Point> cityPositions;
				/*
		int maxX;
		int maxY;
		for(const auto& city : getBest().getCandidate()){
			maxX = 0;
			maxY = 0;
			if(city.getX() > maxX)
				maxX = city.getX();
			if(city.getY() > maxY)
				maxY = city.getY();
		}	
		*/
		
		for(const auto& city : population[0].getCandidate()){
			int posY = city.getY() * wHeight / maxYPosition;
			int posX = city.getX() * wWidth / maxXPosition;

			SDL_Point position;
			position.y = city.getY() * wHeight / maxYPosition;
			position.x = city.getX() * wWidth / maxXPosition;
			cityPositions.push_back(position);

			
		}
		SDL_SetRenderDrawColor(renderer, 255,0,0,255);

		SDL_RenderDrawLines(renderer, &cityPositions[0], cityPositions.size());
		SDL_SetRenderDrawColor(renderer, 0,255,0,255);
		SDL_RenderFillRects(renderer, &cityDots[0], cityDots.size());
		
		SDL_RenderPresent(renderer);
		
		/*
		if(renderer == NULL){
			SDL_RenderDrawLine(renderer, g*10, g, 250, 250);	
		}
		*/
	}
	SDL_DestroyWindow(window);
	SDL_Quit();

}
コード例 #14
0
void Rock::draw(SDL_Renderer* r)
{
    SDL_SetRenderDrawColor(r, 255, 255, 0, 1.0);
    SDL_RenderDrawLines(r, lines, 10);
    SDL_SetRenderDrawColor(r, 0, 0, 0, 255);
}
コード例 #15
0
ファイル: polygon2.c プロジェクト: rikirenz/Graphic
int main(void) 
{
SDL_Window *win;
SDL_Renderer *ren;

int vxmax,vymax;
int n,i,j,cx,cy;
int x[DIM],y[DIM]; 
SDL_Point p[DIM];
float rx,ry,step,alfa;

  if(SDL_Init(SDL_INIT_VIDEO)<0)
  {
    fprintf(stderr,"Couldn't init video: %s\n",SDL_GetError());
    return(1);
  }

  vxmax=400;
  vymax=400;

  win= SDL_CreateWindow("Polygon", 100, 100, vxmax, vymax, SDL_WINDOW_SHOWN);
  if(win==NULL){
	fprintf(stderr,"SDL_CreateWindow Error: %s\n",SDL_GetError());
	SDL_Quit();
	return 1;
  }

  ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  if (ren == NULL){
	SDL_DestroyWindow(win);
	fprintf(stderr,"SDL_CreateRenderer Error: %s\n",SDL_GetError());
	SDL_Quit();
	return 1;
  }

  SDL_SetRenderDrawColor(ren, 50, 50, 50, 255);
  SDL_RenderClear(ren);
  SDL_RenderPresent(ren);

  printf("\nDisegno di un poligono regolare: \n");
  printf("Dai il numero di vertici: \n");
  scanf("%d",&n);
  cx=(int)vxmax/2;
  cy=(int)vymax/2;
  rx=(float)vxmax/2-2;
  ry=(float)vymax/2-2;
  step=6.28/n;
  for (j=0; j<n; j++)
  {
	  alfa=j*step;
	  x[j]=(int)rx*cos(alfa)+cx;
	  y[j]=(int)ry*sin(alfa)+cy;
          p[j].x=x[j];
          p[j].y=y[j];
  }
  p[n].x=x[0];
  p[n].y=y[0];


#ifdef DEBUG
/* disegna la crf. circoscritta al poligono */
 GC_FillCircle(ren, cx, cy, rx);
 GC_DrawCircle(ren, cx, cy, rx);
#endif

/* disegna un poligono di colore bianco */  
  SDL_SetRenderDrawColor(ren,255,255,255,255);
  SDL_RenderDrawLine(ren, x[n-1], y[n-1], x[0], y[0]);
  for (i=0; i<n-1; i++)
    SDL_RenderDrawLine(ren, x[i], y[i], x[i+1], y[i+1]);
  SDL_SetRenderDrawColor(ren,255,0,0,255);
  SDL_RenderDrawLines(ren, p, n+1);
  SDL_RenderPresent(ren);

#ifdef DEBUG
/* disegno artistico: definire DEBUG nel Makefile */
  SDL_SetRenderDrawColor(ren,255,0,0,255);
  for (i=0; i<n; i++)
    for (j=i+1; j<n; j++)
      SDL_RenderDrawLine(ren, x[i], y[i], x[j], y[j]);
  SDL_RenderPresent(ren);
#endif

press();
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);

  
  SDL_Quit();
  return(0);
} 
コード例 #16
0
ファイル: main.c プロジェクト: aevalo/sdl2
int main(int argc, const char* const argv[])
{
  srand(time(NULL));

  if (SDL_Init(SDL_INIT_VIDEO) != 0)
  {
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL:  %s\n", SDL_GetError());
    exit(EXIT_FAILURE);
  }
  atexit(SDL_Quit);

  if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG)
  {
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL2 image:  %s\n", IMG_GetError());
    exit(EXIT_FAILURE);
  }
  atexit(IMG_Quit);

  SDL_Window* window = NULL;
  SDL_Renderer* renderer = NULL;
  if (SDL_CreateWindowAndRenderer(640, 480, SDL_WINDOW_SHOWN, &window, &renderer) < 0)
  {
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window and renderer: %s\n", SDL_GetError());
    exit(EXIT_FAILURE);
  }

  SDL_Surface* icon = IMG_Load("resources/iconzilla.png");
  if (!icon)
  {
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to load icon file: %s\n", IMG_GetError());
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    exit(EXIT_FAILURE);
  }
  SDL_SetWindowIcon(window, icon);
  SDL_FreeSurface(icon);
  SDL_SetWindowTitle(window, "SDL2 test app");

  int done = 0;
  SDL_Point lines[3][2] = {
    {
      {rand() % 640, rand() % 480},
      {rand() % 640, rand() % 480}
    },
    {
      {rand() % 640, rand() % 480},
      {rand() % 640, rand() % 480}
    },
    {
      {rand() % 640, rand() % 480},
      {rand() % 640, rand() % 480}
    }
  };
  SDL_Color colors[3] = {
    {255, 0, 0, SDL_ALPHA_OPAQUE},
    {0, 255, 0, SDL_ALPHA_OPAQUE},
    {0, 0, 255, SDL_ALPHA_OPAQUE}
  };
  while (!done)
  {
    SDL_Event event;
    while (SDL_PollEvent(&event))
    {
      if (event.type == SDL_WINDOWEVENT)
      {
        switch (event.window.event)
        {
          case SDL_WINDOWEVENT_CLOSE:
            done = 1;
            break;
        }
      }
    }
    if (SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE) < 0)
    {
      SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to set draw color: %s\n", SDL_GetError());
    }
    if (SDL_RenderClear(renderer) < 0)
    {
      SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to clear renderer: %s\n", SDL_GetError());
    }
    for(int i = 0; i < 3; i++)
    {
      if (SDL_SetRenderDrawColor(renderer, colors[i].r, colors[i].g, colors[i].b, colors[i].a) < 0)
      {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to set draw color: %s\n", SDL_GetError());
      }
      if (SDL_RenderDrawLines(renderer, lines[i], 2) < 0)
      {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to draw line: %s\n", SDL_GetError());
      }
    }
    SDL_RenderPresent(renderer);
  }

  SDL_DestroyRenderer(renderer);
  SDL_DestroyWindow(window);

  return 0;
}