Ejemplo n.º 1
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10];
    struct point uav_points[4] = { {0, 0}, {6, 8}, {0, -8}, {-6, 8} };
    struct polygon uav = {
        .len = 4,
        .points = uav_points,
    };
    struct point arrow_points[7] = { {1, -10}, {1, -3}, {4, -4}, {0, 0},
                                     {-4, -4}, {-1, -3}, {-1, -10} };
    struct polygon arrow = {
        .len = 7,
        .points = arrow_points,
    };

    move_polygon(&uav, ca->width >> 1, ca->height >> 1);
    draw_polygon(&uav, 3, ca);
    move_polygon(&uav, -1, -1);
    draw_polygon(&uav, 1, ca);


    move_polygon(&arrow, 0, -11);
    transform_polygon(&arrow, ca->width >> 1, ca->height >> 1, priv->direction - priv->heading);
    draw_polygon(&arrow, 3, ca);
    move_polygon(&arrow, -1, -1);
    draw_polygon(&arrow, 1, ca);

    switch (get_units(w->cfg)) {
        case UNITS_METRIC:
        default:
            sprintf(buf, "%dkm/h", (int) ((priv->speed * 3600) / 1000));
            break;
        case UNITS_IMPERIAL:
            sprintf(buf, "%dmph", (int) ((priv->speed * 3600) * M2MILE));
            break;
        case UNITS_CUSTOM_1:
            sprintf(buf, "%dm/s", (int) (priv->speed));
            break;
        case UNITS_CUSTOM_2:
            sprintf(buf, "%df/s", (int) (priv->speed * M2FEET));
            break;
        case UNITS_CUSTOM_3:
            sprintf(buf, "%dkn", (int) ((priv->speed * 3600 * 1.852) / 1000));
            break;
    }
    draw_str(buf, 0, 0, ca, 0);
}


const struct widget_ops wind_widget_ops = {
    .name = "Wind information",
    .mavname = "WINDINF",
    .id = WIDGET_WIND_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Ejemplo n.º 2
0
void drop_polygon_down(Polygon* surface, int n)
{
	//	Polygon is array of subpoly which are ranges from points array
	//	Surface is like a points array
	//	Down means min y (0,-1)  	
	double s_bounds[4];
	surface_bounds(s_bounds ,surface);
	double bounds[4];
	polygon_bounds(bounds, surface, n);
	
	// move polygon to the top of surface + 10
	move_polygon(surface, n, 0, s_bounds[3] - bounds[1] + 10);
/*
	# Now get shortest distance from surface to polygon in positive x=0 direction
	# Such distance = min(distance(vertex, edge)...)  where edge from surface and 
	# vertex from polygon and vice versa...
*/
	double dist = 1e37;
	double d;

	for (int n_s=0; n_s<surface->len;n_s++)
	{	
		for(int i=surface->poly[n_s*2];i<surface->poly[n_s*2+1];i+=2)
		{
			for (int j=surface->subpoly[i];j<surface->subpoly[i+1]-2;j+=2)
			{

				for(int i1=surface->poly[n*2];i1<surface->poly[n*2+1];i1+=2)
				{
					for (int j1=surface->subpoly[i1];j1<surface->subpoly[i1+1]-2;j1+=2)
					{
						// polygon vertex to surface
						d = vertex_to_segment_vertical_dist( surface->points[j1],surface->points[j1+1],  surface->points[j],surface->points[j+1], surface->points[j+2],surface->points[j+3]);
						if (d>=0 && dist>d){dist=d;}	
						// surface vertex to polygon
						d = vertex_to_segment_vertical_dist( surface->points[j],surface->points[j+1],  surface->points[j1],surface->points[j1+1], surface->points[j1+2],surface->points[j1+3]);
						if (d>=0 && dist>d){dist=d;}	
					}
					
				
				}
		
			}
		
		}
		
	}
	
	if (dist<1e37)
	{
		move_polygon(surface,n,0, -dist);
	}
}
Ejemplo n.º 3
0
void move_surface( Polygon*  surface, double x, double y)
{
	for (int i=0;i<surface->len;i++)
	{
		move_polygon(surface,i,x,y);	
	}
}
Ejemplo n.º 4
0
static void render(struct widget *w)
{
    struct home_data *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[50];
    float d, a;
    struct point arrow_points[7] = { {-3, 0}, {-3, -6}, {3, -6}, {3, 0},
                                     {6, 0}, {0, 6}, {-6, 0} };
    struct polygon arrow = {
        .len = 7,
        .points = arrow_points,
    };

    if (priv->lock != HOME_LOCKED) {
        sprintf(buf, "No Home");
        draw_str(buf, 0, 0, ca, 2);
    } else {
        switch (get_units(w->cfg)) {
            case UNITS_METRIC:
            default:
                sprintf(buf, "Alt %dm\nDis %dm\n%d",
                        priv->altitude,
                        (unsigned int) priv->distance,
                        priv->direction);
                break;
            case UNITS_IMPERIAL:
                a = (float) priv->altitude * M2FEET;
                d = (float) priv->distance * M2FEET;
                sprintf(buf, "Alt %df\nDis %df\n%d",
                        (unsigned int) a,
                        (unsigned int) d,
                        priv->direction);
                break;
        }

        draw_str(buf, 0, 0, ca, 1);

        transform_polygon(&arrow, 50, 34, priv->direction + 180);
        draw_polygon(&arrow, 3, ca);
        move_polygon(&arrow, -1, -1);
        draw_polygon(&arrow, 1, ca);
    }
}


const struct widget_ops home_info_widget_ops = {
    .name = "Home info",
    .mavname = "HOMEINF",
    .id = WIDGET_HOME_INFO_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Ejemplo n.º 5
0
// Move each dust particle and destroy the ancient ones and the
// particles that touch the star in the center of screen
void update_dust(void){
  struct dust *pointer = list_of_dust;
  struct dust *temp;
  struct timeval now;
  unsigned long elapsed_microseconds;
  float distance;

  while(pointer != NULL){
    // Moving
    move_polygon(pointer -> body, pointer -> dx / fps, pointer -> dy / fps);
    // Computing the distance:
    distance = pointer -> dx - 400.0;
    distance *= distance;
    distance += (pointer -> dy - 400.0) * (pointer -> dy - 400.0);
    distance = sqrtf(distance);
    
    // Erasing if the dust is too old
    gettimeofday(&now, NULL);
    elapsed_microseconds = (now.tv_usec - pointer -> time.tv_usec) +
      1000000 * (now.tv_sec - pointer  -> time.tv_sec);
    if(elapsed_microseconds > DUST_LIFE || ! gravity_to_dust(pointer)){
      if(pointer -> previous == NULL){ // The first dust
	if(pointer -> next == NULL){ // It's the only dust
	  free(pointer);
	  list_of_dust = NULL;
	  return;
	}
	else{ // We are in the first, but there's others
	  pointer = pointer -> next;
	  free(pointer -> previous);
	  pointer -> previous = NULL;
	  list_of_dust = pointer;
	  continue;
	}
      }
      else{ // We aren't in the first dust
	if(pointer -> next == NULL){ // But we are in the last
	  pointer -> previous -> next = NULL;
	  free(pointer);
	  return;
	}
	else{ // Not the first, nor the last
	  pointer -> previous -> next = pointer -> next;
	  pointer -> next -> previous = pointer -> previous;
	  temp = pointer;
	  pointer = pointer -> previous;
	  free(temp);
	  continue;
	}
      }
    }
    pointer = pointer -> next;
  }
}
Ejemplo n.º 6
0
void move_primitive(PRIMITIVE *p)
{
    switch (p->size)
    {
        case 1:
            move_point(&p->points[0], p->velocity);
            break;
        case 2:
            move_line(&p->points[0], &p->points[1], &p->centroid, p->velocity, p->rotation);
            break;
        default:
            move_polygon(p->points, p->size, &p->centroid, p->velocity, &p->angle, p->rotation, &p->bounding_box);
            break;
    }
}
Ejemplo n.º 7
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10];
    unsigned long d = (unsigned long) priv->home->distance;
    unsigned int r = (w->ca.width/2)-2;
    int x, y;
    int min_increment;
    long i, scale;
    struct point ils_points[5] = { {-4, -6}, {-4, 6}, {0, 10}, {4, 6}, {4, -6} };
    struct polygon ils = {
        .len = 5,
        .points = ils_points,
    };
    struct point uav_points[4] = { {0, 0}, {6, 8}, {0, -8}, {-6, 8} };
    struct polygon uav = {
        .len = 4,
        .points = uav_points,
    };

    struct polygon *p;

    x = (w->ca.width/2)-1;
    y = (w->ca.height/2)-1;


    draw_vline(x, 0, r*2, 2, ca);
    draw_hline(0, r*2, y, 2, ca);

    //draw_circle(x, y, r+1, 3, ca);
    draw_circle(x, y, r  , 2, ca);


    /* auto scale */
    switch (get_units(w->cfg)) {
    default:
    case UNITS_METRIC:
        min_increment = 500;
        scale = ((d / min_increment) + 1) * min_increment;
        sprintf(buf, "%um", (unsigned int) scale);
        break;
    case UNITS_IMPERIAL:
        d *= M2FEET;
        min_increment = 1000;
        scale = ((d / min_increment) + 1) * min_increment;
        if (d > 5000) {
            d = (d * 1000) / MILE2FEET;
            scale /= 1000;
            sprintf(buf, "%umi", (unsigned int) scale);
        } else {
            sprintf(buf, "%uf", (unsigned int) scale);
        }
        break;
    }

    draw_str(buf, 0, 0, ca, 0);

    i = (long) d * r;
    i /= scale;

    switch (w->cfg->props.mode >> 1) {
    case 0:
    default:
        /* radar fixed at uav heading, home moves */
        x += sin(DEG2RAD(priv->home->direction)) * i;
        y -= cos(DEG2RAD(priv->home->direction)) * i;
        transform_polygon(&ils, x, y, priv->stats->launch_heading - priv->heading - 180);
        p = &ils;
        break;
    case 1:
        /* radar always facing north, uav moves */
        x += sin(DEG2RAD(priv->home->uav_bearing)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing)) * i;
        transform_polygon(&uav, x, y, priv->heading);
        p = &uav;
        break;
    case 2:
        /* radar always facing launch direction, uav moves */
        x += sin(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i;
        transform_polygon(&uav, x, y, priv->heading - priv->stats->launch_heading);
        p = &uav;
        break;
    case 3:
        /* testing waypoints */
        /* radar always facing north, uav moves with waypoints */
        if (priv->wp_seq > 0) {
            long i_wp = (long) priv->wp_distance * r;
            i_wp /= scale;
            int x_wp = x, y_wp = y;
            x_wp += sin(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp;
            y_wp -= cos(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp;
            sprintf(buf, "%d", priv->wp_seq);
            draw_str(buf, x_wp, y_wp, ca, 0);
        }
        x += sin(DEG2RAD(priv->home->uav_bearing)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing)) * i;
        transform_polygon(&uav, x, y, priv->heading);
        p = &uav;
        break;
    }

    draw_polygon(p, 3, ca);
    move_polygon(p, -1, -1);
    draw_polygon(p, 1, ca);
}


const struct widget_ops radar_widget_ops = {
    .name = "Radar",
    .mavname = "RADAR",
    .id = WIDGET_RADAR_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Ejemplo n.º 8
0
void test_centroid(Polygon* surface, Polygon* polygons, double* population, double* test, int lt_)
{
	double surf_a=0;
	double c[3];
	double b[4];
	double l;
	double a1,a2;
	int n;
	int polylen = polygons->len;
	for (int test_n =0; test_n<lt_; test_n++)
	{
		if (test[test_n]<0)
		{
			surface->len=0;
			
			for (int i=0; i<polylen; i++)
			{
				n = int(population [test_n*polylen*3+i*3]);
				a1 = population [test_n*polylen*3+i*3+1]*2*PI;
				a2 = population [test_n*polylen*3+i*3+2]*2*PI;
				if (surface->len==0)
				{
			
					surface_append_polygon(surface, polygons, n);
					rotate_polygon(surface,0,a1+a2);
					surf_a = a2;
					surface_join_polygon(surface);
				}
				else
				{
					move_surface(surface, -surface->cx, -surface->cy);
	//				echo_polygon(surface, 0, "After move");				
					surface->cx = 0;
					surface->cy = 0;

	//				echo_polygon(surface, l);

					l = surface->len;
					surface_append_polygon(surface, polygons, n);
					polygon_centroid(c, surface, l);
					move_polygon(surface, l, -c[0], -c[1]);
			
					rotate_polygon(surface, l, a1+a2);
					rotate_surface(surface, a2 - surf_a);
					surf_a = a2;

					drop_polygon_down(surface, l);
					surface_join_polygon(surface);
	//				echo_polygon(surface, 0,"Surface");
	//				echo_polygon(surface, l,"Poly");	

				}	
			}		
	
			rotate_surface(surface, -surf_a);
			surface_bounds(b,surface);
//			printf("Test %d: %10.10f\n",test_n,(b[2]-b[0])*(b[3]-b[1]));
//			printf("Bonds: %f %f %f %f\n", b[0], b[1], b[2], b[3]);
		
			test[test_n]	= (b[2]-b[0])*(b[3]-b[1]);
		}
	}	
}