Example #1
0
void SDLDebugDraw::DrawPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color &color) {
    Sint16 x[vertexCount];
    Sint16 y[vertexCount];
    for(int i = 0; i < vertexCount; ++i){
        b2Vec2 v = vertices[i]; //((vertices[i] + camera.wpos)*camera.getScale()) ;
        v *= camera;
        
        x[i] = (Sint16) v.x;
        y[i] = (Sint16) v.y;
    }

    polygonRGBA (App::get()->ren->renderer, x, y, vertexCount, color.r, color.g, color.b, color.a);

    polygonRGBA (App::get()->ren->renderer, x, y, vertexCount, 255,255,255,255);
}
Example #2
0
/* Interface to SDL_gfx version for drawing polygon  */
int Surface::DrawPolygon(Sint16 x[], Sint16 y[], int n, int color, int fill) {
  int red = (color >> 16) & 0xff;
  int green = (color >> 4) & 0xff;
  int blue = color & 0xff;
  if (fill)
    filledPolygonRGBA(surf, x, y, n, red, green, blue, 255);
  else
    polygonRGBA(surf, x, y, n, red, green, blue, 255);
  return 0;
}
Example #3
0
void CPhysicsDebugDraw::DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{

	Sint16 *PX = new Sint16[vertexCount];
	Sint16 *PY = new Sint16[vertexCount];
	for (int32 i = 0; i < vertexCount; i++)
		{
		PX[i] = (Sint16) (vertices[i].x*C_RATIO);
		PY[i] = (Sint16) (vertices[i].y*C_RATIO);
		//PY[i] = (Sint16) (C_LOGICAL_SIZE_Y -vertices[i].y);
		}
	polygonRGBA(g_app->sdlRenderer,PX,PY,vertexCount,(Uint8)(color.r * 255),(Uint8)(color.g * 255),(Uint8)(color.b * 255),255);
    
	delete []PX;
	delete []PY;
}
Example #4
0
void Renderer::drawPolygon(const b2Vec2* vertices, int32 vertexCount, Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha, bool filled){
	std::vector<short> x(vertexCount);
	std::vector<short> y(vertexCount);

	for(int i=0;i<vertexCount;i++){
		b2Vec2 vec = toScreenCoords(vertices[i]);

		x[i] = (short) vec.x;
		y[i] = (short) vec.y;
	}

	if(filled){
		filledPolygonRGBA(renderer, x.data(), y.data(), vertexCount, red, green, blue, alpha);
	}else{
		polygonRGBA(renderer, x.data(), y.data(), vertexCount, red, green, blue, alpha);
	}
}
Example #5
0
void Renderer::drawPolygon(int16_t * vx, int16_t * vy, int n, const SDL_Color &color)
{
    polygonRGBA(this->renderer, vx, vy, n, color.r, color.g, color.b, color.a);
}
Example #6
0
void draw_hex(SDL_Surface *screen, Hex h, int i, int j, TTF_Font *font) {
    int r, g, blue, alpha;
    alpha = 255;
    SDL_Color text_color = {255, 255, 255};
    char text_label[16];
    
    switch (h.content) {
        case VIDE: {
            r = 150;
            g = 150;
            blue = 150;
            strcpy(text_label, "VIDE");
            break;
        }
        case OBSTACLE: {
            r = 90;
            g = 90;
            blue = 90;
            strcpy(text_label, "OBSTACLE");
            break;
        }
        case EGOUT: {
            if (h.label == 0) {
                r = 130;
                g = 142;
                blue = 35;
                sprintf(text_label, "(O) EGOUT %d", h.id);
            } else if (h.label == 1) {
                r = 140;
                g = 154;
                blue = 110;
                sprintf(text_label, "(F) EGOUT %d", h.id);
            }
            break;
        }
        case LAMPE: {
            if (h.label > 0) {
                // yellow (lit lamp post)
                r = 255;
                g = 255;
                blue = 0;
                text_color.r = 0;
                text_color.g = 0;
                text_color.b = 0;
            } else {
                // gray
                r = 150;
                g = 150;
                blue = 110;   
            }
            sprintf(text_label, "(%d) LAMPE %d", h.label, h.id);
            break;
        }
        case SORTIE: {
            r = 255;
            g = 255;
            blue = 255;
            text_color.r = 0;
            text_color.g = 0;
            text_color.b = 0;
            sprintf(text_label, "SORTIE %d", h.id);
            break;
        }
        case BARRAGE: {
            r = 25;
            g = 25;
            blue = 25;
            sprintf(text_label, "BARRAGE %d", h.id);
            break;
        }
        case MAIGRET: {
            // brown
            r = 139;
            g = 69;
            blue = 19;
            strcpy(text_label, "MAIGRET");
            break;
        }
        case POIROT: {
            // red
            r = 255;
            g = 0;
            blue = 0;
            strcpy(text_label, "POIROT");
            break;
        }
        case LUMIERE: {
            // yellow
            r = 0;
            g = 255;
            blue = 255;
            text_color.r = 0;
            text_color.g = 0;
            text_color.b = 0;
            strcpy(text_label, "LUMIERE");
            break;
        }
        case LEGOUTIER: {
            // orange
            r = 255;
            g = 140;
            blue = 0;
            text_color.r = 0;
            text_color.g = 0;
            text_color.b = 0;
            strcpy(text_label, "LEGOUTIER");
            break;
        }
        case GERBER: {
            // blue
            r = 0;
            g = 0;
            blue = 255;
            strcpy(text_label, "GERBER");
            break;
        }
        case CRUCHOT: {
            // dark blue
            r = 0;
            g = 0;
            blue = 128;
            strcpy(text_label, "CRUCHOT");
            break;
        }
        case FREUD: {
            // purple
            r = 160;
            g = 32;
            blue = 240;
            text_color.r = 0;
            text_color.g = 0;
            text_color.b = 0;
            strcpy(text_label, "FREUD");
            break;
        }
        case DISCRETE: {
            // green
            r = 34;
            g = 139;
            blue = 34;
            strcpy(text_label, "DISCRETE");
            break;
        }
    }
    
    if (h.seen == 1) {
        text_color.r = 255;
        text_color.g = 255;
        text_color.b = 0;
    }
    
    int xi = 0, yi = 500;
    // int x = xi + (a + c) * i;
    int x = xi + (a + c) * i;
    int y = yi - 2 * b * j + b * i;
    short s[6] = { x, x + a, x + a + c, x + 2 * c, x + a + c, x + a }; 
    short t[6] = { y + b, y, y, y + b, y + 2 * b, y + 2 * b };
    
    filledPolygonRGBA(screen, 
        s, t,
        6,
        r, g, blue, alpha);
    
    polygonRGBA(screen, 
        s, t,
        6,
        255, 255, 255, 255);
        
    // compute the metrics of the text to display
    int width, height;
    TTF_SizeUTF8(font, text_label, &width, &height);
    // compute the corresponding text
    SDL_Rect rect;
    rect.x = x + (2 * c - width) / 2;
    rect.y = y + (2 * b - height) / 2;
    // draw the text
    SDL_Surface *text_surface;
    if(!(text_surface = TTF_RenderText_Solid(font, text_label, text_color))) {
        fprintf(stderr, "TTF_RenderText_Solid: %s\n", TTF_GetError());
    } else {
        SDL_BlitSurface(text_surface, NULL, screen, &rect);
    }
    SDL_FreeSurface(text_surface);
    
    if (h.content == MAIGRET) {
        // draw the arrow indicating the lantern's direction
        int ybase, ynorth, ywest, yeast;
        int xbase, xnorth, xwest, xeast;
        
        switch(h.label) {
            case 1: {
                xbase = x + c;
                ybase = y + (3 * b) / 4;
                ynorth = ybase - b / 2;
                xnorth = xbase;
                xwest = xnorth - 6;
                ywest = ynorth + 6;
                xeast = xnorth + 6;
                yeast = ywest;
                break;
            }
            case 2: {
                ybase = y + (3 * b) / 4;
                xbase = x + c;
                ynorth = ybase - b / 4;
                xnorth = xbase - (b * 87) / 200;
                ywest = ynorth + 6;
                xwest = xnorth + 2;
                yeast = ynorth - 2;
                xeast = xnorth + 6;
                break;
            }
            case 3: {
                xbase = x + c;
                ybase = y + (5 * b) / 4;
                ynorth = ybase + b / 4;
                xnorth = xbase - (b * 87) / 200;
                xwest = xnorth + 6;
                ywest = ynorth + 2;
                xeast = xnorth + 2;
                yeast = ynorth - 6;
                break;
            }
            case 4: {
                xbase = x + c;
                ybase = y + (5 * b) / 4;
                ynorth = ybase + b / 2;
                xnorth = xbase;
                xwest = xnorth - 6;
                ywest = ynorth - 6;
                xeast = xnorth + 6;
                yeast = ywest;
                break;
            }
            case 5: {
                xbase = x + c;
                ybase = y + (5 * b) / 4;
                ynorth = ybase + b / 4;
                xnorth = xbase + (b * 87) / 200;
                xwest = xnorth - 2;
                ywest = ynorth - 6;
                xeast = xnorth - 6;
                yeast = ynorth + 2;
                break;
            }
            case 6: {
                ybase = y + (3 * b) / 4;
                xbase = x + c;
                ynorth = ybase - b / 4;
                xnorth = xbase + (b * 87) / 200;
                ywest = ynorth - 2;
                xwest = xnorth - 6;
                yeast = ynorth + 6;
                xeast = xnorth - 2;
                break;
            }
        }
        
        // main line
        lineRGBA(screen, xbase, ybase, xnorth, ynorth,
            255, 255, 0, 255);
        // west part
        lineRGBA(screen, xwest, ywest, xnorth, ynorth,
            255, 255, 0, 255);
        // east part
        lineRGBA(screen, xeast, yeast, xnorth, ynorth,
            255, 255, 0, 255);
    }
}
Example #7
0
void fillWay(Way * way){
	if(map == NULL){
		fprintf(stderr,"La map est NULL dans line fonction fillWay\n");
		return;
	}
	if(way == NULL){
		fprintf(stderr,"Le way est NULL dans line fonction fillWay\n");
		return;
	}
	ListNode * l = way->listNd;
	if(l == NULL){
		fprintf(stderr,"Le way %ld a pas de noeud : line.c fonction fill way\n",way->id );
		return;
	}
	refListNode * current =l->firstRef;
	int nbre=0;
	if(way->size != 0){
		short coord_x [way->size];
		short coord_y [way->size];
		while(current != NULL){
			Node * currentNode = searchNode(map->avl,current->nd);
			if(currentNode != NULL){
				if(currentNode->c != NULL){
					coord_x[nbre] = miseAEchelleX(currentNode->c->x,map->bounds->max->x,windows_Width);
					coord_y[nbre] = miseAEchelleY(currentNode->c->y,map->bounds->max->y,windows_Height);
					nbre++;
				}
				else{
					fprintf(stderr,"le node %ld n'a pas de coordonnees\n",current->nd );
				}
				current = current->next;
			}
			else{
				fprintf(stderr,"Le node %ld n'est pas définis dans le fichier d'entree \n",current->nd );
			}
		}
		if(way->tag != NULL && way->tag->tagKey != NULL && way->tag->c != NULL){
			if(strcmp(way->tag->tagKey,"highway")==0){
				int draw = 1;
				int thick = 0;
				if(way->tag->thick != 0){
					thick = (way->tag->thick+modifThink);
					if(thick < 1){
						draw = zoomDrawHighway(way->tag->tagValue,modifThink);
						thick = 1;
					}
					thick *= zoom;
				}
				int i;
				int x = coord_x[0];
				int y = coord_y[0];
				if(draw == 1){
					for(i=0;i<way->size;i++){
						thickLineRGBA(renderer,x,y,coord_x[i],coord_y[i],thick,way->tag->c->red,way->tag->c->green,way->tag->c->blue,255);
						if(drawContour ==1){
							int diff = 100;
							thickLineRGBA(renderer,x+thick/2,y+thick/2,coord_x[i]+thick/2,coord_y[i]+thick/2,1,checkColor(way->tag->c->red-diff),checkColor(way->tag->c->green-diff),checkColor(way->tag->c->blue-diff),255);
							thickLineRGBA(renderer,x-thick/2,y-thick/2,coord_x[i]-thick/2,coord_y[i]-thick/2,1,checkColor(way->tag->c->red-diff),checkColor(way->tag->c->green-diff),checkColor(way->tag->c->blue-diff),255);
						}
						x = coord_x[i];
						y = coord_y[i];
					}

					//highway(way,coord_y,coord_x,thick);
					//nameHighway(way,l);
				}
			}

			else{
				if(drawContour == 1){
					polygonRGBA(renderer,coord_x,coord_y,way->size,139,71,137,255);
				}
				filledPolygonRGBA(renderer,coord_x,coord_y,way->size,way->tag->c->red,way->tag->c->green,way->tag->c->blue,255);
			}
		}
		else{
			filledPolygonRGBA(renderer,coord_x,coord_y,way->size,0,0,255,255);
		}
	}
}