Exemplo n.º 1
0
int get_slope(loc_t a , loc_t b, int add_line, int reverse, vx_buffer_t* buf) 
{

    if(add_line) {
        int npoints = 2;
        float points[npoints*3];

        points[0] = a.x;
        points[1] = a.y;
        points[2] = 0;
        points[3] = b.x;
        points[4] = b.y;
        points[5] = 0;

        vx_resc_t *verts = vx_resc_copyf(points, npoints*3);
        vx_buffer_add_back(buf, vxo_pix_coords(VX_ORIGIN_BOTTOM_LEFT,
                                            vxo_lines(verts, npoints, GL_LINES, 
                                            vxo_points_style(vx_blue, 2.0f))));   
    }

    if(reverse) {
        if((a.y - b.y) == 0)
            return((a.x - b.x)/.0001);
        int ret = (a.x - b.x) /  (a.y - b.y); 
        return(ret);
    }
    if((a.x - b.x) == 0)
        return((a.y - b.y)/.0001);
    int ret = (a.y - b.y) /  (a.x - b.x); 
    return(ret); 
}
Exemplo n.º 2
0
void project_measurements_through_homography(matd_t* H, vx_buffer_t* buf,
        zarray_t* pix_found, int size)
{
    int npoints = NUM_CHART_BLOBS * 2;          //  line per chart blob
    float points[npoints*3];

    float* real_world_coords;
    if(size == NUM_TARGETS) real_world_coords = target_coords;
    else if(size == NUM_CHART_BLOBS) real_world_coords = chart_coords;
    else assert(0);

    for(int i = 0; i < size; i++) {
        // run each real world point through homography and add to buf
        
        double tmp[3] = {real_world_coords[i*2], real_world_coords[i*2+1], 1};
        matd_t* xy_matrix = matd_create_data(3,1,tmp);
        matd_t* pix_estimated = matd_op("(M)*M",H, xy_matrix);
        MATD_EL(pix_estimated,0,0) /= MATD_EL(pix_estimated,2, 0);
        MATD_EL(pix_estimated,1,0) /= MATD_EL(pix_estimated,2, 0);
        
        vx_buffer_add_back(buf,
                 vxo_pix_coords(VX_ORIGIN_BOTTOM_LEFT,
                        vxo_chain(vxo_mat_translate3(MATD_EL(pix_estimated,0,0), MATD_EL(pix_estimated,1,0), 0),
                            vxo_mat_scale(2.0),
                            vxo_circle(vxo_mesh_style(vx_green)))));

        // create endpoints for lines
        loc_t pos;
        zarray_get(pix_found, i, &pos); //     

        points[6*i + 0] = pos.x;
        points[6*i + 1] = pos.y;
        points[6*i + 2] = 0;
        points[6*i + 3] = MATD_EL(pix_estimated,0,0);
        points[6*i + 4] = MATD_EL(pix_estimated,1,0);
        points[6*i + 5] = 0;
    }

    // make lines
    vx_resc_t *verts = vx_resc_copyf(points, npoints*3);
    vx_buffer_add_back(buf, vxo_pix_coords(VX_ORIGIN_BOTTOM_LEFT,
                                    vxo_lines(verts, npoints, GL_LINES, 
                                        vxo_points_style(vx_blue, 2.0f))));
}
Exemplo n.º 3
0
void add_line_to_buffer(image_u32_t* im, vx_buffer_t* buf, double size, 
                        loc_t p1, loc_t p2, const float* color)
{
    int npoints = 2;          //  line per chart blob
    float points[npoints*3];

    points[0] = p1.x;
    points[1] = p1.y;
    points[2] = 0;
    points[3] = p2.x;
    points[4] = p2.y;
    points[5] = 0;

    // make lines
    vx_resc_t *verts = vx_resc_copyf(points, npoints*3);
    vx_buffer_add_back(buf, vxo_pix_coords(VX_ORIGIN_BOTTOM_LEFT,
                                    vxo_lines(verts, npoints, GL_LINES, 
                                        vxo_points_style(color, size))));
}
Exemplo n.º 4
0
static void draw(state_t * state, vx_world_t * world)
{
    // Draw from the vx shape library
    vx_buffer_add_back(vx_world_get_buffer(world, "fixed-cube"), vxo_chain(vxo_mat_translate3(3.0,0,0),
                       vxo_mat_scale(2),
                       vxo_box(vxo_mesh_style(vx_orange))));
    vx_buffer_swap(vx_world_get_buffer(world, "fixed-cube"));

    // Draw some text
    if (1) {
        vx_object_t *vt = vxo_text_create(VXO_TEXT_ANCHOR_LEFT, "<<right>>hello!\n<<serif-italic-4>>line 2\nfoo<<#ff0000>>red<<sansserif-bold-30,#0000ff80>>blue semi\n<<serif-italic-4>>foo bar baz");
        vx_buffer_t *vb = vx_world_get_buffer(world, "text");
        vx_buffer_add_back(vb, vt);
        vx_buffer_swap(vb);
    }

    // Draw a custom ellipse:
    {
        int npoints = 35;
        float points[npoints*3];
        for (int i = 0; i < npoints; i++) {
            float angle = 2*M_PI*i/npoints;

            float x = 5.0f*cosf(angle);
            float y = 8.0f*sinf(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;
        }

        vx_buffer_add_back(vx_world_get_buffer(world, "ellipse"), vxo_lines(vx_resc_copyf (points, npoints*3),
                           npoints, GL_LINE_LOOP,
                           vxo_lines_style(vx_purple, 1.0f) ));
        vx_buffer_swap(vx_world_get_buffer(world, "ellipse"));
    }

    // Draw a sin wave
    {
        int npoints = 100;
        float points[npoints*3];

        for (int i = 0; i < npoints; i++) {
            float angle = 2*M_PI*i/npoints;

            float x = i*.1;
            float y = sinf(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;
        }

        vx_buffer_add_back(vx_world_get_buffer(world, "sin"), vxo_points(vx_resc_copyf (points, npoints*3), npoints,
                           vxo_points_style(vx_purple, 10.0)));
        vx_buffer_swap(vx_world_get_buffer(world, "sin"));

    }

    // Draw a cos wave
    {
        int npoints = 100;
        float points[npoints*3];
        float colors[npoints*4];

        for (int i = 0; i < npoints; i++) {
            float angle = 2*M_PI*i/npoints;

            float x = i*.1;
            float y = cosf(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;

            float r = angle/(2*M_PI);
            float g = 0.3f;
            float b = 1.0f-(angle/(2*M_PI));

            colors[4*i + 0] = r;
            colors[4*i + 1] = g;
            colors[4*i + 2] = b;
            colors[4*i + 3] = 1.0f;

        }

        vx_buffer_add_back(vx_world_get_buffer(world, "cos"), vxo_points(vx_resc_copyf (points, npoints*3), npoints,
                           vxo_points_style_multi_colored(vx_resc_copyf(colors, npoints*4), 10.0)));
        vx_buffer_swap(vx_world_get_buffer(world, "cos"));

    }

    // Draw a rose
    if (1) {
        int npoints = 100;
        float points[npoints*3];
        float colors[npoints*4];
        int k = 3;

        for (int i = 0; i < npoints; i++) {
            float angle = M_PI*i/npoints; // [0, Pi] for Odd

            float x = cosf(k*angle)*sin(angle);
            float y = cosf(k*angle)*cos(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;

            float r = angle/(M_PI);
            float g = 1.0f-(angle/(M_PI));
            float b = 0.3f;

            colors[4*i + 0] = r;
            colors[4*i + 1] = g;
            colors[4*i + 2] = b;
            colors[4*i + 3] = 1.0f;

        }

        vx_buffer_add_back(vx_world_get_buffer(world, "rose"), vxo_lines(vx_resc_copyf (points, npoints*3), npoints,
                           GL_LINE_LOOP,
                           vxo_lines_style_multi_colored(vx_resc_copyf(colors, npoints*4), 1.0)));
        vx_buffer_swap(vx_world_get_buffer(world, "rose"));

    }


    if (1) { // draw a box with all the fixings
        vx_buffer_t * vb = vx_world_get_buffer(world, "rect");

        // should draw purple square, with green lines, all occluded by red corners.
        vx_buffer_add_back(vb, vxo_depth_test(0,vxo_chain(
                vxo_mat_translate2(-5,-5),
                vxo_rect(vxo_mesh_style(vx_purple),
                         vxo_lines_style(vx_green, 6.0f),
                         vxo_points_style(vx_red, 6.0f)))));
        vx_buffer_swap(vb);

    }

    // Draw a texture
    if (state->img != NULL) {
        image_u8_t * img = state->img;
        vx_object_t * o3 = vxo_image(vx_resc_copyub(img->buf, img->width*img->height*img->bpp),
                                     img->width, img->height, img->bpp == 4? GL_RGBA : GL_RGB, VXO_IMAGE_FLIPY);

        // pack the image into the unit square
        vx_buffer_t * vb = vx_world_get_buffer(world, "texture");
        vx_buffer_add_back(vb, vxo_chain(vxo_mat_scale3(1.0/img->width, 1.0/img->height, 1), o3));
        vx_buffer_swap(vb);
    }
}
Exemplo n.º 5
0
void body_draw(Body *body, vx_buffer_t *buf) {
	vx_object_t *vo;
	float scale = 1/20.0;
	float zoffset = 0;

	joint_t rShoulder = body->getJoint(RSHOULDER);
	joint_t rElbow = body->getJoint(RELBOW);
	joint_t rWrist = body->getJoint(RWRIST);
	joint_t lWrist = body->getJoint(LWRIST);

	double rShoulderX = 0;
	double rShoulderY = 0;
	double rShoulderZ = scale*(-2 * rShoulder.y);
	double rElbowX = scale*(rElbow.x - rShoulder.x);
	double rElbowY = scale*(rElbow.z - rShoulder.z);
	double rElbowZ = scale*(-rElbow.y - rShoulder.y);
	double rWristX = scale*(rWrist.x - rShoulder.x);
	double rWristY = scale*(rWrist.z - rShoulder.z);
	double rWristZ = scale*(-rWrist.y - rShoulder.y);
	double lWristX = scale*(lWrist.x - rShoulder.x);
	double lWristY = scale*(lWrist.z - rShoulder.z);
	double lWristZ = scale*(-lWrist.y - rShoulder.y);
	//Draw Axes
	float axes[12] = {(float) rShoulderX, (float) rShoulderY, (float) rShoulderZ,
						(float) rElbowX, (float) rElbowY, (float) rElbowZ, 
						(float) rElbowX, (float) rElbowY, (float) rElbowZ,
						(float) rWristX, (float) rWristY, (float) rWristZ};

	vx_resc_t *verts = vx_resc_copyf(axes, 12);
	vo = vxo_chain(
		vxo_lines(verts, 4, GL_LINES, vxo_points_style(vx_blue, 2.0f))
	);

	vx_buffer_add_back(buf, vo);	

	//Draw Joints
	vo = vxo_chain(
		vxo_mat_translate3(rShoulderX, rShoulderY, rShoulderZ),
		vxo_mat_scale3(1.5, 1.5, 1.5),
		vxo_sphere(vxo_mesh_style(vx_yellow))
	);

	vx_buffer_add_back(buf, vo);

	vo = vxo_chain(
		vxo_mat_translate3(rElbowX, rElbowY, rElbowZ),
		vxo_mat_scale3(1.5, 1.5, 1.5),
		vxo_sphere(vxo_mesh_style(vx_blue))
	);

	vx_buffer_add_back(buf, vo);

	vo = vxo_chain(
		vxo_mat_translate3(rWristX, rWristY, rWristZ),
		vxo_mat_scale3(1.5, 1.5, 1.5),
		vxo_sphere(vxo_mesh_style(vx_green))
	);

	vx_buffer_add_back(buf, vo);

	vo = vxo_chain(
		vxo_mat_translate3(lWristX, lWristY, lWristZ),
		vxo_mat_scale3(3, 3, 3),
		vxo_sphere(vxo_mesh_style(vx_black))
	);

	vx_buffer_add_back(buf, vo);
}
Exemplo n.º 6
0
void connect_lines(zarray_t* locs, vx_buffer_t* buf)
{
    connection_t lines[12]; 
    int idx = 0;
    // iterate 
    for(int i = 0; i < zarray_size(locs); i++) {
        loc_t curr;
        zarray_get(locs, i, &curr);
        for(int j = 0; j < zarray_size(locs); j++) {
            // make a connection to every point except self and add to the lines
            loc_t other;
            zarray_get(locs, j, &other);
            if(i != j) {     // not same point
                lines[idx].start = curr;
                lines[idx].end = other;
                lines[idx].length = sqrt((curr.x - other.x)*(curr.x - other.x) 
                                            + (curr.y - other.y)*(curr.y - other.y));
                idx++;
            }
        }
    }
    // sort the array by distance
    int flag = 1;    
    connection_t tmp;             
    for(int i = 0; (i < 12) && flag; i++)
    {
        flag = 0;       // only go over again if swap has been made
        for(int j = 0; j < (11); j++)
        {
            if(lines[j+1].length < lines[j].length)      
            { 
                tmp = lines[j];            
                lines[j] = lines[j+1];
                lines[j+1] = tmp;
                flag = 1;              
            }
        }
    }

    for(int i = 0; (i < 12); i++)
    {
        // printf("%lf\n", lines[i].length);
    }

    // usleep(2000000);

    int npoints = 8;
    float points[npoints*3];

    for(int i = 0; i < 4; i++) {
        points[6*i + 0] = lines[i*2].start.x;
        points[6*i + 1] = lines[i*2].start.y;
        points[6*i + 2] = 1;
        points[6*i + 3] = lines[i*2].end.x;
        points[6*i + 4] = lines[i*2].end.y;
        points[6*i + 5] = 1;
    }
    vx_resc_t *verts = vx_resc_copyf(points, npoints*3);
    vx_buffer_add_back(buf, vxo_pix_coords(VX_ORIGIN_BOTTOM_LEFT,
                                        vxo_lines(verts, npoints, GL_LINES, 
                                        vxo_points_style(vx_blue, 2.0f))));

}